mirror of
				git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
				synced 2025-10-31 08:44:41 +00:00 
			
		
		
		
	vfs: take f_lock on modifying f_mode after open time
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 <fengguang.wu@intel.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christoph Hellwig <hch@infradead.org> Cc: Trond Myklebust <Trond.Myklebust@netapp.com> Cc: Chuck Lever <chuck.lever@oracle.com> Cc: <stable@kernel.org> [2.6.33.x] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									85f1fb72fa
								
							
						
					
					
						commit
						42e4960868
					
				
					 2 changed files with 4 additions and 0 deletions
				
			
		|  | @ -393,7 +393,9 @@ retry: | ||||||
| 			continue; | 			continue; | ||||||
| 		if (!(f->f_mode & FMODE_WRITE)) | 		if (!(f->f_mode & FMODE_WRITE)) | ||||||
| 			continue; | 			continue; | ||||||
|  | 		spin_lock(&f->f_lock); | ||||||
| 		f->f_mode &= ~FMODE_WRITE; | 		f->f_mode &= ~FMODE_WRITE; | ||||||
|  | 		spin_unlock(&f->f_lock); | ||||||
| 		if (file_check_writeable(f) != 0) | 		if (file_check_writeable(f) != 0) | ||||||
| 			continue; | 			continue; | ||||||
| 		file_release_write(f); | 		file_release_write(f); | ||||||
|  |  | ||||||
|  | @ -1998,7 +1998,9 @@ nfs4_file_downgrade(struct file *filp, unsigned int share_access) | ||||||
| { | { | ||||||
| 	if (share_access & NFS4_SHARE_ACCESS_WRITE) { | 	if (share_access & NFS4_SHARE_ACCESS_WRITE) { | ||||||
| 		drop_file_write_access(filp); | 		drop_file_write_access(filp); | ||||||
|  | 		spin_lock(&filp->f_lock); | ||||||
| 		filp->f_mode = (filp->f_mode | FMODE_READ) & ~FMODE_WRITE; | 		filp->f_mode = (filp->f_mode | FMODE_READ) & ~FMODE_WRITE; | ||||||
|  | 		spin_unlock(&filp->f_lock); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Wu Fengguang
						Wu Fengguang