lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200407024254.GD48345@xz-x1>
Date:   Mon, 6 Apr 2020 22:42:54 -0400
From:   Peter Xu <peterx@...hat.com>
To:     Andrew Morton <akpm@...ux-foundation.org>
Cc:     syzbot <syzbot+693dc11fcb53120b5559@...kaller.appspotmail.com>,
        bgeffon@...gle.com, linux-kernel@...r.kernel.org,
        linux-mm@...ck.org, syzkaller-bugs@...glegroups.com,
        torvalds@...ux-foundation.org
Subject: Re: BUG: unable to handle kernel paging request in
 kernel_get_mempolicy

On Mon, Apr 06, 2020 at 07:15:34PM -0700, Andrew Morton wrote:
> On Mon, 6 Apr 2020 21:55:35 -0400 Peter Xu <peterx@...hat.com> 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 <peterx@...hat.com> wrote:
> > > 
> > > > >From 23800bff6fa346a4e9b3806dc0cfeb74498df757 Mon Sep 17 00:00:00 2001
> > > > From: Peter Xu <peterx@...hat.com>
> > > > Date: Mon, 6 Apr 2020 20:40:13 -0400
> > > > Subject: [PATCH] mm/mempolicy: Allow lookup_node() to handle fatal signal
> > > > 
> > > > lookup_node() uses gup to pin the page and get node information.  It
> > > > checks against ret>=0 assuming the page will be filled in.  However
> > > > 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.
> > > > 
> > > > ...
> > > >
> > > > --- a/mm/mempolicy.c
> > > > +++ b/mm/mempolicy.c
> > > > @@ -902,7 +902,10 @@ static int lookup_node(struct mm_struct *mm, unsigned long addr)
> > > >  
> > > >  	int locked = 1;
> > > >  	err = get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &locked);
> > > > -	if (err >= 0) {
> > > > +	if (err == 0) {
> > > > +		/* E.g. GUP interupted by fatal signal */
> > > > +		err = -EFAULT;
> > > > +	} else if (err > 0) {
> > > >  		err = 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 (or
> > whatever we return) anyways.
> 
> 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.

> 
> Which makes one wonder why lookup_node() ever worked.  What happens if
> 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.

Thanks,

-- 
Peter Xu

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ