Skip to content

Commit 8bf7719

Browse files
jankaraKent Overstreet
authored andcommitted
bcachefs: Fix determining required file handle length
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 <[email protected]> Signed-off-by: Jan Kara <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent bedd6fe commit 8bf7719

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

fs/bcachefs/fs.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,24 +1143,33 @@ static int bch2_encode_fh(struct inode *vinode, u32 *fh, int *len,
11431143
{
11441144
struct bch_inode_info *inode = to_bch_ei(vinode);
11451145
struct bch_inode_info *dir = to_bch_ei(vdir);
1146-
1147-
if (*len < sizeof(struct bcachefs_fid_with_parent) / sizeof(u32))
1148-
return FILEID_INVALID;
1146+
int min_len;
11491147

11501148
if (!S_ISDIR(inode->v.i_mode) && dir) {
11511149
struct bcachefs_fid_with_parent *fid = (void *) fh;
11521150

1151+
min_len = sizeof(*fid) / sizeof(u32);
1152+
if (*len < min_len) {
1153+
*len = min_len;
1154+
return FILEID_INVALID;
1155+
}
1156+
11531157
fid->fid = bch2_inode_to_fid(inode);
11541158
fid->dir = bch2_inode_to_fid(dir);
11551159

1156-
*len = sizeof(*fid) / sizeof(u32);
1160+
*len = min_len;
11571161
return FILEID_BCACHEFS_WITH_PARENT;
11581162
} else {
11591163
struct bcachefs_fid *fid = (void *) fh;
11601164

1165+
min_len = sizeof(*fid) / sizeof(u32);
1166+
if (*len < min_len) {
1167+
*len = min_len;
1168+
return FILEID_INVALID;
1169+
}
11611170
*fid = bch2_inode_to_fid(inode);
11621171

1163-
*len = sizeof(*fid) / sizeof(u32);
1172+
*len = min_len;
11641173
return FILEID_BCACHEFS_WITHOUT_PARENT;
11651174
}
11661175
}

0 commit comments

Comments
 (0)