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]
Date:   Sat, 7 Oct 2017 21:07:58 -0400
From:   "J. Bruce Fields" <bfields@...ldses.org>
To:     Jeff Layton <jlayton@...hat.com>
Cc:     Jia-Ju Bai <baijiaju1990@....com>, dhowells@...hat.com,
        viro@...iv.linux.org.uk, linux-fsdevel@...r.kernel.org,
        linux-afs@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] fs/afs/flock and fs/locks: Fix possible sleep-in-atomic
 bugs in posix_lock_file

On Sat, Oct 07, 2017 at 06:36:57AM -0400, Jeff Layton wrote:
> On Sat, 2017-10-07 at 17:55 +0800, Jia-Ju Bai wrote:
> > The kernel may sleep under a spinlock, and the function call paths are:
> > afs_do_unlk (acquire the spinlock)
> >   posix_lock_file
> >     posix_lock_inode (fs/locks.c)
> >       locks_get_lock_context
> >         kmem_cache_alloc(GFP_KERNEL) --> may sleep
> > 
> > afs_do_setlk (acquire the spinlock)
> >   posix_lock_file
> >     posix_lock_inode (fs/locks.c)
> >       locks_get_lock_context
> >         kmem_cache_alloc(GFP_KERNEL) --> may sleep
> > 
> > To fix them, GFP_KERNEL is replaced with GFP_ATOMIC.
> > These bugs are found by my static analysis tool and my code review.
> > 
> > Signed-off-by: Jia-Ju Bai <baijiaju1990@....com>
> > ---
> >  fs/locks.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/locks.c b/fs/locks.c
> > index 1bd71c4..975cc62 100644
> > --- a/fs/locks.c
> > +++ b/fs/locks.c
> > @@ -222,7 +222,7 @@ struct file_lock_list_struct {
> >  	if (likely(ctx) || type == F_UNLCK)
> >  		goto out;
> >  
> > -	ctx = kmem_cache_alloc(flctx_cache, GFP_KERNEL);
> > +	ctx = kmem_cache_alloc(flctx_cache, GFP_ATOMIC);
> >  	if (!ctx)
> >  		goto out;
> >  
> 
> NAK
> 
> This needs to be fixed in the AFS code. It should not be calling these
> functions with a spinlock held.

Agreed.

>From a quick look at afs_do_setlk: am I misreading something, or is it
actually trying to do an rpc call to the server while holding i_lock?

I wonder if this is the fault of the BKL conversion: 72f98e72551f
"locks: turn lock_flocks into a spinlock" claims "nothing depends on
lock_flocks using the BKL any more, so we can do the switch over to a
private spinlock."  But this code, with lots of blockers, was under
lock_flocks().  Does that mean nobody's tested fcntl locking over afs
since that change in 2010?

--b.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ