diff options
author | Jonathan Corbet <corbet@lwn.net> | 2008-12-05 16:12:48 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-12-13 15:29:14 -0800 |
commit | 21b7c0e824f0e98242e625a15bea368ea72ebcbb (patch) | |
tree | bb5883ca3e3fd82d9216f686c7a7aee9a9f1a191 /fs/ioctl.c | |
parent | 5c7c64831c51516034a7099ba25718f7aaed19e4 (diff) |
Fix a race condition in FASYNC handling
commit 218d11a8b071b23b76c484fd5f72a4fe3306801e upstream.
Changeset a238b790d5f99c7832f9b73ac8847025815b85f7 (Call fasync()
functions without the BKL) introduced a race which could leave
file->f_flags in a state inconsistent with what the underlying
driver/filesystem believes. Revert that change, and also fix the same
races in ioctl_fioasync() and ioctl_fionbio().
This is a minimal, short-term fix; the real fix will not involve the
BKL.
Reported-by: Oleg Nesterov <oleg@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/ioctl.c')
-rw-r--r-- | fs/ioctl.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/ioctl.c b/fs/ioctl.c index 7db32b3382d..612e0b2f018 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -123,11 +123,9 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp, /* Did FASYNC state change ? */ if ((flag ^ filp->f_flags) & FASYNC) { - if (filp->f_op && filp->f_op->fasync) { - lock_kernel(); + if (filp->f_op && filp->f_op->fasync) error = filp->f_op->fasync(fd, filp, on); - unlock_kernel(); - } else + else error = -ENOTTY; } if (error) @@ -163,11 +161,17 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, break; case FIONBIO: + /* BKL needed to avoid races tweaking f_flags */ + lock_kernel(); error = ioctl_fionbio(filp, argp); + unlock_kernel(); break; case FIOASYNC: + /* BKL needed to avoid races tweaking f_flags */ + lock_kernel(); error = ioctl_fioasync(fd, filp, argp); + unlock_kernel(); break; case FIOQSIZE: |