* [PATCH] fanotify: avoid possible NULL dereference
@ 2023-08-08 9:18 Su Hui
2023-08-10 17:58 ` Amir Goldstein
0 siblings, 1 reply; 3+ messages in thread
From: Su Hui @ 2023-08-08 9:18 UTC (permalink / raw)
To: jack, amir73il, repnop
Cc: linux-fsdevel, linux-kernel, kernel-janitors, Su Hui
smatch error:
fs/notify/fanotify/fanotify_user.c:462 copy_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 <suhui@nfschina.com>
---
fs/notify/fanotify/fanotify_user.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index f69c451018e3..5a5487ae2460 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fanotify: avoid possible NULL dereference
2023-08-08 9:18 [PATCH] fanotify: avoid possible NULL dereference Su Hui
@ 2023-08-10 17:58 ` Amir Goldstein
2024-01-02 13:47 ` Jan Kara
0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2023-08-10 17:58 UTC (permalink / raw)
To: Su Hui; +Cc: jack, repnop, linux-fsdevel, linux-kernel, kernel-janitors
On Tue, Aug 8, 2023 at 12:19 PM Su Hui <suhui@nfschina.com> wrote:
>
> smatch error:
> fs/notify/fanotify/fanotify_user.c:462 copy_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 <suhui@nfschina.com>'
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> ---
> fs/notify/fanotify/fanotify_user.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index f69c451018e3..5a5487ae2460 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fanotify: avoid possible NULL dereference
2023-08-10 17:58 ` Amir Goldstein
@ 2024-01-02 13:47 ` Jan Kara
0 siblings, 0 replies; 3+ messages in thread
From: Jan Kara @ 2024-01-02 13:47 UTC (permalink / raw)
To: Amir Goldstein
Cc: Su Hui, jack, repnop, linux-fsdevel, linux-kernel,
kernel-janitors
On Thu 10-08-23 20:58:16, Amir Goldstein wrote:
> On Tue, Aug 8, 2023 at 12:19 PM Su Hui <suhui@nfschina.com> wrote:
> >
> > smatch error:
> > fs/notify/fanotify/fanotify_user.c:462 copy_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 <suhui@nfschina.com>'
>
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>
I'm sorry but this has somehow fallen through the cracks.
> > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> > index f69c451018e3..5a5487ae2460 100644
> > --- a/fs/notify/fanotify/fanotify_user.c
> > +++ b/fs/notify/fanotify/fanotify_user.c
> > @@ -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
> >
> > /* 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 <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-02 13:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-08 9:18 [PATCH] fanotify: avoid possible NULL dereference Su Hui
2023-08-10 17:58 ` Amir Goldstein
2024-01-02 13:47 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).