nfsd and special kernel filesystems
Subsystems (4)
Amir Goldstein
reviewerv3 cover nfsd and special kernel filesystems
Christian,
I noticed that the kernel-doc refactoring queued on vfs-7.0.misc was going to conflict with v2 [1], so I rebased over vfs-7.0.misc and split it into doc update and nfsd fix patch that could be backported.
RVBs by Chuck and Jeff were removed due to the slight changes in wording.
I'd like to acknowledge that Christoph wrote on v2 that:
"As last time I'd be happy to help write documentation, but even
after looking at the methods, their documentations and the commits adding them I do not understand them. So getting an explanation from Christian would be really helpful to move forward here."
IMO, further clarifications of the new methods is very much welcome, but should not be blocking the merge of this patch set, which at least clarifies the WHAT (to use them for) if not the HOW (to use them).
Thanks,
Amir.
Changes since v2:
- Rebase over vfs-7.0.misc
- Split to doc/fix patches
- Remove RVBs
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
Amir Goldstein (2):
exportfs: clarify the documentation of open()/permission() expotrfs
ops
nfsd: do not allow exporting of special kernel filesystems
fs/nfsd/export.c | 8 +++++--- include/linux/exportfs.h | 25 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-)
Signature · 1 line
2.52.0
Amir Goldstein
reviewerPATCH v3 1/2 exportfs: clarify the documentation of open()/permission() expotrfs ops
pidfs and nsfs recently gained support for encode/decode of file handles via name_to_handle_at(2)/opan_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.
Update kernel-doc comments to express the fact the those methods are for open_by_handle(2) system only and not compatible with nfsd.
--- include/linux/exportfs.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
include/linux/exportfs.h +13 -3
@@ -192,7 +192,9 @@ struct handle_to_path_ctx {#define FILEID_VALID_USER_FLAGS (FILEID_IS_CONNECTABLE | FILEID_IS_DIR)/** -* struct export_operations - for nfsd to communicate with file systems +* struct export_operations +* +* Methods for nfsd to communicate with file systems: * @encode_fh: encode a file handle fragment from a dentry * @fh_to_dentry: find the implied object and get a dentry for it * @fh_to_parent: find the implied object's parent and get a dentry for it
@@ -200,6 +202,10 @@ struct handle_to_path_ctx {* @get_parent: find the parent of a given directory * @commit_metadata: commit metadata changes to stable storage * +* Methods for open_by_handle(2) syscall with special kernel file systems: +* @permission: custom permission for opening a file by handle +* @open: custom open routine for opening file by handle +* * See Documentation/filesystems/nfs/exporting.rst for details on how to use * this interface correctly and the definition of the flags. *
@@ -244,10 +250,14 @@ struct handle_to_path_ctx {* space cannot be allocated, a %ERR_PTR should be returned. * * @permission: -* Allow filesystems to specify a custom permission function. +* Allow filesystems to specify a custom permission function for the +* open_by_handle_at(2) syscall instead of the default permission check. +* This custom permission function is not respected by nfsd. * * @open: -* Allow filesystems to specify a custom open function. +* Allow filesystems to specify a custom open function for the +* open_by_handle_at(2) syscall instead of the default file_open_root(). +* This custom open function is not respected by nfsd. * * @commit_metadata: * @commit_metadata should commit metadata changes to stable storage.
Signature · 1 line
2.52.0
Chuck Lever
maintainerRe: [PATCH v3 1/2] exportfs: clarify the documentation of open()/permission() expotrfs ops
Typo in Subject: s/expotrfs/exportfs
Quoted 2 lines · Amir Goldstein
pidfs and nsfs recently gained support for encode/decode of file handles via name_to_handle_at(2)/opan_by_handle_at(2).
s/opan/open
And one more below:
Quoted 17 lines
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.
Update kernel-doc comments to express the fact the those methods are for
open_by_handle(2)system only and not compatible with nfsd.Signed-off-by Amir Goldstein <[email protected]>--- include/linux/exportfs.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)include/linux/exportfs.h +0
-0
include/linux/exportfs.h struct handle_to_path_ctx { · line 197
Quoted 7 lines
include/linux/exportfs.h +3
-1@@ -192,7 +192,9 @@ struct handle_to_path_ctx {#define FILEID_VALID_USER_FLAGS (FILEID_IS_CONNECTABLE | FILEID_IS_DIR)/** -* struct export_operations - for nfsd to communicate with file systems +* struct export_operations +* +* Methods for nfsd to communicate with file systems:
Let's not remove the brief description for the export_operations struct in the Doxygen output.
Quoted 33 lines
include/linux/exportfs.h +10
-2* @encode_fh: encode a file handle fragment from a dentry * @fh_to_dentry: find the implied object and get a dentry for it * @fh_to_parent: find the implied object's parent and get a dentry for it @@ -200,6 +202,10 @@ struct handle_to_path_ctx {* @get_parent: find the parent of a given directory * @commit_metadata: commit metadata changes to stable storage * +* Methods for open_by_handle(2) syscall with special kernel file systems: +* @permission: custom permission for opening a file by handle +* @open: custom open routine for opening file by handle +* * See Documentation/filesystems/nfs/exporting.rst for details on how to use * this interface correctly and the definition of the flags. * @@ -244,10 +250,14 @@ struct handle_to_path_ctx {* space cannot be allocated, a %ERR_PTR should be returned. * * @permission: -* Allow filesystems to specify a custom permission function. +* Allow filesystems to specify a custom permission function for the +* open_by_handle_at(2) syscall instead of the default permission check. +* This custom permission function is not respected by nfsd. * * @open: -* Allow filesystems to specify a custom open function. +* Allow filesystems to specify a custom open function for the +* open_by_handle_at(2) syscall instead of the default file_open_root(). +* This custom open function is not respected by nfsd. * * @commit_metadata: * @commit_metadata should commit metadata changes to stable storage. Signature · 1 line
2.52.0
Signature · 1 line
Chuck Lever
Amir Goldstein
reviewerRe: [PATCH v3 1/2] exportfs: clarify the documentation of open()/permission() expotrfs ops
Quoted 32 lines · Chuck Lever
Typo in Subject: s/expotrfs/exportfs
Quoted 2 lines · Amir Goldstein
pidfs and nsfs recently gained support for encode/decode of file handles via name_to_handle_at(2)/opan_by_handle_at(2).
s/opan/open
And one more below:
Quoted 19 lines
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.
Update kernel-doc comments to express the fact the those methods are for
open_by_handle(2)system only and not compatible with nfsd.Signed-off-by Amir Goldstein <[email protected]>--- include/linux/exportfs.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)include/linux/exportfs.h +0
-0@@ -192,7 +192,9 @@ struct handle_to_path_ctx {#define FILEID_VALID_USER_FLAGS (FILEID_IS_CONNECTABLE | FILEID_IS_DIR)
Quoted 9 lines
include/linux/exportfs.h struct handle_to_path_ctx { · line 197
Quoted 5 lines
include/linux/exportfs.h +3
-1/** -* struct export_operations - for nfsd to communicate with file systems +* struct export_operations +* +* Methods for nfsd to communicate with file systems: Let's not remove the brief description for the
export_operationsstruct in the Doxygen output.
OK. will fix for v4.
Thanks,
Amir.
Amir Goldstein
reviewerPATCH v3 2/2 nfsd: do not allow exporting of special kernel filesystems
In reply to Amir Goldsteinpidfs and nsfs recently gained support for encode/decode of file handles via name_to_handle_at(2)/opan_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.
--- fs/nfsd/export.c | 8 +++++--- include/linux/exportfs.h | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-)
fs/nfsd/export.c +5 -3
@@ -427,7 +427,8 @@ static int check_export(const struct path *path, int *flags, unsigned char *uuid* either a device number (so FS_REQUIRES_DEV needed) * or an FSID number (so NFSEXP_FSID or ->uuid is needed). * 2: We must be able to find an inode from a filehandle. -* This means that s_export_op must be set. +* This means that s_export_op must be set and comply with +* the requirements for remote filesystem export. * 3: We must not currently be on an idmapped mount. */ 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 *uuidreturn -EINVAL ; } -if (!exportfs_can_decode_fh (inode->i_sb->s_export_op)) { -dprintk ("exp_export: export of invalid fs type.\n" ); +if (!exportfs_may_export (inode->i_sb->s_export_op)) { +dprintk ("exp_export: export of invalid fs type (%s).\n" , + inode->i_sb->s_type->name);return -EINVAL ; }
include/linux/exportfs.h +9 -0
@@ -340,6 +340,15 @@ static inline bool exportfs_can_decode_fh(const struct export_operations *nop)return nop && nop->fh_to_dentry; } +static inline bool exportfs_may_export (const struct export_operations *nop) +{ +/* +* Do not allow nfs export for filesystems with custom ->open() and +* ->permission() ops, which nfsd does not respect (e.g. pidfs, nsfs). +*/ +return exportfs_can_decode_fh (nop) && !nop->open && !nop->permission; +} +static inline bool exportfs_can_encode_fh (const struct export_operations *nop,int fh_flags) {
Signature · 1 line
2.52.0
Chuck Lever
maintainerRe: [PATCH v3 2/2] nfsd: do not allow exporting of special kernel filesystems
Quoted 2 lines · Amir Goldstein
pidfs and nsfs recently gained support for encode/decode of file handles via name_to_handle_at(2)/opan_by_handle_at(2).
s/opan/open
One more below:
Quoted 48 lines
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 b3caba8f7a34a ("pidfs: implement file handle support")Fixes 5222470b2fbb3 ("nsfs: support file handles")Signed-off-by Amir Goldstein <[email protected]>--- fs/nfsd/export.c | 8 +++++--- include/linux/exportfs.h | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-)fs/nfsd/export.c +0
-0@@ -427,7 +427,8 @@ static int check_export(const struct path *path,int *flags, unsigned char *uuid
fs/nfsd/export.c +2
-1* either a device number (so FS_REQUIRES_DEV needed) * or an FSID number (so NFSEXP_FSID or ->uuid is needed). * 2: We must be able to find an inode from a filehandle. -* This means that s_export_op must be set. +* This means that s_export_op must be set and comply with +* the requirements for remote filesystem export. * 3: We must not currently be on an idmapped mount. */ 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
fs/nfsd/export.c +3
-2return -EINVAL ; } -if (!exportfs_can_decode_fh (inode->i_sb->s_export_op)) { -dprintk ("exp_export: export of invalid fs type.\n" ); +if (!exportfs_may_export (inode->i_sb->s_export_op)) { +dprintk ("exp_export: export of invalid fs type (%s).\n" , + inode->i_sb->s_type->name);return -EINVAL ; }include/linux/exportfs.h +0
-0
include/linux/exportfs.h static inline bool exportfs_can_decode_fh(const · line 349
Quoted 10 lines
include/linux/exportfs.h +6
-0@@ -340,6 +340,15 @@ static inline bool exportfs_can_decode_fh(const struct export_operations *nop)return nop && nop->fh_to_dentry; } +static inline bool exportfs_may_export (const struct export_operations *nop) +{ +/* +* Do not allow nfs export for filesystems with custom ->open() and +* ->permission() ops, which nfsd does not respect (e.g. pidfs, nsfs). +*/
The comment says "with custom ->open() and ->permission() ops" but the code blocks export if either one is set. The commit message correctly says "or" - should the comment be updated to match?
Quoted 8 lines
include/linux/exportfs.h +3
-0+return exportfs_can_decode_fh (nop) && !nop->open && !nop->permission; +} +static inline bool exportfs_can_encode_fh (const struct export_operations *nop,int fh_flags){
Signature · 1 line
2.52.0
Signature · 1 line
Chuck Lever
Amir Goldstein
reviewerRe: [PATCH v3 2/2] nfsd: do not allow exporting of special kernel filesystems
Quoted 64 lines · Chuck Lever
Quoted 2 lines · Amir Goldstein
pidfs and nsfs recently gained support for encode/decode of file handles via name_to_handle_at(2)/opan_by_handle_at(2).
s/opan/open
One more below:
Quoted 52 lines
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 b3caba8f7a34a ("pidfs: implement file handle support")Fixes 5222470b2fbb3 ("nsfs: support file handles")Signed-off-by Amir Goldstein <[email protected]>--- fs/nfsd/export.c | 8 +++++--- include/linux/exportfs.h | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-)fs/nfsd/export.c +0
-0@@ -427,7 +427,8 @@ static int check_export(const struct path *path,int *flags, unsigned char *uuid
* either a device number (soFS_REQUIRES_DEVneeded)
* or an FSID number (soNFSEXP_FSIDor ->uuid is needed).
* 2: We must be able to find an inode from a filehandle.fs/nfsd/export.c +2
-1-* This means that s_export_op must be set. +* This means that s_export_op must be set and comply with +* the requirements for remote filesystem export. * 3: We must not currently be on an idmapped mount. */ 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
return -EINVAL; }fs/nfsd/export.c +3
-2-if (!exportfs_can_decode_fh (inode->i_sb->s_export_op)) { -dprintk ("exp_export: export of invalid fs type.\n" ); +if (!exportfs_may_export (inode->i_sb->s_export_op)) { +dprintk ("exp_export: export of invalid fs type (%s).\n" , + inode->i_sb->s_type->name);return -EINVAL ; }include/linux/exportfs.h +0
-0@@ -340,6 +340,15 @@ static inline bool exportfs_can_decode_fh(const struct export_operations *nop)return nop && nop->fh_to_dentry; }
Quoted 11 lines
include/linux/exportfs.h static inline bool exportfs_can_decode_fh(const struct export_operations *nop) · line 348
Quoted 6 lines
include/linux/exportfs.h +6
-0+static inline bool exportfs_may_export (const struct export_operations *nop) +{ +/* +* Do not allow nfs export for filesystems with custom ->open() and +* ->permission() ops, which nfsd does not respect (e.g. pidfs, nsfs). +*/ The comment says "with custom ->open() and ->permission() ops" but the code blocks export if either one is set. The commit message correctly says "or" - should the comment be updated to match?
Of course.
Will fix for v4.
Thanks,
Amir.
Quoted 28 lines · Amir Goldstein
Christian,
I noticed that the kernel-doc refactoring queued on vfs-7.0.misc was going to conflict with v2 [1], so I rebased over vfs-7.0.misc and split it into doc update and nfsd fix patch that could be backported.
RVBs by Chuck and Jeff were removed due to the slight changes in wording.
I'd like to acknowledge that Christoph wrote on v2 that:
"As last time I'd be happy to help write documentation, but even
after looking at the methods, their documentations and the commits adding them I do not understand them. So getting an explanation from Christian would be really helpful to move forward here."IMO, further clarifications of the new methods is very much welcome, but should not be blocking the merge of this patch set, which at least clarifies the WHAT (to use them for) if not the HOW (to use them).
Thanks,
Amir.Changes since v2:
- Rebase over vfs-7.0.misc
- Split to doc/fix patches
- Remove RVBs[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
Quoted 8 lines
Amir Goldstein (2):
exportfs: clarify the documentation of open()/permission() expotrfs
ops
nfsd: do not allow exporting of special kernel filesystemsfs/nfsd/export.c | 8 +++++--- include/linux/exportfs.h | 25 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-)
Updated version seems reasonable: