fanotify: avoid possible NULL dereference
PATCH 1/1 fanotify: avoid possible NULL dereference
smatch error:fs/notify/fanotify/fanotify_user.c:462 copy_fid_info_to_user():
we previously assumed 'fh' could be null (see line 421)
--- fs/notify/fanotify/fanotify_user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify_user.c +2 -1
@@ -459,12 +459,13 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh,if (WARN_ON_ONCE (len <sizeof (handle)))return -EFAULT ; - handle.handle_type = fh->type; handle.handle_bytes = fh_len;/* Mangle handle_type for bad file_handle */ if (!fh_len) handle.handle_type =FILEID_INVALID ; +else + handle.handle_type = fh->type;if (copy_to_user (buf, &handle,sizeof (handle)))return -EFAULT ;
Signature · 1 line
2.30.2
Quoted 7 lines · Su Hui
smatch error:
fs/notify/fanotify/fanotify_user.c:462copy_fid_info_to_user():
we previously assumed 'fh' could be null (see line 421)Fixes afc894c784c8 ("fanotify: Store fanotify handles differently")Signed-off-by Su Hui <[email protected]>'
Quoted 26 lines
--- fs/notify/fanotify/fanotify_user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/notify/fanotify/fanotify_user.c +2
-2@@ -459,12 +459,13 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh,if (WARN_ON_ONCE (len <sizeof (handle)))return -EFAULT ; - handle.handle_type = fh->type; handle.handle_bytes = fh_len;/* Mangle handle_type for bad file_handle */ if (!fh_len) handle.handle_type =FILEID_INVALID ; +else + handle.handle_type = fh->type;if (copy_to_user (buf, &handle,sizeof (handle)))return -EFAULT ; --2.30.2
Jan Kara
maintainerQuoted 10 lines · Amir Goldstein
Quoted 7 lines · Su Hui
smatch error:
fs/notify/fanotify/fanotify_user.c:462copy_fid_info_to_user():
we previously assumed 'fh' could be null (see line 421)Fixes afc894c784c8 ("fanotify: Store fanotify handles differently")Signed-off-by Su Hui <[email protected]>'Reviewed-by Amir Goldstein <[email protected]>
I'm sorry but this has somehow fallen through the cracks.
Quoted 10 lines
fs/notify/fanotify/fanotify_user.c static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh, · line 462
Quoted 10 lines
fs/notify/fanotify/fanotify_user.c +0
-1@@ -459,12 +459,13 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh,if (WARN_ON_ONCE (len <sizeof (handle)))return -EFAULT ; - handle.handle_type = fh->type; handle.handle_bytes = fh_len;
Well, if passed 'fh' is NULL, we have problems later in the function anyway. E.g. in fanotify_fh_buf() a few lines below. So I think this needs a bit more work that just this small fixup...
Honza
Quoted 12 lines
Quoted 12 lines
fs/notify/fanotify/fanotify_user.c +2
-1/* Mangle handle_type for bad file_handle */ if (!fh_len) handle.handle_type =FILEID_INVALID ; +else + handle.handle_type = fh->type;if (copy_to_user (buf, &handle,sizeof (handle)))return -EFAULT ; --2.30.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR