Skip to content

Commit 09bb8bf

Browse files
NeilBrownJ. Bruce Fields
authored andcommitted
exportfs: be careful to only return expected errors.
When nfsd calls fh_to_dentry, it expect ESTALE or ENOMEM as errors. In particular it can be tempting to return ENOENT, but this is not handled well by nfsd. Rather than requiring strict adherence to error code code filesystems, treat all unexpected error codes the same as ESTALE. This is safest. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 7d22fc1 commit 09bb8bf

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎fs/exportfs/expfs.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,10 @@ struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid,
428428
if (!nop || !nop->fh_to_dentry)
429429
return ERR_PTR(-ESTALE);
430430
result = nop->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fileid_type);
431-
if (!result)
432-
result = ERR_PTR(-ESTALE);
433-
if (IS_ERR(result))
434-
return result;
431+
if (PTR_ERR(result) == -ENOMEM)
432+
return ERR_CAST(result);
433+
if (IS_ERR_OR_NULL(result))
434+
return ERR_PTR(-ESTALE);
435435

436436
if (d_is_dir(result)) {
437437
/*
@@ -541,6 +541,8 @@ struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid,
541541

542542
err_result:
543543
dput(result);
544+
if (err != -ENOMEM)
545+
err = -ESTALE;
544546
return ERR_PTR(err);
545547
}
546548
EXPORT_SYMBOL_GPL(exportfs_decode_fh);

‎include/linux/exportfs.h‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ struct fid {
157157
* @fh_to_dentry is given a &struct super_block (@sb) and a file handle
158158
* fragment (@fh, @fh_len). It should return a &struct dentry which refers
159159
* to the same file that the file handle fragment refers to. If it cannot,
160-
* it should return a %NULL pointer if the file was found but no acceptable
161-
* &dentries were available, or an %ERR_PTR error code indicating why it
162-
* couldn't be found (e.g. %ENOENT or %ENOMEM). Any suitable dentry can be
163-
* returned including, if necessary, a new dentry created with d_alloc_root.
164-
* The caller can then find any other extant dentries by following the
165-
* d_alias links.
160+
* it should return a %NULL pointer if the file cannot be found, or an
161+
* %ERR_PTR error code of %ENOMEM if a memory allocation failure occurred.
162+
* Any other error code is treated like %NULL, and will cause an %ESTALE error
163+
* for callers of exportfs_decode_fh().
164+
* Any suitable dentry can be returned including, if necessary, a new dentry
165+
* created with d_alloc_root. The caller can then find any other extant
166+
* dentries by following the d_alias links.
166167
*
167168
* fh_to_parent:
168169
* Same as @fh_to_dentry, except that it returns a pointer to the parent

0 commit comments

Comments
 (0)