file locking fix for 3.2

Subsystems: file locking (flock() and fcntl()/lockf()), filesystems (vfs and infrastructure), the rest

2 messages, 2 authors, 2011-12-24 · open the first message on its own page

file locking fix for 3.2

From: J. Bruce Fields <hidden>
Date: 2011-12-24 21:50:15

Please pull the following change from the for-3.2 branch at:

	git://linux-nfs.org/~bfields/linux.git for-3.2

One small 3.2 regression in the file-locking code.  Seems like an
unlikely bug (null dereference on kmalloc failure), but the fix is a
one-liner.

--b.

J. Bruce Fields (1):
      locks: fix null dereference on lease-break failure path

 fs/locks.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

commit b67e18a8e3425725cc17cc7633bccb06fb3c9eda
Author: J. Bruce Fields [off-list ref]
Date:   Mon Dec 19 17:57:11 2011 -0500

    locks: fix null dereference on lease-break failure path
    
    Commit 778fc546f749c588aa2f6cd50215d2715c374252 "locks: fix tracking of
    inprogress lease breaks" introduced a null dereference on failure to
    allocate memory.
    
    This means an open (without O_NONBLOCK set) on a file with a lease
    applied (generally only done when Samba or nfsd (with v4) is running)
    could crash if a kmalloc() fails.
    
    Signed-off-by: J. Bruce Fields [off-list ref]
diff --git a/fs/locks.c b/fs/locks.c
index 3b0d05d..96a487a 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1214,8 +1214,8 @@ int __break_lease(struct inode *inode, unsigned int mode)
 	if ((flock == NULL) || !IS_LEASE(flock))
 		goto out;
 
-	if (!locks_conflict(flock, new_fl))
-		goto out;
+	if (flock->fl_type == F_RDLCK && !want_write)
+		goto out; /* no conflict */
 
 	for (fl = flock; fl && IS_LEASE(fl); fl = fl->fl_next)
 		if (fl->fl_owner == current->files)

Re: file locking fix for 3.2

From: Al Viro <viro@ZenIV.linux.org.uk>
Date: 2011-12-24 22:55:29

On Sat, Dec 24, 2011 at 04:50:12PM -0500, J. Bruce Fields wrote:
    locks: fix null dereference on lease-break failure path
    
    Commit 778fc546f749c588aa2f6cd50215d2715c374252 "locks: fix tracking of
    inprogress lease breaks" introduced a null dereference on failure to
    allocate memory.
    
    This means an open (without O_NONBLOCK set) on a file with a lease
    applied (generally only done when Samba or nfsd (with v4) is running)
    could crash if a kmalloc() fails.
NULL?  AFAICS, lease_alloc() returns ERR_PTR() on failure...  I really
don't like the look of that code, TBH - at the very least it needs to
be commented a lot.  E.g. the rules for calling or not calling ->lm_break()
are really not obvious - AFAICS, we do that if
	i_have_this_lease || (mode & O_NONBLOCK)
is true *or* if allocation has succeeded.  The former condition is what'll
end up with -EWOULDBLOCK; I can understand not wanting to return that in
preference to -ENOMEM, but...  Do we want to skip ->lm_break() stuff only
in case of allocation failures that won't be overridden by -EWOULDBLOCK?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help