Skip to content

Commit 8631e01

Browse files
amir73iljankara
authored andcommitted
fanotify: sanitize handle_type values when reporting fid
Unlike file_handle, type and len of struct fanotify_fh are u8. Traditionally, filesystem return handle_type < 0xff, but there is no enforecement for that in vfs. Add a sanity check in fanotify to avoid truncating handle_type if its value is > 0xff. Fixes: 7cdafe6 ("exportfs: check for error return value from exportfs_encode_*()") Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent e540341 commit 8631e01

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,13 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode,
454454
dwords = fh_len >> 2;
455455
type = exportfs_encode_fid(inode, buf, &dwords);
456456
err = -EINVAL;
457-
if (type <= 0 || type == FILEID_INVALID || fh_len != dwords << 2)
457+
/*
458+
* Unlike file_handle, type and len of struct fanotify_fh are u8.
459+
* Traditionally, filesystem return handle_type < 0xff, but there
460+
* is no enforecement for that in vfs.
461+
*/
462+
BUILD_BUG_ON(MAX_HANDLE_SZ > 0xff || FILEID_INVALID > 0xff);
463+
if (type <= 0 || type >= FILEID_INVALID || fh_len != dwords << 2)
458464
goto out_err;
459465

460466
fh->type = type;

0 commit comments

Comments
 (0)