fanotify: sanitize handle_type values when reporting fid
Subsystems (3)
Amir Goldstein
reviewerPATCH 1/1 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.
---
Jan,
This cleanup is a followup to the review of FILEID_PIDFS. The Fixes commit is a bit misleading because there is no bug in the Fixes commit, it's a just a fix-it-better statement, which is practical for stable backporting.
Thanks,
Amir.
fs/notify/fanotify/fanotify.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify.c +7 -1
@@ -454,7 +454,13 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, dwords = fh_len >>2 ; type =exportfs_encode_fid (inode, buf, &dwords); err = -EINVAL ; -if (type <=0 || type ==FILEID_INVALID || fh_len != dwords <<2 ) +/* +* 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. +*/ +BUILD_BUG_ON (MAX_HANDLE_SZ >0xff ||FILEID_INVALID >0xff ); +if (type <=0 || type >=FILEID_INVALID || fh_len != dwords <<2 ) goto out_err; fh->type = type;
Signature · 1 line
2.43.0
Jan Kara
maintainerQuoted 9 lines · Amir Goldstein
Unlike
file_handle, type and len of structfanotify_fhare u8. Traditionally, filesystem returnhandle_type<0xff, but there is no enforecement for that in vfs.Add a sanity check in fanotify to avoid truncating
handle_typeif its value is >0xff.Fixes 7cdafe6cc4a6 ("exportfs: check for error return value from exportfs_encode_*()")Signed-off-by Amir Goldstein <[email protected]>
Thanks. Added to my tree.
Honza
Quoted 37 lines
---
Jan,
This cleanup is a followup to the review of
FILEID_PIDFS. The Fixes commit is a bit misleading because there is no bug in the Fixes commit, it's a just a fix-it-better statement, which is practical for stable backporting.Thanks,
Amir.fs/notify/fanotify/fanotify.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/notify/fanotify/fanotify.c +7
-1@@ -454,7 +454,13 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, dwords = fh_len >>2 ; type =exportfs_encode_fid (inode, buf, &dwords); err = -EINVAL ; -if (type <=0 || type ==FILEID_INVALID || fh_len != dwords <<2 ) +/* +* 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. +*/ +BUILD_BUG_ON (MAX_HANDLE_SZ >0xff ||FILEID_INVALID >0xff ); +if (type <=0 || type >=FILEID_INVALID || fh_len != dwords <<2 ) goto out_err; fh->type = type;Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR