Commit 272531ac authored by Gabriel Krisman Bertazi's avatar Gabriel Krisman Bertazi Committed by Jan Kara
Browse files

fanotify: Encode empty file handle when no inode is provided

Instead of failing, encode an invalid file handle in fanotify_encode_fh
if no inode is provided.  This bogus file handle will be reported by
FAN_FS_ERROR for non-inode errors.

Link: https://lore.kernel.org/r/20211025192746.66445-16-krisman@collabora.com


Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarGabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 74fe4734
Loading
Loading
Loading
Loading
+8 −1
Original line number Original line Diff line number Diff line
@@ -370,8 +370,14 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode,
	fh->type = FILEID_ROOT;
	fh->type = FILEID_ROOT;
	fh->len = 0;
	fh->len = 0;
	fh->flags = 0;
	fh->flags = 0;

	/*
	 * Invalid FHs are used by FAN_FS_ERROR for errors not
	 * linked to any inode. The f_handle won't be reported
	 * back to userspace.
	 */
	if (!inode)
	if (!inode)
		return 0;
		goto out;


	/*
	/*
	 * !gpf means preallocated variable size fh, but fh_len could
	 * !gpf means preallocated variable size fh, but fh_len could
@@ -403,6 +409,7 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode,
	fh->type = type;
	fh->type = type;
	fh->len = fh_len;
	fh->len = fh_len;


out:
	/*
	/*
	 * Mix fh into event merge key.  Hash might be NULL in case of
	 * Mix fh into event merge key.  Hash might be NULL in case of
	 * unhashed FID events (i.e. FAN_FS_ERROR).
	 * unhashed FID events (i.e. FAN_FS_ERROR).