summaryrefslogtreecommitdiff
path: root/fs/nfs/dir.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2017-07-03 08:27:26 +0300
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2017-07-13 23:00:08 +0300
commiteaa2b82c3b3c938ab4635f8967d33f3e581da836 (patch)
tree94cfbdc4c28f6c84ac2d1391afc0f3673983f6df /fs/nfs/dir.c
parentcc89684c9a265828ce061037f1f79f4a68ccd3f7 (diff)
downloadlinux-eaa2b82c3b3c938ab4635f8967d33f3e581da836.tar.xz
NFS: guard against confused server in nfs_atomic_open()
A confused server could return a filehandle for an NFSv4 OPEN request, which it previously returned for a directory. So the inode returned by ->open_context() in nfs_atomic_open() could conceivably be a directory inode. This has particular implications for the call to nfs_file_set_open_context() in nfs_finish_open(). If that is called on a directory inode, then the nfs_open_context that gets stored in the filp->private_data will be linked to nfs_inode->open_files. When the directory is closed, nfs_closedir() will (ultimately) free the ->private_data, but not unlink it from nfs_inode->open_files (because it doesn't expect an nfs_open_context there). Subsequently the memory could get used for something else and eventually if the ->open_files list is walked, the walker will fall off the end and crash. So: change nfs_finish_open() to only call nfs_file_set_open_context() for regular-file inodes. This failure mode has been seen in a production setting (unknown NFS server implementation). The kernel was v3.0 and the specific sequence seen would not affect more recent kernels, but I think a risk is still present, and caution is wise. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'fs/nfs/dir.c')
-rw-r--r--fs/nfs/dir.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 98b18aaf45c9..90bc4025ca3c 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1431,8 +1431,10 @@ static int nfs_finish_open(struct nfs_open_context *ctx,
err = finish_open(file, dentry, do_open, opened);
if (err)
goto out;
- nfs_file_set_open_context(file, ctx);
-
+ if (S_ISREG(file->f_path.dentry->d_inode->i_mode))
+ nfs_file_set_open_context(file, ctx);
+ else
+ err = -ESTALE;
out:
return err;
}