[NFS]: Check that the server returns a valid regular file to our OPEN request Signed-off-by: Trond Myklebust --- dir.c | 4 +++- nfs4proc.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) Index: linux-2.6.13-rc1/fs/nfs/nfs4proc.c =================================================================== --- linux-2.6.13-rc1.orig/fs/nfs/nfs4proc.c +++ linux-2.6.13-rc1/fs/nfs/nfs4proc.c @@ -671,6 +671,20 @@ static int _nfs4_do_open(struct inode *d status = _nfs4_proc_open(dir, sp, &o_arg, &o_res); if (status != 0) goto out_err; + /* OPEN on anything except a regular file is disallowed in NFSv4 */ + switch (f_attr.mode & S_IFMT) { + case S_IFREG: + break; + case S_IFLNK: + status = -ELOOP; + goto out_err; + case S_IFDIR: + status = -EISDIR; + goto out_err; + default: + status = -ENOTDIR; + goto out_err; + } status = -ENOMEM; inode = nfs_fhget(dir->i_sb, &o_res.fh, &f_attr); Index: linux-2.6.13-rc1/fs/nfs/dir.c =================================================================== --- linux-2.6.13-rc1.orig/fs/nfs/dir.c +++ linux-2.6.13-rc1/fs/nfs/dir.c @@ -954,10 +954,12 @@ static struct dentry *nfs_atomic_lookup( res = NULL; goto out; /* This turned out not to be a regular file */ + case -EISDIR: + case -ENOTDIR: + goto no_open; case -ELOOP: if (!(nd->intent.open.flags & O_NOFOLLOW)) goto no_open; - /* case -EISDIR: */ /* case -EINVAL: */ default: goto out;