From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wu Fengguang Subject: [PATCH 4/6] vfs: take f_lock on modifying f_mode after open time Date: Fri, 15 Jan 2010 09:39:58 +0800 Message-ID: <20100115014422.683631340@intel.com> References: <20100115013954.311049665@intel.com> Cc: Al Viro , Christoph Hellwig , Wu Fengguang To: Andrew Morton Return-path: Received: from mga14.intel.com ([143.182.124.37]:59358 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752897Ab0AOBtd (ORCPT ); Thu, 14 Jan 2010 20:49:33 -0500 Cc: LKML CC: Eric Paris CC: Nick Piggin CC: Andi Kleen CC: David Howells CC: Jonathan Corbet cc: Content-Disposition: inline; filename=fmode-lock.patch Sender: linux-fsdevel-owner@vger.kernel.org List-ID: We'll introduce FMODE_RANDOM which will be runtime modified. So protect all runtime modification to f_mode with f_lock to avoid races. CC: Al Viro CC: Christoph Hellwig Signed-off-by: Wu Fengguang --- fs/file_table.c | 2 ++ fs/nfsd/nfs4state.c | 2 ++ 2 files changed, 4 insertions(+) --- linux.orig/fs/file_table.c 2010-01-15 09:11:07.000000000 +0800 +++ linux/fs/file_table.c 2010-01-15 09:11:15.000000000 +0800 @@ -392,7 +392,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); --- linux.orig/fs/nfsd/nfs4state.c 2010-01-15 09:08:22.000000000 +0800 +++ linux/fs/nfsd/nfs4state.c 2010-01-15 09:11:15.000000000 +0800 @@ -1998,7 +1998,9 @@ nfs4_file_downgrade(struct file *filp, u { 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); } }