From: Dave Hansen <haveblue@us.ibm.com>
To: Matthew Wilcox <willy@debian.org>
Cc: linux-fsdevel@vger.kernel.org, Stephen Rothwell <sfr@canb.auug.org.au>
Subject: Re: race with i_flock?
Date: Wed, 17 Jul 2002 15:31:14 -0700 [thread overview]
Message-ID: <3D35F032.9040408@us.ibm.com> (raw)
In-Reply-To: 20020717125533.Z27706@parcelfarce.linux.theplanet.co.uk
[-- Attachment #1: Type: text/plain, Size: 1317 bytes --]
Matthew Wilcox wrote:
> On Tue, Jul 16, 2002 at 07:27:00PM -0700, Dave Hansen wrote:
>>which is:
>>static inline int get_lease(struct inode *inode, unsigned int mode)
>>{
>>------->if (inode->i_flock && (inode->i_flock->fl_flags & FL_LEASE))
>> return __get_lease(inode, mode);
>> return 0;
>>}
>>
>>It appears that i_flock is NULL:
>
> Doh! That's entirely possible. open() could race with posix_lock_file and
> remove the first element of the i_flock list between the two tests. So...
> let's change get_lease() to be:
>
> static inline int get_lease(struct inode *inode, unsigned int mode)
> {
> if (inode->i_flock)
> return __get_lease(inode, mode);
> return 0;
> }
>
> __get_lease in 2.5.x has sufficient checks in it already; 2.4 does not
> and needs something like this:
>
>
> lock_kernel();
> flock = inode->i_flock;
> + if (!flock || (flock->fl_flags & FL_LEASE) == 0)
> + goto out;
> if (flock->fl_type & F_INPROGRESS) {
> if ((mode & O_NONBLOCK)
>
> This must be a 1-insn wide race. I'm very impressed you managed to hit
> it ;-)
You have no idea :)
How about this patch? I can't believe that I'm spreading the BKL, but
it is needed in this case. And, you _are_ removing it from flocking
in 2.5, right?
--
Dave Hansen
haveblue@us.ibm.com
[-- Attachment #2: i_flock-race_fix.2.5.25-0.patch --]
[-- Type: text/plain, Size: 854 bytes --]
--- linux-2.5.25-clean/fs/locks.c Thu Jul 11 00:18:43 2002
+++ linux/fs/locks.c Wed Jul 17 15:28:47 2002
@@ -1083,8 +1083,6 @@
alloc_err = lease_alloc(NULL, mode & FMODE_WRITE ? F_WRLCK : F_RDLCK,
&new_fl);
- lock_kernel();
-
time_out_leases(inode);
flock = inode->i_flock;
@@ -1155,7 +1153,6 @@
}
out:
- unlock_kernel();
if (!alloc_err)
locks_free_lock(new_fl);
return error;
--- linux-2.5.25-clean/include/linux/fs.h Thu Jul 11 00:18:47 2002
+++ linux/include/linux/fs.h Wed Jul 17 15:28:37 2002
@@ -1044,9 +1044,12 @@
static inline int get_lease(struct inode *inode, unsigned int mode)
{
+ int ret = 0;
+ lock_kernel();
if (inode->i_flock && (inode->i_flock->fl_flags & FL_LEASE))
- return __get_lease(inode, mode);
- return 0;
+ ret = __get_lease(inode, mode);
+ unlock_kernel();
+ return ret;
}
/* fs/open.c */
next prev parent reply other threads:[~2002-07-17 22:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-17 2:27 race with i_flock? Dave Hansen
2002-07-17 6:32 ` Andrew Morton
2002-07-17 11:55 ` Matthew Wilcox
2002-07-17 22:31 ` Dave Hansen [this message]
2002-07-18 1:07 ` Matthew Wilcox
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=3D35F032.9040408@us.ibm.com \
--to=haveblue@us.ibm.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sfr@canb.auug.org.au \
--cc=willy@debian.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.