exportfs: add flag to allow marking export operations as only supporting file handles
Subsystems (6)
Christian Brauner
maintainercover exportfs: add flag to allow marking export operations as only supporting file handles
Hey,
Some filesystems like kernfs and pidfs support file handles as a convenience to enable the use of name_to_handle_at(2) and open_by_handle_at(2) but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly and make NFS check for its presence.
@Amir, I'll reorder the patches such that this series comes prior to the pidfs file handle series. Doing it that way will mean that there's never a state where pidfs supports file handles while also being exportable. It's probably not a big deal but it's definitely cleaner. It also means the last patch in this series to mark pidfs as non-exportable can be dropped. Instead pidfs export operations will be marked as non-exportable in the patch that they are added in.
Thanks!
Christian
---
Christian Brauner (4):
exportfs: add flag to indicate local file handles
kernfs: restrict to local file handles
ovl: restrict to exportable file handles
pidfs: restrict to local file handles
fs/kernfs/mount.c | 1 + fs/nfsd/export.c | 8 +++++++- fs/overlayfs/util.c | 7 ++++++- fs/pidfs.c | 1 + include/linux/exportfs.h | 1 + 5 files changed, 16 insertions(+), 2 deletions(-)
---
base-commit: 74e20c5946ab3f8ad959ea34f63f21e157d3ebae
change-id: 20241201-work-exportfs-cd49bee773c5
Christian Brauner
maintainerPATCH 1/4 exportfs: add flag to indicate local file handles
Some filesystems like kernfs and pidfs support file handles as a convenience to use name_to_handle_at(2) and open_by_handle_at(2) but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly.
--- fs/nfsd/export.c | 8 +++++++- include/linux/exportfs.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)
fs/nfsd/export.c +7 -1
@@ -417,6 +417,7 @@ static struct svc_export *svc_export_lookup(struct svc_export *);static int check_export (struct path *path,int *flags,unsigned char *uuid) {struct inode *inode =d_inode (path->dentry); +const struct export_operations *nop;/* * We currently export only dirs, regular files, and (for v4
@@ -449,11 +450,16 @@ static int check_export(struct path *path, int *flags, unsigned char *uuid)return -EINVAL ; } -if (!exportfs_can_decode_fh (inode->i_sb->s_export_op)) { +if (!exportfs_can_decode_fh (nop)) {dprintk ("exp_export: export of invalid fs type.\n" );return -EINVAL ; } +if (nop && nop->flags &EXPORT_OP_LOCAL_FILE_HANDLE ) { +dprintk ("exp_export: filesystem only supports non-exportable file handles.\n" ); +return -EINVAL ; + } +if (is_idmapped_mnt (path->mnt)) {dprintk ("exp_export: export of idmapped mounts not yet supported.\n" );return -EINVAL ;
include/linux/exportfs.h +1 -0
@@ -280,6 +280,7 @@ struct export_operations {*/ #define EXPORT_OP_FLUSH_ON_CLOSE (0x20)/* fs flushes file data on close */ #define EXPORT_OP_ASYNC_LOCK (0x40)/* fs can do async lock request */ +#define EXPORT_OP_LOCAL_FILE_HANDLE (0x80)/* fs only supports file handles, no proper export */ unsigned long flags; };
Signature · 1 line
2.45.2
Amir Goldstein
maintainerRe: [PATCH 1/4] exportfs: add flag to indicate local file handles
Quoted 49 lines · Christian Brauner
Some filesystems like kernfs and pidfs support file handles as a convenience to use
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly.Fixes aa8188253474 ("kernfs: add exportfs operations")Cc stable <[email protected]> # >= 4.14Signed-off-by Christian Brauner <[email protected]>--- fs/nfsd/export.c | 8 +++++++- include/linux/exportfs.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)fs/nfsd/export.c +7
-1@@ -417,6 +417,7 @@ static struct svc_export *svc_export_lookup(struct svc_export *);static int check_export (struct path *path,int *flags,unsigned char *uuid) {struct inode *inode =d_inode (path->dentry); +const struct export_operations *nop;/* * We currently export only dirs, regular files, and (for v4 @@ -449,11 +450,16 @@ static int check_export(struct path *path, int *flags, unsigned char *uuid)return -EINVAL ; } -if (!exportfs_can_decode_fh (inode->i_sb->s_export_op)) { +if (!exportfs_can_decode_fh (nop)) {dprintk ("exp_export: export of invalid fs type.\n" );return -EINVAL ; } +if (nop && nop->flags &EXPORT_OP_LOCAL_FILE_HANDLE ) { +dprintk ("exp_export: filesystem only supports non-exportable file handles.\n" ); +return -EINVAL ; + } +if (is_idmapped_mnt (path->mnt)) {dprintk ("exp_export: export of idmapped mounts not yet supported.\n" );return -EINVAL ;include/linux/exportfs.h +0
-0
include/linux/exportfs.h struct export_operations { · line 285
Quoted 6 lines
include/linux/exportfs.h +1
-0@@ -280,6 +280,7 @@ struct export_operations {*/ #define EXPORT_OP_FLUSH_ON_CLOSE (0x20)/* fs flushes file data on close */ #define EXPORT_OP_ASYNC_LOCK (0x40)/* fs can do async lock request */ +#define EXPORT_OP_LOCAL_FILE_HANDLE (0x80)/* fs only supports file handles, no proper export */ unsigned long flags; };
Please update Documentation/filesystems/nfs/exporting.rst.
Thanks,
Amir.
kernel test robot
build botRe: [PATCH 1/4] exportfs: add flag to indicate local file handles
In reply to Christian Braunerkernel test robot noticed the following build warnings:
Hi Christian,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 74e20c5946ab3f8ad959ea34f63f21e157d3ebae]
url: https://github.com/intel-lab-lkp/linux/commits/Christian-Brauner/exportfs-add-flag-to-indicate-local-file-handles/20241201-211528 base: 74e20c5946ab3f8ad959ea34f63f21e157d3ebae patch link: https://lore.kernel.org/r/20241201-work-exportfs-v1-1-b850dda4502a%40kernel.org patch subject: [PATCH 1/4] exportfs: add flag to indicate local file handles config: arm-footbridge_defconfig (https://download.01.org/0day-ci/archive/20241201/[email protected]/config) compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 592c0fe55f6d9a811028b5f3507be91458ab2713) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241201/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from fs/nfsd/export.c:19:
In file included from include/linux/sunrpc/svc_xprt.h:11:
In file included from include/linux/sunrpc/svc.h:17:
In file included from include/linux/sunrpc/xdr.h:17:
In file included from include/linux/scatterlist.h:8:
In file included from include/linux/mm.h:2223:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
>> fs/nfsd/export.c:458:6: warning: variable 'nop' is uninitialized when used here [-Wuninitialized]
458 | if (nop && nop->flags & EXPORT_OP_LOCAL_FILE_HANDLE) {
| ^~~
fs/nfsd/export.c:420:37: note: initialize the variable 'nop' to silence this warning
420 | const struct export_operations *nop;
| ^
| = NULL
fs/nfsd/export.c:1045:17: warning: variable 'inode' set but not used [-Wunused-but-set-variable]
1045 | struct inode *inode;
| ^3 warnings generated.
vim +/nop +458 fs/nfsd/export.c
416
417 static int check_export(struct path *path, int *flags, unsigned char *uuid)
418 {
419 struct inode *inode = d_inode(path->dentry);
420 const struct export_operations *nop;
421
422 /*
423 * We currently export only dirs, regular files, and (for v4
424 * pseudoroot) symlinks.
425 */
426 if (!S_ISDIR(inode->i_mode) &&
427 !S_ISLNK(inode->i_mode) &&
428 !S_ISREG(inode->i_mode))
429 return -ENOTDIR;
430
431 /*
432 * Mountd should never pass down a writeable V4ROOT export, but,
433 * just to make sure:
434 */
435 if (*flags & NFSEXP_V4ROOT)
436 *flags |= NFSEXP_READONLY;
437
438 /* There are two requirements on a filesystem to be exportable.
439 * 1: We must be able to identify the filesystem from a number.
440 * either a device number (so FS_REQUIRES_DEV needed)
441 * or an FSID number (so NFSEXP_FSID or ->uuid is needed).
442 * 2: We must be able to find an inode from a filehandle.
443 * This means that s_export_op must be set.
444 * 3: We must not currently be on an idmapped mount.
445 */
446 if (!(inode->i_sb->s_type->fs_flags & FS_REQUIRES_DEV) &&
447 !(*flags & NFSEXP_FSID) &&
448 uuid == NULL) {
449 dprintk("exp_export: export of non-dev fs without fsid\n");
450 return -EINVAL;
451 }
452
453 if (!exportfs_can_decode_fh(nop)) {
454 dprintk("exp_export: export of invalid fs type.\n");
455 return -EINVAL;
456 }
457
> 458 if (nop && nop->flags & EXPORT_OP_LOCAL_FILE_HANDLE) { 459 dprintk("exp_export: filesystem only supports non-exportable file handles.\n");
460 return -EINVAL;
461 }
462
463 if (is_idmapped_mnt(path->mnt)) {
464 dprintk("exp_export: export of idmapped mounts not yet supported.\n");
465 return -EINVAL;
466 }
467
468 if (inode->i_sb->s_export_op->flags & EXPORT_OP_NOSUBTREECHK &&
469 !(*flags & NFSEXP_NOSUBTREECHECK)) {
470 dprintk("%s: %s does not support subtree checking!\n",
471 __func__, inode->i_sb->s_type->name);
472 return -EINVAL;
473 }
474 return 0;
475 }
476
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 1/4] exportfs: add flag to indicate local file handles
In reply to Christian BraunerQuoted 26 lines · Christian Brauner
Some filesystems like kernfs and pidfs support file handles as a convenience to use
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly.Fixes aa8188253474 ("kernfs: add exportfs operations")Cc stable <[email protected]> # >= 4.14Signed-off-by Christian Brauner <[email protected]>--- fs/nfsd/export.c | 8 +++++++- include/linux/exportfs.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)fs/nfsd/export.c +1
-0@@ -417,6 +417,7 @@ static struct svc_export *svc_export_lookup(struct svc_export *);static int check_export (struct path *path,int *flags,unsigned char *uuid) {struct inode *inode =d_inode (path->dentry); +const struct export_operations *nop;/* * We currently export only dirs, regular files, and (for v4
fs/nfsd/export.c static int check_export(struct path *path, int *flags, unsigned char *uuid) · line 453
Quoted 5 lines
fs/nfsd/export.c +1
-1@@ -449,11 +450,16 @@ static int check_export(struct path *path, int *flags, unsigned char *uuid)return -EINVAL ; } -if (!exportfs_can_decode_fh (inode->i_sb->s_export_op)) { +if (!exportfs_can_decode_fh (nop)) {
Where is nop initialised?
fs/nfsd/export.c static int check_export(struct path *path, int *flags, unsigned char *uuid) · line 458
Quoted 5 lines
fs/nfsd/export.c +1
-0dprintk ("exp_export: export of invalid fs type.\n" );return -EINVAL ; } +if (nop && nop->flags &EXPORT_OP_LOCAL_FILE_HANDLE ) {
Also, please use () around & operations so we can understand that this is not an accidental typo. i.e:
if (nop && (nop->flags & EXPORT_OP_LOCAL_FILE_HANDLE)) {clearly expresses the intent of the code, and now it is obviously correct at a glance.
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Christian Brauner
maintainerRe: [PATCH 1/4] exportfs: add flag to indicate local file handles
Quoted 30 lines · Dave Chinner
Quoted 29 lines · Christian Brauner
Some filesystems like kernfs and pidfs support file handles as a convenience to use
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly.Fixes aa8188253474 ("kernfs: add exportfs operations")Cc stable <[email protected]> # >= 4.14Signed-off-by Christian Brauner <[email protected]>--- fs/nfsd/export.c | 8 +++++++- include/linux/exportfs.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)fs/nfsd/export.c +1
-0@@ -417,6 +417,7 @@ static struct svc_export *svc_export_lookup(struct svc_export *);static int check_export (struct path *path,int *flags,unsigned char *uuid) {struct inode *inode =d_inode (path->dentry); +const struct export_operations *nop;/* * We currently export only dirs, regular files, and (for v4 @@ -449,11 +450,16 @@ static int check_export(struct path *path, int *flags, unsigned char *uuid)return -EINVAL ; }
Quoted 4 lines
fs/nfsd/export.c static int check_export(struct path *path, int *flags, unsigned char *uuid) · line 453
Quoted 2 lines
fs/nfsd/export.c +1
-1-if (!exportfs_can_decode_fh (inode->i_sb->s_export_op)) { +if (!exportfs_can_decode_fh (nop)) {Where is nop initialised?
Yep, already fixed in tree yesterday. Thanks for catching this though!
Quoted 10 lines
fs/nfsd/export.c static int check_export(struct path *path, int *flags, unsigned char *uuid) · line 458
Quoted 6 lines
fs/nfsd/export.c +1
-0dprintk ("exp_export: export of invalid fs type.\n" );return -EINVAL ; } +if (nop && nop->flags &EXPORT_OP_LOCAL_FILE_HANDLE ) {Also, please use () around & operations so we can understand that this is not an accidental typo. i.e:
Quoted 4 lines
if (nop && (nop->flags & EXPORT_OP_LOCAL_FILE_HANDLE)) {clearly expresses the intent of the code, and now it is obviously correct at a glance.
Done.
Christian Brauner
maintainerPATCH 2/4 kernfs: restrict to local file handles
In reply to Christian BraunerThe kernfs filesystem uses local file handles that cannot be exported. Mark its export operations accordingly.
--- fs/kernfs/mount.c | 1 + 1 file changed, 1 insertion(+)
fs/kernfs/mount.c +1 -0
@@ -154,6 +154,7 @@ static const struct export_operations kernfs_export_ops = { .fh_to_dentry = kernfs_fh_to_dentry, .fh_to_parent = kernfs_fh_to_parent, .get_parent = kernfs_get_parent_dentry, + .flags = EXPORT_OP_LOCAL_FILE_HANDLE, };/**
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 3/4 ovl: restrict to exportable file handles
In reply to Christian BraunerEnsure that overlayfs only allows decoding exportable file handles.
--- fs/overlayfs/util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/overlayfs/util.c +6 -1
@@ -83,10 +83,15 @@ void ovl_revert_creds(const struct cred *old_cred)*/ int ovl_can_decode_fh (struct super_block *sb) { +const struct export_operations *nop = sb->s_export_op; +if (!capable (CAP_DAC_READ_SEARCH ))return 0 ; -if (!exportfs_can_decode_fh (sb->s_export_op)) +if (!exportfs_can_decode_fh (nop)) +return 0 ; + +if (nop && nop->flags &EXPORT_OP_LOCAL_FILE_HANDLE )return 0 ;return sb->s_export_op->encode_fh ?-1 :FILEID_INO32_GEN ;
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 4/4 pidfs: restrict to local file handles
In reply to Christian BraunerThe pidfs filesystem uses local file handles that cannot be exported. Mark its export operations accordingly.
--- fs/pidfs.c | 1 + 1 file changed, 1 insertion(+)
fs/pidfs.c +1 -0
@@ -570,6 +570,7 @@ static const struct export_operations pidfs_export_operations = { .fh_to_dentry = pidfs_fh_to_dentry, .open = pidfs_export_open, .permission = pidfs_export_permission, + .flags = EXPORT_OP_LOCAL_FILE_HANDLE, };static int pidfs_init_inode (struct inode *inode,void *data)
Signature · 1 line
2.45.2
Quoted 32 lines · Christian Brauner
Hey,
Some filesystems like kernfs and pidfs support file handles as a convenience to enable the use of
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly and make NFS check for its presence.@Amir, I'll reorder the patches such that this series comes prior to the pidfs file handle series. Doing it that way will mean that there's never a state where pidfs supports file handles while also being exportable. It's probably not a big deal but it's definitely cleaner. It also means the last patch in this series to mark pidfs as non-exportable can be dropped. Instead pidfs export operations will be marked as non-exportable in the patch that they are added in.
Thanks!
Christian---
Christian Brauner (4):
exportfs: add flag to indicate local file handles
kernfs: restrict to local file handles
ovl: restrict to exportable file handles
pidfs: restrict to local file handlesfs/kernfs/mount.c | 1 + fs/nfsd/export.c | 8 +++++++- fs/overlayfs/util.c | 7 ++++++- fs/pidfs.c | 1 + include/linux/exportfs.h | 1 + 5 files changed, 16 insertions(+), 2 deletions(-)
Quoted 4 lines
---
base-commit:74e20c5946ab3f8ad959ea34f63f21e157d3ebae
change-id: 20241201-work-exportfs-cd49bee773c5
I've been following the pidfs filehandle discussion and this is exactly what I was thinking we needed: a way to explicitly label certain fstypes as unexportable via nfsd.
Chuck Lever III
Acked-by Chuck LeverQuoted 42 lines · Jeff Layton
Quoted 32 lines · Christian Brauner
Hey,
Some filesystems like kernfs and pidfs support file handles as a convenience to enable the use of
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly and make NFS check for its presence.@Amir, I'll reorder the patches such that this series comes prior to the pidfs file handle series. Doing it that way will mean that there's never a state where pidfs supports file handles while also being exportable. It's probably not a big deal but it's definitely cleaner. It also means the last patch in this series to mark pidfs as non-exportable can be dropped. Instead pidfs export operations will be marked as non-exportable in the patch that they are added in.
Thanks!
Christian---
Christian Brauner (4):
exportfs: add flag to indicate local file handles
kernfs: restrict to local file handles
ovl: restrict to exportable file handles
pidfs: restrict to local file handlesfs/kernfs/mount.c | 1 + fs/nfsd/export.c | 8 +++++++- fs/overlayfs/util.c | 7 ++++++- fs/pidfs.c | 1 + include/linux/exportfs.h | 1 + 5 files changed, 16 insertions(+), 2 deletions(-)Quoted 4 lines
---
base-commit:74e20c5946ab3f8ad959ea34f63f21e157d3ebae
change-id: 20241201-work-exportfs-cd49bee773c5
Quoted 6 lines
I've been following the pidfs filehandle discussion and this is exactly what I was thinking we needed: a way to explicitly label certain fstypes as unexportable via nfsd.
Reviewed-by Jeff Layton <[email protected]>
Though, I wonder if a similar but separate prohibition mechanism might be necessary for other in-kernel network file system server implementations (eg, ksmbd).
--
Chuck Lever
Christian Brauner
maintainerQuoted 3 lines
Though, I wonder if a similar but separate prohibition mechanism might be necessary for other in-kernel network file system server implementations (eg, ksmbd).
Oh hm, interesting question.
I have no idea how ksmbd or 9p "exports" work. I really hope they don't allow exporting arbitrary pseudo-fses.
Jeff Layton
maintainerQuoted 7 lines · Christian Brauner
Quoted 3 lines
Though, I wonder if a similar but separate prohibition mechanism might be necessary for other in-kernel network file system server implementations (eg, ksmbd).
Oh hm, interesting question.
I have no idea how ksmbd or 9p "exports" work. I really hope they don't allow exporting arbitrary pseudo-fses.
SMB is path-based so there's no worry about filehandles there. It looks like ksmbd keeps a set of ksmbd_share_config objects, that are configured by userland. If someone deliberately shares stuff under /proc, then I guess they get to keep all of the pieces. ;)
9P does use filehandles, but there is no in-kernel server, so far. Wedson had one in development at one point [1], but I haven't heard anything about it in a while.
[1]: https://kangrejos.com/Async%20Rust%20and%209p%20server.pdf
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 9 lines · Christian Brauner
Hey,
Some filesystems like kernfs and pidfs support file handles as a convenience to enable the use of
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly and make NFS check for its presence.
Quoted 7 lines
@Amir, I'll reorder the patches such that this series comes prior to the pidfs file handle series. Doing it that way will mean that there's never a state where pidfs supports file handles while also being exportable. It's probably not a big deal but it's definitely cleaner. It also means the last patch in this series to mark pidfs as non-exportable can be dropped. Instead pidfs export operations will be marked as non-exportable in the patch that they are added in.
Yeh, looks good!
Apart from missing update to exporting.rst
Thanks,
Amir.
Quoted 8 lines · Christian Brauner
Hey,
Some filesystems like kernfs and pidfs support file handles as a convenience to enable the use of
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly and make NFS check for its presence.
Quoted 7 lines
@Amir, I'll reorder the patches such that this series comes prior to the pidfs file handle series. Doing it that way will mean that there's never a state where pidfs supports file handles while also being exportable. It's probably not a big deal but it's definitely cleaner. It also means the last patch in this series to mark pidfs as non-exportable can be dropped. Instead pidfs export operations will be marked as non-exportable in the patch that they are added in.
Can you please invert the polarity? Marking something as not supporting is always awkward. Clearly marking it as supporting something (and writing down in detail what is required for that) is much better, even it might cause a little more churn initially.
Christian Brauner
maintainerQuoted 17 lines · Christoph Hellwig
Quoted 8 lines · Christian Brauner
Hey,
Some filesystems like kernfs and pidfs support file handles as a convenience to enable the use of
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly and make NFS check for its presence.Quoted 7 lines
@Amir, I'll reorder the patches such that this series comes prior to the pidfs file handle series. Doing it that way will mean that there's never a state where pidfs supports file handles while also being exportable. It's probably not a big deal but it's definitely cleaner. It also means the last patch in this series to mark pidfs as non-exportable can be dropped. Instead pidfs export operations will be marked as non-exportable in the patch that they are added in.
Quoted 4 lines
Can you please invert the polarity? Marking something as not supporting is always awkward. Clearly marking it as supporting something (and writing down in detail what is required for that) is much better, even it might cause a little more churn initially.
Fine by me but let's do that as a cleanup on top, please. Especially because we need to backport this to stable.
Amir Goldstein
maintainerQuoted 18 lines · Christoph Hellwig
Quoted 8 lines · Christian Brauner
Hey,
Some filesystems like kernfs and pidfs support file handles as a convenience to enable the use of
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly and make NFS check for its presence.Quoted 7 lines
@Amir, I'll reorder the patches such that this series comes prior to the pidfs file handle series. Doing it that way will mean that there's never a state where pidfs supports file handles while also being exportable. It's probably not a big deal but it's definitely cleaner. It also means the last patch in this series to mark pidfs as non-exportable can be dropped. Instead pidfs export operations will be marked as non-exportable in the patch that they are added in.
Quoted 5 lines
Can you please invert the polarity? Marking something as not supporting is always awkward. Clearly marking it as supporting something (and writing down in detail what is required for that) is much better, even it might cause a little more churn initially.
Churn would be a bit annoying, but I guess it makes sense. I agree with Christian that it should be done as cleanup to allow for easier backport.
Please suggest a name for this opt-in flag.EXPORT_OP_NFS_EXPORT???
Thanks,
Amir.
Quoted 25 lines · Amir Goldstein
Quoted 18 lines · Christoph Hellwig
Quoted 8 lines · Christian Brauner
Hey,
Some filesystems like kernfs and pidfs support file handles as a convenience to enable the use of
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly and make NFS check for its presence.Quoted 7 lines
@Amir, I'll reorder the patches such that this series comes prior to the pidfs file handle series. Doing it that way will mean that there's never a state where pidfs supports file handles while also being exportable. It's probably not a big deal but it's definitely cleaner. It also means the last patch in this series to mark pidfs as non-exportable can be dropped. Instead pidfs export operations will be marked as non-exportable in the patch that they are added in.
Quoted 5 lines
Can you please invert the polarity? Marking something as not supporting is always awkward. Clearly marking it as supporting something (and writing down in detail what is required for that) is much better, even it might cause a little more churn initially.
Quoted 6 lines
Churn would be a bit annoying, but I guess it makes sense. I agree with Christian that it should be done as cleanup to allow for easier backport.
Please suggest a name for this opt-in flag.
EXPORT_OP_NFS_EXPORT???
That's probably too specific to NFS--
AFAICT the goal here is to prevent exporting {pid,kern}fs file handles to other nodes, correct? Because we don't want to allow a process on another computer to mess around with processes on the local computer?
How about:
/* file handles can be used by a process on another node */
#define EXPORT_OP_ALLOW_REMOTE_NODES (...)
--D
Quoted 3 lines
Thanks,
Amir.
Amir Goldstein
maintainerQuoted 36 lines · Darrick J. Wong
Quoted 25 lines · Amir Goldstein
Quoted 18 lines · Christoph Hellwig
Quoted 8 lines · Christian Brauner
Hey,
Some filesystems like kernfs and pidfs support file handles as a convenience to enable the use of
name_to_handle_at(2)andopen_by_handle_at(2)but don't want to and cannot be reliably exported. Add a flag that allows them to mark their export operations accordingly and make NFS check for its presence.Quoted 7 lines
@Amir, I'll reorder the patches such that this series comes prior to the pidfs file handle series. Doing it that way will mean that there's never a state where pidfs supports file handles while also being exportable. It's probably not a big deal but it's definitely cleaner. It also means the last patch in this series to mark pidfs as non-exportable can be dropped. Instead pidfs export operations will be marked as non-exportable in the patch that they are added in.
Quoted 5 lines
Can you please invert the polarity? Marking something as not supporting is always awkward. Clearly marking it as supporting something (and writing down in detail what is required for that) is much better, even it might cause a little more churn initially.
Quoted 6 lines
Churn would be a bit annoying, but I guess it makes sense. I agree with Christian that it should be done as cleanup to allow for easier backport.
Please suggest a name for this opt-in flag.
EXPORT_OP_NFS_EXPORT???That's probably too specific to NFS--
Quoted 8 lines
AFAICT the goal here is to prevent exporting {pid,kern}fs file handles to other nodes, correct? Because we don't want to allow a process on another computer to mess around with processes on the local computer?
How about:
/* file handles can be used by a process on another node */
#defineEXPORT_OP_ALLOW_REMOTE_NODES(...)
This has a sound of security which is incorrect IMO.
The fact that we block nfsd export of cgroups does not prevent any type of userland file server from exporting cgroup file handles.
I hate to be a pain, but IMO, the claim that inverted polarity is clearer is not a consensus and there are plenty of counter examples. I do not object to inverting the polarity if a flag name is found that explains the property well, but IMO, this is not it.
Maybe opt-out of nfsd export is a little less safer than opt-in, but
1. opt-out is and will remain the rare exception for export_operations
2. at least the flag name EXPORT_OP_LOCAL_FILE_HANDLE
is pretty clear IMO
Plus, as I wrote in another email, the fact that pidfs is SB_NOUSER, so userspace is not allowed to mount it into the namespace and userland file servers cannot export the filesystem itself.
That property itself (SB_NOUSER), is therefore a good enough indication to deny nfsd export of this fs.
So really the immediate need for an explicit flag is only to stop exporting kernfs/cgroupfs and I don't see this need spreading much further (perhaps to nsfs) and therefore, the value of inverting to opt-in is questionable IMO.
Thanks,
Amir.
Quoted 6 lines · Amir Goldstein
Quoted 2 lines
/* file handles can be used by a process on another node */
#defineEXPORT_OP_ALLOW_REMOTE_NODES(...)This has a sound of security which is incorrect IMO.
The fact that we block nfsd export of cgroups does not prevent any type of userland file server from exporting cgroup file handles.
So what is the purpose of the flag? Asking for a coherent name and description was the other bigger ask for me.
Quoted 4 lines
Maybe opt-out of nfsd export is a little less safer than opt-in, but
1. opt-out is and will remain the rare exception forexport_operations
2. at least the flag nameEXPORT_OP_LOCAL_FILE_HANDLE
is pretty clear IMO
Even after this thread I have absolutely no idea what problem it tries to solve. Maybe that's not just the flag names fault, and not of opt-in vs out, but both certainly don't help.
Quoted 5 lines
Plus, as I wrote in another email, the fact that pidfs is
SB_NOUSER, so userspace is not allowed to mount it into the namespace and userland file servers cannot export the filesystem itself. That property itself (SB_NOUSER), is therefore a good enough indication to deny nfsd export of this fs.
So check SB_NOUSER in nfsd and be done with it?
Amir Goldstein
maintainerQuoted 21 lines · Christoph Hellwig
Quoted 6 lines · Amir Goldstein
Quoted 2 lines
/* file handles can be used by a process on another node */
#defineEXPORT_OP_ALLOW_REMOTE_NODES(...)This has a sound of security which is incorrect IMO.
The fact that we block nfsd export of cgroups does not prevent any type of userland file server from exporting cgroup file handles.So what is the purpose of the flag? Asking for a coherent name and description was the other bigger ask for me.
Quoted 4 lines
Maybe opt-out of nfsd export is a little less safer than opt-in, but
1. opt-out is and will remain the rare exception forexport_operations
2. at least the flag nameEXPORT_OP_LOCAL_FILE_HANDLE
is pretty clear IMOEven after this thread I have absolutely no idea what problem it tries to solve. Maybe that's not just the flag names fault, and not of opt-in vs out, but both certainly don't help.
Quoted 8 lines
Quoted 5 lines
Plus, as I wrote in another email, the fact that pidfs is
SB_NOUSER, so userspace is not allowed to mount it into the namespace and userland file servers cannot export the filesystem itself. That property itself (SB_NOUSER), is therefore a good enough indication to deny nfsd export of this fs.So check
SB_NOUSERin nfsd and be done with it?
That will work for the new user (pidfs).
I think SB_KERNMOUNT qualifies as well, because it signifies a mount that does not belong to any user's mount namespace.
For example, tmpfs (shmem) can be exported via nfs, but trying to export an anonymous memfd should fail.
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new mount_fd and magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.
The thinking behind adding the EXPORT_OP_LOCAL_FILE_HANDLE flag was that when kernfs/cgroups was added exportfs support with commit aa8188253474 ("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.
[CC patch authors]
I tried to look for some property of cgroupfs that will make it not eligible for nfs such as the SB_KERNMOUNT and SB_NOUSER indicators, but as far as I can see cgroups looks like any other non-blockdev filesystem.
Maybe we were wrong about the assumption that cgroupfs should be treated specially and deny export cgroups over nfs??
Thanks,
Amir.
Greg KH
maintainerQuoted 51 lines · Amir Goldstein
Quoted 21 lines · Christoph Hellwig
Quoted 6 lines · Amir Goldstein
Quoted 2 lines
/* file handles can be used by a process on another node */
#defineEXPORT_OP_ALLOW_REMOTE_NODES(...)This has a sound of security which is incorrect IMO.
The fact that we block nfsd export of cgroups does not prevent any type of userland file server from exporting cgroup file handles.So what is the purpose of the flag? Asking for a coherent name and description was the other bigger ask for me.
Quoted 4 lines
Maybe opt-out of nfsd export is a little less safer than opt-in, but
1. opt-out is and will remain the rare exception forexport_operations
2. at least the flag nameEXPORT_OP_LOCAL_FILE_HANDLE
is pretty clear IMOEven after this thread I have absolutely no idea what problem it tries to solve. Maybe that's not just the flag names fault, and not of opt-in vs out, but both certainly don't help.
Quoted 8 lines
Quoted 5 lines
Plus, as I wrote in another email, the fact that pidfs is
SB_NOUSER, so userspace is not allowed to mount it into the namespace and userland file servers cannot export the filesystem itself. That property itself (SB_NOUSER), is therefore a good enough indication to deny nfsd export of this fs.So check
SB_NOUSERin nfsd and be done with it?That will work for the new user (pidfs).
I think
SB_KERNMOUNTqualifies as well, because it signifies a mount that does not belong to any user's mount namespace.For example, tmpfs (shmem) can be exported via nfs, but trying to export an anonymous memfd should fail.
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.
Quoted 8 lines
[CC patch authors]
I tried to look for some property of cgroupfs that will make it not eligible for nfs such as the
SB_KERNMOUNTandSB_NOUSERindicators, but as far as I can see cgroups looks like any other non-blockdev filesystem.Maybe we were wrong about the assumption that cgroupfs should be treated specially and deny export cgroups over nfs??
Please don't export any of the "fake" kernel filesystems (configfs, cgroups, sysfs, debugfs, proc, etc) over nfs please. That way lies madness and makes no sense.
thanks,
greg k-h
Amir Goldstein
maintainerQuoted 59 lines · Greg KH
Quoted 57 lines · Amir Goldstein
Quoted 21 lines · Christoph Hellwig
Quoted 6 lines · Amir Goldstein
Quoted 2 lines
/* file handles can be used by a process on another node */
#defineEXPORT_OP_ALLOW_REMOTE_NODES(...)This has a sound of security which is incorrect IMO.
The fact that we block nfsd export of cgroups does not prevent any type of userland file server from exporting cgroup file handles.So what is the purpose of the flag? Asking for a coherent name and description was the other bigger ask for me.
Quoted 4 lines
Maybe opt-out of nfsd export is a little less safer than opt-in, but
1. opt-out is and will remain the rare exception forexport_operations
2. at least the flag nameEXPORT_OP_LOCAL_FILE_HANDLE
is pretty clear IMOEven after this thread I have absolutely no idea what problem it tries to solve. Maybe that's not just the flag names fault, and not of opt-in vs out, but both certainly don't help.
Quoted 8 lines
Quoted 5 lines
Plus, as I wrote in another email, the fact that pidfs is
SB_NOUSER, so userspace is not allowed to mount it into the namespace and userland file servers cannot export the filesystem itself. That property itself (SB_NOUSER), is therefore a good enough indication to deny nfsd export of this fs.So check
SB_NOUSERin nfsd and be done with it?That will work for the new user (pidfs).
I think
SB_KERNMOUNTqualifies as well, because it signifies a mount that does not belong to any user's mount namespace.For example, tmpfs (shmem) can be exported via nfs, but trying to export an anonymous memfd should fail.
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.[CC patch authors]
I tried to look for some property of cgroupfs that will make it not eligible for nfs such as the
SB_KERNMOUNTandSB_NOUSERindicators, but as far as I can see cgroups looks like any other non-blockdev filesystem.
Quoted 6 lines
Quoted 2 lines
Maybe we were wrong about the assumption that cgroupfs should be treated specially and deny export cgroups over nfs??
Please don't export any of the "fake" kernel filesystems (configfs, cgroups, sysfs, debugfs, proc, etc) over nfs please. That way lies madness and makes no sense.
Agreed. The problem is that when looking in vfs for a clear definition of "fake" kernel filesystems, I cannot find an objective criteria, especially for those "fake" fs that you listed.
The "pseudo" filesystems (that call init_pseudo()) which are clearly marked with SB_NOUSER (except for nsfs)
The "internal" filesystems that use kern_mount() internal mount ns are clearly marked with SB_KERNMOUNT.
One commonality that I found among most fs that have a known sysfs mount point is that they use get_tree_single() because they are "singleton" filesystems. However, a singleton filesystem may not be fake (efivarfs, openpromfs), so I am not sure this is a good indication for no nfs export and in any case, this it not true for procfs, sysfs, cgroups (kernfs).
We are left with the fact that there is no clear criteria with the list of "fake" filesystems that you mentioned and among that list, only cgroupfs has implemented file handles, so I see two options:
1. Explicitly opt-out of nfs export for cgroups as the proposed patch set does
2. Clearly mark all "fake" filesystems, for whatever "fake" means with SB_<WHATEVER> and then let nfsd query the "fake" fs flag
#1 is pretty straightforward.
#2 means this discussion will go on for some time and that I may eventually need to submit a "What is a fake filesystem?" topic to LSFMM ;)
Thanks,
Amir.
Quoted 6 lines · Greg KH
Quoted 2 lines
Maybe we were wrong about the assumption that cgroupfs should be treated specially and deny export cgroups over nfs??
Please don't export any of the "fake" kernel filesystems (configfs, cgroups, sysfs, debugfs, proc, etc) over nfs please. That way lies madness and makes no sense.
Umm, yes: it sounds like a pretty useless idea. But you can do that today with a userland nfs server, so why explicitly forbid it for the kernel nfs server. In either case you absolutely have to want it, you're not going to accidentally NFS export a file system.
I'm still trying to understand what problem we're trying to solve here.
Quoted 11 lines · Amir Goldstein
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.
Can you please explain what the problem with exporting these file systems over NFS is? Yes, it's not going to be very useful. But what is actually problematic about it? Any why is it not problematic with a userland nfs server? We really need to settle that argumet before deciding a flag name or polarity.
Amir Goldstein
maintainerQuoted 14 lines · Christoph Hellwig
Quoted 11 lines · Amir Goldstein
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.
Quoted 6 lines
Can you please explain what the problem with exporting these file systems over NFS is? Yes, it's not going to be very useful. But what is actually problematic about it? Any why is it not problematic with a userland nfs server? We really need to settle that argumet before deciding a flag name or polarity.
I agree that it is not the end of the world and users do have to explicitly use fsid= argument to be able to export cgroupfs via nfsd.
The idea for this patch started from the claim that Jeff wrote that cgroups is not allowed for nfsd export, but I couldn't find where it is not allowed.
I have no issue personally with leaving cgroupfs exportable via nfsd and changing restricting only SB_NOUSER and SB_KERNMOUNT fs.
Jeff, Chuck, what is your opinion w.r.t exportability of cgroupfs via nfsd?
Thanks,
Amir.
Quoted 25 lines · Amir Goldstein
Quoted 14 lines · Christoph Hellwig
Quoted 11 lines · Amir Goldstein
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.Quoted 6 lines
Can you please explain what the problem with exporting these file systems over NFS is? Yes, it's not going to be very useful. But what is actually problematic about it? Any why is it not problematic with a userland nfs server? We really need to settle that argumet before deciding a flag name or polarity.
I agree that it is not the end of the world and users do have to explicitly use fsid= argument to be able to export cgroupfs via nfsd.
Quoted 7 lines
The idea for this patch started from the claim that Jeff wrote that cgroups is not allowed for nfsd export, but I couldn't find where it is not allowed.
I have no issue personally with leaving cgroupfs exportable via nfsd and changing restricting only
SB_NOUSERandSB_KERNMOUNTfs.Jeff, Chuck, what is your opinion w.r.t exportability of cgroupfs via nfsd?
We all seem to be hard-pressed to find a usage scenario where exporting pseudo-filesystems via NFS is valuable. But maybe someone has done it and has a good reason for it.
The issue is whether such export should be consistently and actively prevented.
I'm not aware of any specific security issues with it.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerQuoted 23 lines · Chuck Lever
Quoted 22 lines · Amir Goldstein
Quoted 20 lines · Christoph Hellwig
Quoted 11 lines · Amir Goldstein
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.Can you please explain what the problem with exporting these file systems over NFS is? Yes, it's not going to be very useful. But what is actually problematic about it? Any why is it not problematic with a userland nfs server? We really need to settle that argumet before deciding a flag name or polarity.
Quoted 6 lines
Quoted 6 lines
I agree that it is not the end of the world and users do have to explicitly use fsid= argument to be able to export cgroupfs via nfsd.
The idea for this patch started from the claim that Jeff wrote that cgroups is not allowed for nfsd export, but I couldn't find where it is not allowed.
I think that must have been a wrong assumption on my part. I don't see anything that specifically prevents that either. If cgroupfs is mounted and you tell mountd to export it, I don't see what would prevent that.
To be clear, I don't see how you would trick bog-standard mountd into exporting a filesystem that isn't mounted into its namespace, however. Writing a replacement for mountd is always a possibilty.
Quoted 5 lines
Quoted 4 lines
I have no issue personally with leaving cgroupfs exportable via nfsd and changing restricting only
SB_NOUSERandSB_KERNMOUNTfs.Jeff, Chuck, what is your opinion w.r.t exportability of cgroupfs via nfsd?
Quoted 10 lines
We all seem to be hard-pressed to find a usage scenario where exporting pseudo-filesystems via NFS is valuable. But maybe someone has done it and has a good reason for it.
The issue is whether such export should be consistently and actively prevented.
I'm not aware of any specific security issues with it.
I'm not either, but we are in new territory here. nfsd is a network service, so it does present more of an attack surface vs. local access.
In general, you do have to take active steps to export a filesystem, but if someone exports / with "crossmnt", everything mounted is potentially accessible. That's obviously a dumb thing to do, but people make mistakes, and it's possible that doing this could be part of a wider exploit.
I tend to think it safest to make exporting via nfsd an opt-in thing on a per-fs basis (along the lines of this patchset). If someone wants to allow access to more "exotic" filesystems, let them argue their use- case on the list first.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 64 lines · Jeff Layton
Quoted 23 lines · Chuck Lever
Quoted 22 lines · Amir Goldstein
Quoted 20 lines · Christoph Hellwig
Quoted 11 lines · Amir Goldstein
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.Can you please explain what the problem with exporting these file systems over NFS is? Yes, it's not going to be very useful. But what is actually problematic about it? Any why is it not problematic with a userland nfs server? We really need to settle that argumet before deciding a flag name or polarity.
Quoted 6 lines
Quoted 6 lines
I agree that it is not the end of the world and users do have to explicitly use fsid= argument to be able to export cgroupfs via nfsd.
The idea for this patch started from the claim that Jeff wrote that cgroups is not allowed for nfsd export, but I couldn't find where it is not allowed.
I think that must have been a wrong assumption on my part. I don't see anything that specifically prevents that either. If cgroupfs is mounted and you tell mountd to export it, I don't see what would prevent that.
To be clear, I don't see how you would trick bog-standard mountd into exporting a filesystem that isn't mounted into its namespace, however. Writing a replacement for mountd is always a possibilty.
Quoted 5 lines
Quoted 4 lines
I have no issue personally with leaving cgroupfs exportable via nfsd and changing restricting only
SB_NOUSERandSB_KERNMOUNTfs.Jeff, Chuck, what is your opinion w.r.t exportability of cgroupfs via nfsd?
Quoted 10 lines
We all seem to be hard-pressed to find a usage scenario where exporting pseudo-filesystems via NFS is valuable. But maybe someone has done it and has a good reason for it.
The issue is whether such export should be consistently and actively prevented.
I'm not aware of any specific security issues with it.
I'm not either, but we are in new territory here. nfsd is a network service, so it does present more of an attack surface vs. local access.
In general, you do have to take active steps to export a filesystem, but if someone exports / with "crossmnt", everything mounted is potentially accessible. That's obviously a dumb thing to do, but people make mistakes, and it's possible that doing this could be part of a wider exploit.
Quoted 4 lines
I tend to think it safest to make exporting via nfsd an opt-in thing on a per-fs basis (along the lines of this patchset). If someone wants to allow access to more "exotic" filesystems, let them argue their use- case on the list first.
If we were starting from scratch, 100% agree.
The current situation is that these file systems appear to be exportable (and not only via NFS). The proposal is that this facility is to be taken away. This can easily turn into a behavior regression for someone if we're not careful.
Signature · 1 line
Chuck Lever
Christian Brauner
maintainerQuoted 70 lines · Chuck Lever
Quoted 64 lines · Jeff Layton
Quoted 23 lines · Chuck Lever
Quoted 22 lines · Amir Goldstein
Quoted 20 lines · Christoph Hellwig
Quoted 11 lines · Amir Goldstein
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.Can you please explain what the problem with exporting these file systems over NFS is? Yes, it's not going to be very useful. But what is actually problematic about it? Any why is it not problematic with a userland nfs server? We really need to settle that argumet before deciding a flag name or polarity.
Quoted 6 lines
Quoted 6 lines
I agree that it is not the end of the world and users do have to explicitly use fsid= argument to be able to export cgroupfs via nfsd.
The idea for this patch started from the claim that Jeff wrote that cgroups is not allowed for nfsd export, but I couldn't find where it is not allowed.
I think that must have been a wrong assumption on my part. I don't see anything that specifically prevents that either. If cgroupfs is mounted and you tell mountd to export it, I don't see what would prevent that.
To be clear, I don't see how you would trick bog-standard mountd into exporting a filesystem that isn't mounted into its namespace, however. Writing a replacement for mountd is always a possibilty.
Quoted 5 lines
Quoted 4 lines
I have no issue personally with leaving cgroupfs exportable via nfsd and changing restricting only
SB_NOUSERandSB_KERNMOUNTfs.Jeff, Chuck, what is your opinion w.r.t exportability of cgroupfs via nfsd?
Quoted 10 lines
We all seem to be hard-pressed to find a usage scenario where exporting pseudo-filesystems via NFS is valuable. But maybe someone has done it and has a good reason for it.
The issue is whether such export should be consistently and actively prevented.
I'm not aware of any specific security issues with it.
I'm not either, but we are in new territory here. nfsd is a network service, so it does present more of an attack surface vs. local access.
In general, you do have to take active steps to export a filesystem, but if someone exports / with "crossmnt", everything mounted is potentially accessible. That's obviously a dumb thing to do, but people make mistakes, and it's possible that doing this could be part of a wider exploit.
Quoted 4 lines
I tend to think it safest to make exporting via nfsd an opt-in thing on a per-fs basis (along the lines of this patchset). If someone wants to allow access to more "exotic" filesystems, let them argue their use- case on the list first.
Quoted 6 lines
If we were starting from scratch, 100% agree.
The current situation is that these file systems appear to be exportable (and not only via NFS). The proposal is that this facility is to be taken away. This can easily turn into a behavior regression for someone if we're not careful.
So I'm happy to drop the exportfs preliminary we have now preventing kernfs from being exported but then Christoph and you should figure out what the security implications of allowing kernfs instances to be exported areare because I'm not an NFS export expert.
Filesystems that fall under kernfs that are exportable by NFS as I currently understand it are at least:
(1) sysfs
(2) cgroupfs
Has anyone ever actually tried to export the two and tested what happens? Because I wouldn't be surprised if this ended in tears but maybe I'm overly pessimistic.
Both (1) and (2) are rather special and don't have standard filesystem semantics in a few places.
- cgroupfs isn't actually namespace aware. Whereas most filesystems like tmpfs and ramfs that are mountable inside unprivileged containers are multi-instance filesystems, aka allocate a new superblock per container cgroupfs is single-instance with a nasty implementation to virtualize the per-container view via cgroup namespaces. I wouldn't be surprised if that ends up being problematic.
- Cgroupfs has write-time permission checks as the process that is moved into a cgroup isn't known at open time. That has been exploitable before this was fixed.
- Even though it's legacy cgroup has a v1 and v2 mode where v1 is even more messed up than v2 including the release-agent logic which ends up issuing a usermode helper to call a binary when a cgroup is released.
- sysfs potentially exposes all kinds of extremly low-level information to a remote machine.
None of this gives me the warm and fuzzy. But that's just me.
Otherwise, I don't understand what it means that a userspace NFS server can export kernfs instances. I don't know what that means and what the contrast to in-kernel NFS server export is and whether that has the same security implications. If so it's even scary that some random userspace NFS server can just expose guts like kernfs.
But if both of you feel that this is safe to do and there aren't any security issues lurking that have gone unnoticed simply because no one has really ever exported sysfs or cgroupfs then by all means continue allowing that. I'm rather skeptical.
Christian Brauner
maintainerQuoted 122 lines · Christian Brauner
Quoted 70 lines · Chuck Lever
Quoted 64 lines · Jeff Layton
Quoted 23 lines · Chuck Lever
Quoted 22 lines · Amir Goldstein
Quoted 20 lines · Christoph Hellwig
Quoted 11 lines · Amir Goldstein
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.Can you please explain what the problem with exporting these file systems over NFS is? Yes, it's not going to be very useful. But what is actually problematic about it? Any why is it not problematic with a userland nfs server? We really need to settle that argumet before deciding a flag name or polarity.
Quoted 6 lines
Quoted 6 lines
I agree that it is not the end of the world and users do have to explicitly use fsid= argument to be able to export cgroupfs via nfsd.
The idea for this patch started from the claim that Jeff wrote that cgroups is not allowed for nfsd export, but I couldn't find where it is not allowed.
I think that must have been a wrong assumption on my part. I don't see anything that specifically prevents that either. If cgroupfs is mounted and you tell mountd to export it, I don't see what would prevent that.
To be clear, I don't see how you would trick bog-standard mountd into exporting a filesystem that isn't mounted into its namespace, however. Writing a replacement for mountd is always a possibilty.
Quoted 5 lines
Quoted 4 lines
I have no issue personally with leaving cgroupfs exportable via nfsd and changing restricting only
SB_NOUSERandSB_KERNMOUNTfs.Jeff, Chuck, what is your opinion w.r.t exportability of cgroupfs via nfsd?
Quoted 10 lines
We all seem to be hard-pressed to find a usage scenario where exporting pseudo-filesystems via NFS is valuable. But maybe someone has done it and has a good reason for it.
The issue is whether such export should be consistently and actively prevented.
I'm not aware of any specific security issues with it.
I'm not either, but we are in new territory here. nfsd is a network service, so it does present more of an attack surface vs. local access.
In general, you do have to take active steps to export a filesystem, but if someone exports / with "crossmnt", everything mounted is potentially accessible. That's obviously a dumb thing to do, but people make mistakes, and it's possible that doing this could be part of a wider exploit.
Quoted 4 lines
I tend to think it safest to make exporting via nfsd an opt-in thing on a per-fs basis (along the lines of this patchset). If someone wants to allow access to more "exotic" filesystems, let them argue their use- case on the list first.
Quoted 6 lines
If we were starting from scratch, 100% agree.
The current situation is that these file systems appear to be exportable (and not only via NFS). The proposal is that this facility is to be taken away. This can easily turn into a behavior regression for someone if we're not careful.
So I'm happy to drop the exportfs preliminary we have now preventing kernfs from being exported but then Christoph and you should figure out what the security implications of allowing kernfs instances to be exported areare because I'm not an NFS export expert.
Filesystems that fall under kernfs that are exportable by NFS as I currently understand it are at least:
(1) sysfs
(2) cgroupfsHas anyone ever actually tried to export the two and tested what happens? Because I wouldn't be surprised if this ended in tears but maybe I'm overly pessimistic.
Both (1) and (2) are rather special and don't have standard filesystem semantics in a few places.
- cgroupfs isn't actually namespace aware. Whereas most filesystems like tmpfs and ramfs that are mountable inside unprivileged containers are multi-instance filesystems, aka allocate a new superblock per container cgroupfs is single-instance with a nasty implementation to virtualize the per-container view via cgroup namespaces. I wouldn't be surprised if that ends up being problematic.
- Cgroupfs has write-time permission checks as the process that is moved into a cgroup isn't known at open time. That has been exploitable before this was fixed.
- Even though it's legacy cgroup has a v1 and v2 mode where v1 is even more messed up than v2 including the release-agent logic which ends up issuing a usermode helper to call a binary when a cgroup is released.
- sysfs potentially exposes all kinds of extremly low-level information to a remote machine.
None of this gives me the warm and fuzzy. But that's just me.
Otherwise, I don't understand what it means that a userspace NFS server can export kernfs instances. I don't know what that means and what the contrast to in-kernel NFS server export is and whether that has the same security implications. If so it's even scary that some random userspace NFS server can just expose guts like kernfs.
Quoted 4 lines
But if both of you feel that this is safe to do and there aren't any security issues lurking that have gone unnoticed simply because no one has really ever exported sysfs or cgroupfs then by all means continue allowing that. I'm rather skeptical.
Amir pointed that sysfs can't be exported as it opts out of kernfs export_operations being set.
Quoted 4 lines · Christian Brauner
So I'm happy to drop the exportfs preliminary we have now preventing kernfs from being exported but then Christoph and you should figure out what the security implications of allowing kernfs instances to be exported areare because I'm not an NFS export expert.
I'm pretty sure you can do all kinds of really stupid things with it, and very few if any useful ones. But the litmus tests is if those are things that only the kernel nfs server can do vs things that a userland nfs (or other protocol) server could do the open by handle syscalls. Because if they aren't specific to the kernel nfs server they are just random policy for privileged actions.
Jeff Layton
maintainerQuoted 114 lines · Christian Brauner
Quoted 70 lines · Chuck Lever
Quoted 64 lines · Jeff Layton
Quoted 23 lines · Chuck Lever
Quoted 22 lines · Amir Goldstein
Quoted 20 lines · Christoph Hellwig
Quoted 11 lines · Amir Goldstein
To be clear, exporting pidfs or internal shmem via an anonymous fd is probably not possible with existing userspace tools, but with all the new
mount_fdand magic link apis, I can never be sure what can be made possible to achieve when the user holds an anonymous fd.The thinking behind adding the
EXPORT_OP_LOCAL_FILE_HANDLEflag was that when kernfs/cgroups was added exportfs support with commitaa8188253474("kernfs: add exportfs operations"), there was no intention to export cgroupfs over nfs, only local to uses, but that was never enforced, so we thought it would be good to add this restriction and backport it to stable kernels.Can you please explain what the problem with exporting these file systems over NFS is? Yes, it's not going to be very useful. But what is actually problematic about it? Any why is it not problematic with a userland nfs server? We really need to settle that argumet before deciding a flag name or polarity.
Quoted 6 lines
Quoted 6 lines
I agree that it is not the end of the world and users do have to explicitly use fsid= argument to be able to export cgroupfs via nfsd.
The idea for this patch started from the claim that Jeff wrote that cgroups is not allowed for nfsd export, but I couldn't find where it is not allowed.
I think that must have been a wrong assumption on my part. I don't see anything that specifically prevents that either. If cgroupfs is mounted and you tell mountd to export it, I don't see what would prevent that.
To be clear, I don't see how you would trick bog-standard mountd into exporting a filesystem that isn't mounted into its namespace, however. Writing a replacement for mountd is always a possibilty.
Quoted 5 lines
Quoted 4 lines
I have no issue personally with leaving cgroupfs exportable via nfsd and changing restricting only
SB_NOUSERandSB_KERNMOUNTfs.Jeff, Chuck, what is your opinion w.r.t exportability of cgroupfs via nfsd?
Quoted 10 lines
We all seem to be hard-pressed to find a usage scenario where exporting pseudo-filesystems via NFS is valuable. But maybe someone has done it and has a good reason for it.
The issue is whether such export should be consistently and actively prevented.
I'm not aware of any specific security issues with it.
I'm not either, but we are in new territory here. nfsd is a network service, so it does present more of an attack surface vs. local access.
In general, you do have to take active steps to export a filesystem, but if someone exports / with "crossmnt", everything mounted is potentially accessible. That's obviously a dumb thing to do, but people make mistakes, and it's possible that doing this could be part of a wider exploit.
Quoted 4 lines
I tend to think it safest to make exporting via nfsd an opt-in thing on a per-fs basis (along the lines of this patchset). If someone wants to allow access to more "exotic" filesystems, let them argue their use- case on the list first.
Quoted 6 lines
If we were starting from scratch, 100% agree.
The current situation is that these file systems appear to be exportable (and not only via NFS). The proposal is that this facility is to be taken away. This can easily turn into a behavior regression for someone if we're not careful.
So I'm happy to drop the exportfs preliminary we have now preventing kernfs from being exported but then Christoph and you should figure out what the security implications of allowing kernfs instances to be exported areare because I'm not an NFS export expert.
Filesystems that fall under kernfs that are exportable by NFS as I currently understand it are at least:
(1) sysfs
(2) cgroupfsHas anyone ever actually tried to export the two and tested what happens? Because I wouldn't be surprised if this ended in tears but maybe I'm overly pessimistic.
Both (1) and (2) are rather special and don't have standard filesystem semantics in a few places.
- cgroupfs isn't actually namespace aware. Whereas most filesystems like tmpfs and ramfs that are mountable inside unprivileged containers are multi-instance filesystems, aka allocate a new superblock per container cgroupfs is single-instance with a nasty implementation to virtualize the per-container view via cgroup namespaces. I wouldn't be surprised if that ends up being problematic.
- Cgroupfs has write-time permission checks as the process that is moved into a cgroup isn't known at open time. That has been exploitable before this was fixed.
- Even though it's legacy cgroup has a v1 and v2 mode where v1 is even more messed up than v2 including the release-agent logic which ends up issuing a usermode helper to call a binary when a cgroup is released.
- sysfs potentially exposes all kinds of extremly low-level information to a remote machine.
Quoted 8 lines
None of this gives me the warm and fuzzy. But that's just me.
Otherwise, I don't understand what it means that a userspace NFS server can export kernfs instances. I don't know what that means and what the contrast to in-kernel NFS server export is and whether that has the same security implications. If so it's even scary that some random userspace NFS server can just expose guts like kernfs.
A userspace NFS server can export anything to which it has access. If cgroupfs or sysfs is mounted and the server is running with appropriate permissions then there is nothing that prevents it from making that available. It's helpful if the filesystem can implement name_to_handle_at() and open_by_handle_at(), but even that isn't specifically required.
Quoted 4 lines
But if both of you feel that this is safe to do and there aren't any security issues lurking that have gone unnoticed simply because no one has really ever exported sysfs or cgroupfs then by all means continue allowing that. I'm rather skeptical.
I'm not sure I agree that it's "safe", but in order to export kernfs or pidfs you have to explicitly set it up to be exported. Christoph has a good point that we don't have a specific scenario that we're trying to prevent here.
My main thinking here is that:
1/ exporting these fstypes is not something we consider useful
2/ by forbidding this now, we prevent someone from complaining that there is a regression later if we do find that it's problematic and have to forbid it
Also, if we forbid this now, that might force someone who does want to do this to articulate their use-case publicly.
Signature · 1 line
Jeff Layton <[email protected]>