Skip to content

Commit 572c28f

Browse files
krisman-at-collaborajankara
authored andcommitted
fanotify: WARN_ON against too large file handles
struct fanotify_error_event, at least, is preallocated and isn't able to to handle arbitrarily large file handles. Future-proof the code by complaining loudly if a handle larger than MAX_HANDLE_SZ is ever found. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Amir Goldstein <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 4bd5a5c commit 572c28f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,23 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
360360
static int fanotify_encode_fh_len(struct inode *inode)
361361
{
362362
int dwords = 0;
363+
int fh_len;
363364

364365
if (!inode)
365366
return 0;
366367

367368
exportfs_encode_inode_fh(inode, NULL, &dwords, NULL);
369+
fh_len = dwords << 2;
368370

369-
return dwords << 2;
371+
/*
372+
* struct fanotify_error_event might be preallocated and is
373+
* limited to MAX_HANDLE_SZ. This should never happen, but
374+
* safeguard by forcing an invalid file handle.
375+
*/
376+
if (WARN_ON_ONCE(fh_len > MAX_HANDLE_SZ))
377+
return 0;
378+
379+
return fh_len;
370380
}
371381

372382
/*

0 commit comments

Comments
 (0)