Re: BUG? "Call fasync() functions without the BKL" is racy

From: Andi Kleen
Date: Mon Dec 01 2008 - 19:15:05 EST



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(&current->files->file_lock);
+ if (!(filp->f_flags & O_LOCK_FLAGS))
+ filp->f_flags |= O_LOCK_FLAGS;
+ else
+ error = -EAGAIN;
+ spin_unlock(&current->files->file_lock);
+ if (error) /* pretend ->f_flags was changed after us */
+ return 0;
+
if ((arg ^ filp->f_flags) & FASYNC) {
if (filp->f_op && filp->f_op->fasync) {
error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);
@@ -183,7 +192,8 @@ static int setfl(int fd, struct file * f
}
}
- filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK);
+ filp->f_flags = (arg & SETFL_MASK) |
+ (filp->f_flags & ~(SETFL_MASK | O_LOCK_FLAGS));
out:
return error;
}

What do you think?

Looks reasonable. Just would need to make sure that O_LOCK_FLAGS doesn't
leak out to user space.

-Andi


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/