Skip to content

Commit b3c78bc

Browse files
amir73ilbrauner
authored andcommitted
nfsd: do not allow exporting of special kernel filesystems
pidfs and nsfs recently gained support for encode/decode of file handles via name_to_handle_at(2)/open_by_handle_at(2). These special kernel filesystems have custom ->open() and ->permission() export methods, which nfsd does not respect and it was never meant to be used for exporting those filesystems by nfsd. Therefore, do not allow nfsd to export filesystems with custom ->open() or ->permission() methods. Fixes: b3caba8 ("pidfs: implement file handle support") Fixes: 5222470 ("nsfs: support file handles") Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Link: https://patch.msgid.link/20260129100212.49727-3-amir73il@gmail.com Reviewed-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent a39162f commit b3c78bc

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

fs/nfsd/export.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ static int check_export(const struct path *path, int *flags, unsigned char *uuid
427427
* either a device number (so FS_REQUIRES_DEV needed)
428428
* or an FSID number (so NFSEXP_FSID or ->uuid is needed).
429429
* 2: We must be able to find an inode from a filehandle.
430-
* This means that s_export_op must be set.
430+
* This means that s_export_op must be set and comply with
431+
* the requirements for remote filesystem export.
431432
* 3: We must not currently be on an idmapped mount.
432433
*/
433434
if (!(inode->i_sb->s_type->fs_flags & FS_REQUIRES_DEV) &&
@@ -437,8 +438,9 @@ static int check_export(const struct path *path, int *flags, unsigned char *uuid
437438
return -EINVAL;
438439
}
439440

440-
if (!exportfs_can_decode_fh(inode->i_sb->s_export_op)) {
441-
dprintk("exp_export: export of invalid fs type.\n");
441+
if (!exportfs_may_export(inode->i_sb->s_export_op)) {
442+
dprintk("exp_export: export of invalid fs type (%s).\n",
443+
inode->i_sb->s_type->name);
442444
return -EINVAL;
443445
}
444446

include/linux/exportfs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,15 @@ static inline bool exportfs_can_decode_fh(const struct export_operations *nop)
338338
return nop && nop->fh_to_dentry;
339339
}
340340

341+
static inline bool exportfs_may_export(const struct export_operations *nop)
342+
{
343+
/*
344+
* Do not allow nfs export for filesystems with custom ->open() or
345+
* ->permission() ops, which nfsd does not respect (e.g. pidfs, nsfs).
346+
*/
347+
return exportfs_can_decode_fh(nop) && !nop->open && !nop->permission;
348+
}
349+
341350
static inline bool exportfs_can_encode_fh(const struct export_operations *nop,
342351
int fh_flags)
343352
{

0 commit comments

Comments
 (0)