vfs: take f_lock on modifying f_mode after open time
authorWu Fengguang <[email protected]>
Fri, 5 Mar 2010 21:42:01 +0000 (13:42 -0800)
committerLinus Torvalds <[email protected]>
Sat, 6 Mar 2010 19:26:25 +0000 (11:26 -0800)
We'll introduce FMODE_RANDOM which will be runtime modified.  So protect
all runtime modification to f_mode with f_lock to avoid races.

Signed-off-by: Wu Fengguang <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Trond Myklebust <[email protected]>
Cc: Chuck Lever <[email protected]>
Cc: <[email protected]> [2.6.33.x]
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
fs/file_table.c
fs/nfsd/nfs4state.c

index b98404b5438385dc803498ba5e0c710a7244ed60..32d12b78bac8e2c05a80dc53386b355bdc10ef73 100644 (file)
@@ -393,7 +393,9 @@ retry:
                        continue;
                if (!(f->f_mode & FMODE_WRITE))
                        continue;
+               spin_lock(&f->f_lock);
                f->f_mode &= ~FMODE_WRITE;
+               spin_unlock(&f->f_lock);
                if (file_check_writeable(f) != 0)
                        continue;
                file_release_write(f);
index f19ed866c95fd18ef5da370b9cd09387c6d71c8a..fcafe6087f692d398c1a291b4c2b7bb732578c78 100644 (file)
@@ -1998,7 +1998,9 @@ nfs4_file_downgrade(struct file *filp, unsigned int share_access)
 {
        if (share_access & NFS4_SHARE_ACCESS_WRITE) {
                drop_file_write_access(filp);
+               spin_lock(&filp->f_lock);
                filp->f_mode = (filp->f_mode | FMODE_READ) & ~FMODE_WRITE;
+               spin_unlock(&filp->f_lock);
        }
 }