From: Chris Wright <chrisw@osdl.org>
To: Matthew Wilcox <matthew@wil.cx>
Cc: Chris Wright <chrisw@osdl.org>,
Ivan Kalatchev <ivan.kalatchev@esg.ca>,
linux-kernel@vger.kernel.org
Subject: [TEST PATCH] Re: kernel 2.6.8 bug in fs/locks.c
Date: Fri, 1 Oct 2004 17:52:30 -0700 [thread overview]
Message-ID: <20041001175230.F1973@build.pdx.osdl.net> (raw)
In-Reply-To: <20041001122332.E1973@build.pdx.osdl.net>; from chrisw@osdl.org on Fri, Oct 01, 2004 at 12:23:33PM -0700
* Chris Wright (chrisw@osdl.org) wrote:
> * Ivan Kalatchev (ivan.kalatchev@esg.ca) wrote:
> > I'm using pthreads for each user-application connections. To protect
> > configuration file from corruption I used file locking mechanism - fcntl
> > with F_WRLCK/F_RDLCK.
>
> I must be confused. pthreads and fcntl locking...that does't give
> proper exclusion? The BUG, however, is no good. Despite the fact
> that it appears to come at the result of an application bug, we should
> be able to handle this w/out a BUG. AFAICT, one thread has closed the
> file descriptor, whilst another is mucking with the locks. So the locker
> winds up holding the last ref to the filp. This blows the logic of when
> locks_remove_posix gets called. Thanks for the bug report.
This is a rather ugly fix, but it demonstrates the hole. It's possible
for a posix lock to get applied after the final close of the file. This
means locks_remove_posix misses the yet to be created posix lock, and
on final fput when leaving fcntl, locks_remove_flock will BUG().
I was able to reproduce Ivan's bugreport. I doubt it's the right/best
fix, but it's functional (no more BUG()). Against -bk-curr.
Signed-off-by: Chris Wright <chrisw@osdl.org>
===== fs/fcntl.c 1.40 vs edited =====
--- 1.40/fs/fcntl.c 2004-09-02 02:48:03 -07:00
+++ edited/fs/fcntl.c 2004-10-01 17:34:15 -07:00
@@ -364,7 +364,7 @@
asmlinkage long sys_fcntl(int fd, unsigned int cmd, unsigned long arg)
{
- struct file *filp;
+ struct file *filp, *filp2;
long err = -EBADF;
filp = fget(fd);
@@ -379,6 +379,11 @@
err = do_fcntl(fd, cmd, arg, filp);
+ filp2 = fget(fd);
+ if (filp2 != filp)
+ locks_remove_posix(filp, current->files);
+ if (filp2)
+ fput(filp2);
fput(filp);
out:
return err;
@@ -387,7 +392,7 @@
#if BITS_PER_LONG == 32
asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
{
- struct file * filp;
+ struct file *filp, *filp2;
long err;
err = -EBADF;
@@ -414,6 +419,12 @@
err = do_fcntl(fd, cmd, arg, filp);
break;
}
+
+ filp2 = fget(fd);
+ if (filp2 != filp)
+ locks_remove_posix(filp, current->files);
+ if (filp2)
+ fput(filp2);
fput(filp);
out:
return err;
prev parent reply other threads:[~2004-10-02 0:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-01 16:24 Ivan Kalatchev
2004-10-01 19:23 ` Chris Wright
2004-10-02 0:52 ` Chris Wright [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041001175230.F1973@build.pdx.osdl.net \
--to=chrisw@osdl.org \
--cc=ivan.kalatchev@esg.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew@wil.cx \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®