]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
exportfs: require ->fh_to_parent() to encode connectable file handles
authorAmir Goldstein <amir73il@gmail.com>
Sun, 25 May 2025 10:47:31 +0000 (12:47 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 30 May 2025 05:30:47 +0000 (07:30 +0200)
When user requests a connectable file handle explicitly with the
AT_HANDLE_CONNECTABLE flag, fail the request if filesystem (e.g. nfs)
does not know how to decode a connected non-dir dentry.

Fixes: c374196b2b9f ("fs: name_to_handle_at() support for "explicit connectable" file handles")
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://lore.kernel.org/20250525104731.1461704-1-amir73il@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/exportfs.h

index fc93f0abf513cd66bd6a83318d42228b5510d824..25c4a5afbd44329a5e8472c2f3a128fcc3a69949 100644 (file)
@@ -314,6 +314,9 @@ static inline bool exportfs_can_decode_fh(const struct export_operations *nop)
 static inline bool exportfs_can_encode_fh(const struct export_operations *nop,
                                          int fh_flags)
 {
+       if (!nop)
+               return false;
+
        /*
         * If a non-decodeable file handle was requested, we only need to make
         * sure that filesystem did not opt-out of encoding fid.
@@ -321,6 +324,13 @@ static inline bool exportfs_can_encode_fh(const struct export_operations *nop,
        if (fh_flags & EXPORT_FH_FID)
                return exportfs_can_encode_fid(nop);
 
+       /*
+        * If a connectable file handle was requested, we need to make sure that
+        * filesystem can also decode connected file handles.
+        */
+       if ((fh_flags & EXPORT_FH_CONNECTABLE) && !nop->fh_to_parent)
+               return false;
+
        /*
         * If a decodeable file handle was requested, we need to make sure that
         * filesystem can also decode file handles.