Skip to content

Commit

Permalink
fanotify: WARN_ON against too large file handles
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
krisman-at-collabora authored and jankara committed Oct 27, 2021
1 parent 4bd5a5c commit 572c28f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion fs/notify/fanotify/fanotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,23 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
static int fanotify_encode_fh_len(struct inode *inode)
{
int dwords = 0;
int fh_len;

if (!inode)
return 0;

exportfs_encode_inode_fh(inode, NULL, &dwords, NULL);
fh_len = dwords << 2;

return dwords << 2;
/*
* struct fanotify_error_event might be preallocated and is
* limited to MAX_HANDLE_SZ. This should never happen, but
* safeguard by forcing an invalid file handle.
*/
if (WARN_ON_ONCE(fh_len > MAX_HANDLE_SZ))
return 0;

return fh_len;
}

/*
Expand Down

0 comments on commit 572c28f

Please sign in to comment.