]> git.itanic.dy.fi Git - linux-stable/commitdiff
bcachefs: Fix determining required file handle length
authorJan Kara <jack@suse.cz>
Wed, 13 Dec 2023 16:51:04 +0000 (17:51 +0100)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 13 Dec 2023 18:09:36 +0000 (13:09 -0500)
The ->encode_fh method is responsible for setting amount of space
required for storing the file handle if not enough space was provided.
bch2_encode_fh() was not setting required length in that case which
breaks e.g. fanotify. Fix it.

Reported-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs.c

index 371565e02ff273cdded33d32ce3f913deccccad6..ba93e32d7708e6b877d627971b5b63eefa632bc4 100644 (file)
@@ -1143,24 +1143,33 @@ static int bch2_encode_fh(struct inode *vinode, u32 *fh, int *len,
 {
        struct bch_inode_info *inode    = to_bch_ei(vinode);
        struct bch_inode_info *dir      = to_bch_ei(vdir);
-
-       if (*len < sizeof(struct bcachefs_fid_with_parent) / sizeof(u32))
-               return FILEID_INVALID;
+       int min_len;
 
        if (!S_ISDIR(inode->v.i_mode) && dir) {
                struct bcachefs_fid_with_parent *fid = (void *) fh;
 
+               min_len = sizeof(*fid) / sizeof(u32);
+               if (*len < min_len) {
+                       *len = min_len;
+                       return FILEID_INVALID;
+               }
+
                fid->fid = bch2_inode_to_fid(inode);
                fid->dir = bch2_inode_to_fid(dir);
 
-               *len = sizeof(*fid) / sizeof(u32);
+               *len = min_len;
                return FILEID_BCACHEFS_WITH_PARENT;
        } else {
                struct bcachefs_fid *fid = (void *) fh;
 
+               min_len = sizeof(*fid) / sizeof(u32);
+               if (*len < min_len) {
+                       *len = min_len;
+                       return FILEID_INVALID;
+               }
                *fid = bch2_inode_to_fid(inode);
 
-               *len = sizeof(*fid) / sizeof(u32);
+               *len = min_len;
                return FILEID_BCACHEFS_WITHOUT_PARENT;
        }
 }