From: Oleg Nesterov <oleg@redhat.com>
To: Jonathan Corbet <corbet@lwn.net>
Cc: Andi Kleen <ak@linux.intel.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Vitaly Mayatskikh <vmayatsk@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: BUG? "Call fasync() functions without the BKL" is racy
Date: Tue, 2 Dec 2008 13:29:39 +0100 [thread overview]
Message-ID: <20081202122939.GA3619@redhat.com> (raw)
In-Reply-To: <20081201123405.51d20d84@bike.lwn.net>
On 12/01, Jonathan Corbet wrote:
>
> On Mon, 1 Dec 2008 20:15:55 +0100
> Oleg Nesterov <oleg@redhat.com> wrote:
>
> > > Hmm, about checking for this case and retrying?
> > >
> > > Or put a fasync mutex into files_struct.
> >
> > Perhaps, we can add O_LOCK_FLAGS, then something like
> >
> > --- a/fs/fcntl.c
> > +++ b/fs/fcntl.c
> > @@ -175,6 +175,15 @@ static int setfl(int fd, struct file * f
> > if (error)
> > return error;
> >
> > + spin_lock(¤t->files->file_lock);
> > + if (!(filp->f_flags & O_LOCK_FLAGS))
> > + filp->f_flags |= O_LOCK_FLAGS;
> > + else
> > + error = -EAGAIN;
> > + spin_unlock(¤t->files->file_lock);
> > + if (error) /* pretend ->f_flags was changed after us
> > */
> > + return 0;
> > +
>
> This strikes me as overkill.
and doesn't really help. fork() clones files_struct, we can't rely
on ->file_lock. And we have fd passing.
> What we really want to do is to protect
> against concurrent access to f_flags - something which could come about
> in a couple of other situations (nfsd/vfs.c tweaks it, for example).
> We *could* just extend files_lock to cover f_flags too, but that comes
> at the cost of making ->fasync() atomic when it never has been before -
> doesn't seem like a good idea.
>
> Perhaps we just need a single f_flags_mutex? For code changing
> f_flags only (it woudn't be needed to query the flags)? Then
> ioctl_fionbio() and ioctl_fioasync() could use it too. It's hard to
> imagine that there's enough contention to warrant any more than that,
> especially given that it all (except ioctl_fionbio()) has been under
> the BKL until now.
A bit ugly to use the global mutex to protect all ->f_flags, but yes,
I agree. Imho this is 2.6.28 material, we need the simple fix or the
user can crash the kernel.
Still I'd like to see the better fix for the long term, the only (afaics)
flag with the "side effect" is FASYNC, perhaps we can move it to (say)
->f_mode, but this is ugly of course and still need serialization for the
pathes which play with FASYNC.
Otherwise, any code which changes ->f_flags can clear FASYNC if we race
with sys_fcntl(F_SETFL, FASYNC).
If we introduce the new lock, we should change for example tty_io.c:fionbio(),
tty has the ->fasync() method. Currently tty_io.c relies on lock_kernel().
Oleg.
next prev parent reply other threads:[~2008-12-02 12:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-28 19:25 BUG? "Call fasync() functions without the BKL" is racy Oleg Nesterov
2008-12-01 11:34 ` Andi Kleen
2008-12-01 19:15 ` Oleg Nesterov
2008-12-01 19:34 ` Jonathan Corbet
2008-12-02 12:29 ` Oleg Nesterov [this message]
2008-12-02 16:30 ` Andi Kleen
2008-12-03 19:06 ` Oleg Nesterov
2008-12-03 21:21 ` Andi Kleen
2008-12-03 22:45 ` Jonathan Corbet
2008-12-04 14:34 ` Oleg Nesterov
2008-12-05 23:12 ` [PATCH 2.6.28] Fix FASYNC race Jonathan Corbet
2008-12-02 0:15 ` BUG? "Call fasync() functions without the BKL" is racy Andi Kleen
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=20081202122939.GA3619@redhat.com \
--to=oleg@redhat.com \
--cc=ak@linux.intel.com \
--cc=corbet@lwn.net \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=vmayatsk@redhat.com \
/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