diff options
| -rw-r--r-- | fs/fcntl.c | 7 | ||||
| -rw-r--r-- | fs/ioctl.c | 12 | 
2 files changed, 15 insertions, 4 deletions
diff --git a/fs/fcntl.c b/fs/fcntl.c index ac4f7db9f13..549daf8005f 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -19,6 +19,7 @@  #include <linux/signal.h>  #include <linux/rcupdate.h>  #include <linux/pid_namespace.h> +#include <linux/smp_lock.h>  #include <asm/poll.h>  #include <asm/siginfo.h> @@ -175,6 +176,11 @@ static int setfl(int fd, struct file * filp, unsigned long arg)  	if (error)  		return error; +	/* +	 * We still need a lock here for now to keep multiple FASYNC calls +	 * from racing with each other. +	 */ +	lock_kernel();  	if ((arg ^ filp->f_flags) & FASYNC) {  		if (filp->f_op && filp->f_op->fasync) {  			error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0); @@ -185,6 +191,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg)  	filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK);   out: +	unlock_kernel();  	return error;  } diff --git a/fs/ioctl.c b/fs/ioctl.c index d152856c371..43e8b2c0664 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -400,11 +400,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) @@ -440,11 +438,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:  |