Skip to content

Commit 6e45906

Browse files
committed
NFSD: Return NFS4ERR_FILE_OPEN only when linking an open file
RFC 8881 Section 18.9.4 paragraphs 1 - 2 tell us that RENAME should return NFS4ERR_FILE_OPEN only when the target object is a file that is currently open. If the target is a directory, some other status must be returned. The VFS is unlikely to return -EBUSY, but NFSD has to ensure that errno does not leak to clients as a status code that is not permitted by spec. Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 3b60984 commit 6e45906

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

fs/nfsd/vfs.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,16 +1698,25 @@ nfsd_symlink(struct svc_rqst *rqstp, struct svc_fh *fhp,
16981698
return err;
16991699
}
17001700

1701-
/*
1702-
* Create a hardlink
1703-
* N.B. After this call _both_ ffhp and tfhp need an fh_put
1701+
/**
1702+
* nfsd_link - create a link
1703+
* @rqstp: RPC transaction context
1704+
* @ffhp: the file handle of the directory where the new link is to be created
1705+
* @name: the filename of the new link
1706+
* @len: the length of @name in octets
1707+
* @tfhp: the file handle of an existing file object
1708+
*
1709+
* After this call _both_ ffhp and tfhp need an fh_put.
1710+
*
1711+
* Returns a generic NFS status code in network byte-order.
17041712
*/
17051713
__be32
17061714
nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
17071715
char *name, int len, struct svc_fh *tfhp)
17081716
{
17091717
struct dentry *ddir, *dnew, *dold;
17101718
struct inode *dirp;
1719+
int type;
17111720
__be32 err;
17121721
int host_err;
17131722

@@ -1727,19 +1736,19 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
17271736
if (isdotent(name, len))
17281737
goto out;
17291738

1739+
err = nfs_ok;
1740+
type = d_inode(tfhp->fh_dentry)->i_mode & S_IFMT;
17301741
host_err = fh_want_write(tfhp);
1731-
if (host_err) {
1732-
err = nfserrno(host_err);
1742+
if (host_err)
17331743
goto out;
1734-
}
17351744

17361745
ddir = ffhp->fh_dentry;
17371746
dirp = d_inode(ddir);
17381747
inode_lock_nested(dirp, I_MUTEX_PARENT);
17391748

17401749
dnew = lookup_one_len(name, ddir, len);
17411750
if (IS_ERR(dnew)) {
1742-
err = nfserrno(PTR_ERR(dnew));
1751+
host_err = PTR_ERR(dnew);
17431752
goto out_unlock;
17441753
}
17451754

@@ -1755,17 +1764,26 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
17551764
fh_fill_post_attrs(ffhp);
17561765
inode_unlock(dirp);
17571766
if (!host_err) {
1758-
err = nfserrno(commit_metadata(ffhp));
1759-
if (!err)
1760-
err = nfserrno(commit_metadata(tfhp));
1761-
} else {
1762-
err = nfserrno(host_err);
1767+
host_err = commit_metadata(ffhp);
1768+
if (!host_err)
1769+
host_err = commit_metadata(tfhp);
17631770
}
1771+
17641772
dput(dnew);
17651773
out_drop_write:
17661774
fh_drop_write(tfhp);
1775+
if (host_err == -EBUSY) {
1776+
/*
1777+
* See RFC 8881 Section 18.9.4 para 1-2: NFSv4 LINK
1778+
* wants a status unique to the object type.
1779+
*/
1780+
if (type != S_IFDIR)
1781+
err = nfserr_file_open;
1782+
else
1783+
err = nfserr_acces;
1784+
}
17671785
out:
1768-
return err;
1786+
return err != nfs_ok ? err : nfserrno(host_err);
17691787

17701788
out_dput:
17711789
dput(dnew);

0 commit comments

Comments
 (0)