mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	NFSv4: Handle case where the lookup of a directory fails
If the application sets the O_DIRECTORY flag, and tries to open a
regular file, nfs_atomic_open() will punt to doing a regular lookup.
If the server then returns a regular file, we will happily return a
file descriptor with uninitialised open state.
The fix is to return the expected ENOTDIR error in these cases.
Reported-by: Lyu Tao <tao.lyu@epfl.ch>
Fixes: 0dd2b474d0 ("nfs: implement i_op->atomic_open()")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
			
			
This commit is contained in:
		
							parent
							
								
									34bf20ce98
								
							
						
					
					
						commit
						ac795161c9
					
				
					 1 changed files with 13 additions and 0 deletions
				
			
		
							
								
								
									
										13
									
								
								fs/nfs/dir.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								fs/nfs/dir.c
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -1994,6 +1994,19 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 | 
			
		|||
 | 
			
		||||
no_open:
 | 
			
		||||
	res = nfs_lookup(dir, dentry, lookup_flags);
 | 
			
		||||
	if (!res) {
 | 
			
		||||
		inode = d_inode(dentry);
 | 
			
		||||
		if ((lookup_flags & LOOKUP_DIRECTORY) && inode &&
 | 
			
		||||
		    !S_ISDIR(inode->i_mode))
 | 
			
		||||
			res = ERR_PTR(-ENOTDIR);
 | 
			
		||||
	} else if (!IS_ERR(res)) {
 | 
			
		||||
		inode = d_inode(res);
 | 
			
		||||
		if ((lookup_flags & LOOKUP_DIRECTORY) && inode &&
 | 
			
		||||
		    !S_ISDIR(inode->i_mode)) {
 | 
			
		||||
			dput(res);
 | 
			
		||||
			res = ERR_PTR(-ENOTDIR);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (switched) {
 | 
			
		||||
		d_lookup_done(dentry);
 | 
			
		||||
		if (!res)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue