From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9ADFC2BABC for ; Tue, 7 Apr 2020 02:43:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9FC5520731 for ; Tue, 7 Apr 2020 02:43:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Wh8M8o81" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FC5520731 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4E89C8E0005; Mon, 6 Apr 2020 22:43:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 498FA8E0001; Mon, 6 Apr 2020 22:43:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3883C8E0005; Mon, 6 Apr 2020 22:43:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0247.hostedemail.com [216.40.44.247]) by kanga.kvack.org (Postfix) with ESMTP id 1D2738E0001 for ; Mon, 6 Apr 2020 22:43:02 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DB473A2A6 for ; Tue, 7 Apr 2020 02:43:01 +0000 (UTC) X-FDA: 76679511762.12.song48_37872f901ff05 X-HE-Tag: song48_37872f901ff05 X-Filterd-Recvd-Size: 6433 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Apr 2020 02:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586227380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l86zxK76Vt//qHwCjr+nA5OE46Vkq1wOK9qYQEFTAP8=; b=Wh8M8o81iOLc2sxXZcDJHSle2lf5Qix2fYgenlSJ1oDj9givGUnxkF5F0uZFwDfY76XyzH iqq+DsMFL1qkbjNnb2OxEwMAAWNzMFp52NsjCi87k9kSQ0rJ2dgtp3jLCf2Zs7xuBcXRVv 1qzfYTl+PpF7Ft4KR8mAZe6lgRqnJcU= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-79-_Fq4-28MMG-t46YLlZ9WNg-1; Mon, 06 Apr 2020 22:42:57 -0400 X-MC-Unique: _Fq4-28MMG-t46YLlZ9WNg-1 Received: by mail-qv1-f70.google.com with SMTP id d2so1750483qve.11 for ; Mon, 06 Apr 2020 19:42:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qRbC1rzVADwFG25IejKrn57SzQYDjjpXJx3tCx1nnHU=; b=cEzpCWzEGF3yeCDoew5UQDxJ02Dxjif1QJmquBhZ8GDamZbvesIQumcw/Jx9h0yZ0k rKh8DaBnq4OWL9ZAbXV64p3CwKtDASRmgPRPBeSh8HcKlPTazoXT2OM4AW1gMxrkvp7R vbQCfKuLe6kVf4IBcTmqN4V6EXgXjQF0ZM7mUwZ+laKfsP1eedFWhHLn7cPwWSk0OIqY avvhleETM31bFPPYc+6LQdxyuclD4CwY3Me7KHODMDDGnGYMEQFGf4ByKlI2oQ31BdUM 2moGzepvTDGtxuRjDqC4GgSwvi+jIPZwWHmJUDMneYipG0i3Xp24VDkok+8tA5AqnU/J o5zQ== X-Gm-Message-State: AGi0PuYA2TB9P71UC9kFIoNPsTSAP477YM0bNJdWv/Fdvku5j5g227pW IkwEeaDF+1e1NsZfrp5r8a+afk9NUgEZhq0V3b/SnF/hVgcxZEoq3/syAwlPGJYId8FvC5Txp5R rWFxutrBOepE= X-Received: by 2002:a0c:ee43:: with SMTP id m3mr168866qvs.164.1586227376958; Mon, 06 Apr 2020 19:42:56 -0700 (PDT) X-Google-Smtp-Source: APiQypKZUk6f94FsaqytTfxzUg3txoTEW6qWDqKeIkY3IOnUYwqNFVwRuP3nRvxR5AYnByyz8NRjlQ== X-Received: by 2002:a0c:ee43:: with SMTP id m3mr168850qvs.164.1586227376652; Mon, 06 Apr 2020 19:42:56 -0700 (PDT) Received: from xz-x1 ([2607:9880:19c0:32::3]) by smtp.gmail.com with ESMTPSA id y16sm9994696qtj.32.2020.04.06.19.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Apr 2020 19:42:56 -0700 (PDT) Date: Mon, 6 Apr 2020 22:42:54 -0400 From: Peter Xu To: Andrew Morton Cc: syzbot , bgeffon@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, torvalds@linux-foundation.org Subject: Re: BUG: unable to handle kernel paging request in kernel_get_mempolicy Message-ID: <20200407024254.GD48345@xz-x1> References: <0000000000002b25f105a2a3434d@google.com> <20200407004745.GA48345@xz-x1> <20200406183941.38a2e52026e42dbfde239a56@linux-foundation.org> <20200407015535.GC48345@xz-x1> <20200406191534.aafd8f74406c242ba1a42549@linux-foundation.org> MIME-Version: 1.0 In-Reply-To: <20200406191534.aafd8f74406c242ba1a42549@linux-foundation.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Apr 06, 2020 at 07:15:34PM -0700, Andrew Morton wrote: > On Mon, 6 Apr 2020 21:55:35 -0400 Peter Xu wrote: >=20 > > On Mon, Apr 06, 2020 at 06:39:41PM -0700, Andrew Morton wrote: > > > On Mon, 6 Apr 2020 20:47:45 -0400 Peter Xu wrote: > > >=20 > > > > >From 23800bff6fa346a4e9b3806dc0cfeb74498df757 Mon Sep 17 00:00:00 = 2001 > > > > From: Peter Xu > > > > Date: Mon, 6 Apr 2020 20:40:13 -0400 > > > > Subject: [PATCH] mm/mempolicy: Allow lookup_node() to handle fatal = signal > > > >=20 > > > > lookup_node() uses gup to pin the page and get node information. I= t > > > > checks against ret>=3D0 assuming the page will be filled in. Howev= er > > > > it's also possible that gup will return zero, for example, when the > > > > thread is quickly killed with a fatal signal. Teach lookup_node() = to > > > > gracefully return an error -EFAULT if it happens. > > > >=20 > > > > ... > > > > > > > > --- a/mm/mempolicy.c > > > > +++ b/mm/mempolicy.c > > > > @@ -902,7 +902,10 @@ static int lookup_node(struct mm_struct *mm, u= nsigned long addr) > > > > =20 > > > > =09int locked =3D 1; > > > > =09err =3D get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &lock= ed); > > > > -=09if (err >=3D 0) { > > > > +=09if (err =3D=3D 0) { > > > > +=09=09/* E.g. GUP interupted by fatal signal */ > > > > +=09=09err =3D -EFAULT; > > > > +=09} else if (err > 0) { > > > > =09=09err =3D page_to_nid(p); > > > > =09=09put_page(p); > > > > =09} > > >=20 > > > Doh. Thanks. > > >=20 > > > Should it have been -EINTR? > >=20 > > It looks ok to me too. I was returning -EFAULT to follow the same > > value as get_vaddr_frames() (which is the other caller of > > get_user_pages_locked()). So far the only path that I found can > > trigger this is when there's a fatal signal pending right after the > > gup. If so, the userspace won't have a chance to see the -EINTR (or > > whatever we return) anyways. >=20 > Yup. I guess we're a victim of get_user_pages()'s screwy return value > conventions - the caller cannot distinguish between invalid-addr and > fatal-signal. Indeed. >=20 > Which makes one wonder why lookup_node() ever worked. What happens if > get_mempolicy(MPOL_F_NODE) is passed a wild userspace address? >=20 I'm not familiar with mempolicy at all, but do you mean MPOL_F_NODE with MPOL_F_ADDR? Asked since iiuc if only MPOL_F_NODE is specified, the kernel should not use the userspace addr at all (which seems to be the thing we do now). get_mempolicy(MPOL_F_NODE|MPOL_F_ADDR) seems to return -EFAULT as expected, though I agree maybe it would still be nicer to differentiate the two cases. Thanks, --=20 Peter Xu