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 B07E0C2BA1A for ; Tue, 7 Apr 2020 15:59:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 677502075E for ; Tue, 7 Apr 2020 15:59:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Z2RRhRaY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 677502075E 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 136EE8E0015; Tue, 7 Apr 2020 11:59:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E6908E0011; Tue, 7 Apr 2020 11:59:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F16B08E0015; Tue, 7 Apr 2020 11:59:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id DA8DA8E0011 for ; Tue, 7 Apr 2020 11:59:23 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9E8A8A8F0 for ; Tue, 7 Apr 2020 15:59:23 +0000 (UTC) X-FDA: 76681518606.28.drop00_17bfc3e36e513 X-HE-Tag: drop00_17bfc3e36e513 X-Filterd-Recvd-Size: 7503 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Apr 2020 15:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586275162; 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=lhqJdNpKfYyyacATER1JzPR9is3jQayAxnZWt/MwsN4=; b=Z2RRhRaYdSfiUIAVCV25Mp4FYq2+uhuz9QFBvm5GX4HO67tIfQ+r5eFwXAPVKOacZ7cnqa q+ptDlZYPwvtKHSIsREr25cyORMwjG3WOQuUzn6GjpDh/cYGsd8i3l5V/qhOm76XBsHD4c +/iiFsMUE8f6bkSlwmGUb9mtrFPXE5A= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-278-YSMpCnPoPVm5c0kH34rkhg-1; Tue, 07 Apr 2020 11:59:20 -0400 X-MC-Unique: YSMpCnPoPVm5c0kH34rkhg-1 Received: by mail-qk1-f198.google.com with SMTP id w21so3506286qkj.18 for ; Tue, 07 Apr 2020 08:59:20 -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=uyjESamdwUR+qBAftAf1wggTNgdAJyF9I7vk6xL9aJk=; b=oNIvudBLcfFUFGV8N0zAG5qEOcZZEL/HArQ/mAg1f65X3MHIN6WH0vPnAzu+dQVZQQ 9Nc5bKdSB2Bq7VcdCqx/RS6OdeI4Wgqvzi1M9H/F64DMzZOBSMZr3M0UK6HlY6ojzN+O E9d6b+YnmhVuugGzEjqQbOuIvYv2I/47GbXuPjo15Y53WiGJYk4/IlhMaVQ4FvR/OXEB 4dFFFYwxbhuokI02UUXjYo64xtPrS9vcRtsfgMxl0NxoYmuzz3jVDAS1taoucLtvYCdq abMHOOTpajUB+WH3Uf1qXN9k0igeRjT8e2O2Wi8lWFaZrr/XK2Y23kLZF0VVOIZYvhnU 38Zw== X-Gm-Message-State: AGi0PuZQCWi956wR6wT9lC1rQbpc4fRb+3Zme5uu2p3MHoL7+/XN6MmE yLAFLbeJIQUHByTgpmJgZQuzXE+EI/V1dACLd/PP9s3COaMcqr1vTHQc64V7y3kgzKzlAV1eQJK DK+sakJGAPBk= X-Received: by 2002:ac8:544b:: with SMTP id d11mr2980134qtq.122.1586275160051; Tue, 07 Apr 2020 08:59:20 -0700 (PDT) X-Google-Smtp-Source: APiQypITVF/A5j/lHW/Mk28wZXwa0K1fTtGrCfGOtpwxDP9B0toGgUPl684klg2CCJr7b6M9QM6bHQ== X-Received: by 2002:ac8:544b:: with SMTP id d11mr2980108qtq.122.1586275159771; Tue, 07 Apr 2020 08:59:19 -0700 (PDT) Received: from xz-x1 ([2607:9880:19c0:32::3]) by smtp.gmail.com with ESMTPSA id z40sm7063418qtj.45.2020.04.07.08.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 08:59:18 -0700 (PDT) Date: Tue, 7 Apr 2020 11:59:17 -0400 From: Peter Xu To: Dmitry Vyukov Cc: Andrew Morton , syzbot , Brian Geffon , LKML , Linux-MM , syzkaller-bugs , Linus Torvalds , Andrey Konovalov Subject: Re: BUG: unable to handle kernel paging request in kernel_get_mempolicy Message-ID: <20200407155917.GF48345@xz-x1> References: <0000000000002b25f105a2a3434d@google.com> <20200407004745.GA48345@xz-x1> <20200406183941.38a2e52026e42dbfde239a56@linux-foundation.org> <20200407015535.GC48345@xz-x1> <20200406191534.aafd8f74406c242ba1a42549@linux-foundation.org> <20200407024254.GD48345@xz-x1> MIME-Version: 1.0 In-Reply-To: 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 Tue, Apr 07, 2020 at 10:27:15AM +0200, Dmitry Vyukov wrote: > On Tue, Apr 7, 2020 at 4:43 AM Peter Xu wrote: > > > > 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: > > > > > > > On Mon, Apr 06, 2020 at 06:39:41PM -0700, Andrew Morton wrote: > > > > > On Mon, 6 Apr 2020 20:47:45 -0400 Peter Xu wr= ote: > > > > > > > > > > > >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 fa= tal signal > > > > > > > > > > > > lookup_node() uses gup to pin the page and get node information= . It > > > > > > checks against ret>=3D0 assuming the page will be filled in. H= owever > > > > > > it's also possible that gup will return zero, for example, when= the > > > > > > thread is quickly killed with a fatal signal. Teach lookup_nod= e() to > > > > > > gracefully return an error -EFAULT if it happens. > > > > > > > > > > > > ... > > > > > > > > > > > > --- a/mm/mempolicy.c > > > > > > +++ b/mm/mempolicy.c > > > > > > @@ -902,7 +902,10 @@ static int lookup_node(struct mm_struct *m= m, unsigned long addr) > > > > > > > > > > > > int locked =3D 1; > > > > > > err =3D get_user_pages_locked(addr & PAGE_MASK, 1, 0, &= p, &locked); > > > > > > - if (err >=3D 0) { > > > > > > + if (err =3D=3D 0) { > > > > > > + /* E.g. GUP interupted by fatal signal */ > > > > > > + err =3D -EFAULT; > > > > > > + } else if (err > 0) { > > > > > > err =3D page_to_nid(p); > > > > > > put_page(p); > > > > > > } > > > > > > > > > > Doh. Thanks. > > > > > > > > > > Should it have been -EINTR? > > > > > > > > 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 (o= r > > > > whatever we return) anyways. > > > > > > Yup. I guess we're a victim of get_user_pages()'s screwy return valu= e > > > conventions - the caller cannot distinguish between invalid-addr and > > > fatal-signal. > > > > Indeed. > > > > > > > > Which makes one wonder why lookup_node() ever worked. What happens i= f > > > get_mempolicy(MPOL_F_NODE) is passed a wild userspace address? > > > > > > > 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. >=20 > Am I reading this correctly that we put an initialized struct page* in > this case? If so, with stack spraying this looks like an "interesting" > bug. Yeah, so far it should be fine, but... ideally I guess we should init page=3D=3DNULL in lookup_node() too to avoid potential risk on exploiting. Maybe we could squash this into the fix if still possible. Thanks, --=20 Peter Xu