[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH2r5mvHpNA-FLuq3gwV06tzwv+ioqQxFWqC8f3rcRPMrmdOFg@mail.gmail.com>
Date: Fri, 9 Aug 2024 10:38:17 -0500
From: Steve French <smfrench@...il.com>
To: Dan Carpenter <dan.carpenter@...aro.org>
Cc: Su Hui <suhui@...china.com>, David Howells <dhowells@...hat.com>, sfrench@...ba.org,
pc@...guebit.com, ronniesahlberg@...il.com, sprasad@...rosoft.com,
tom@...pey.com, bharathsm@...rosoft.com, nathan@...nel.org,
ndesaulniers@...gle.com, morbo@...gle.com, justinstitt@...gle.com,
linux-cifs@...r.kernel.org, samba-technical@...ts.samba.org,
linux-kernel@...r.kernel.org, llvm@...ts.linux.dev,
kernel-janitors@...r.kernel.org
Subject: Re: [PATCH] smb/client: avoid possible NULL dereference in cifs_free_subrequest()
On Fri, Aug 9, 2024 at 10:01 AM Dan Carpenter <dan.carpenter@...aro.org> wrote:
>
> On Thu, Aug 08, 2024 at 08:23:32PM +0800, Su Hui wrote:
> > Clang static checker (scan-build) warning:
> > cifsglob.h:line 890, column 3
> > Access to field 'ops' results in a dereference of a null pointer.
> >
> > Commit 519be989717c ("cifs: Add a tracepoint to track credits involved in
> > R/W requests") adds a check for 'rdata->server', and let clang throw this
> > warning about NULL dereference.
> >
> > When 'rdata->credits.value != 0 && rdata->server == NULL' happens,
> > add_credits_and_wake_if() will call rdata->server->ops->add_credits().
> > This will cause NULL dereference problem. Add a check for 'rdata->server'
> > to avoid NULL dereference.
> >
> > Signed-off-by: Su Hui <suhui@...china.com>
>
> Needs a Fixes tag.
I had added a fixes tag
> Also when you add a Fixes tag, then get_maintainer will add the David Howells
> automatically. I've added him manually.
>
> > ---
> > fs/smb/client/file.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
> > index b2405dd4d4d4..45459af5044d 100644
> > --- a/fs/smb/client/file.c
> > +++ b/fs/smb/client/file.c
> > @@ -315,7 +315,7 @@ static void cifs_free_subrequest(struct netfs_io_subrequest *subreq)
> > #endif
> > }
> >
> > - if (rdata->credits.value != 0)
> > + if (rdata->credits.value != 0) {
> > trace_smb3_rw_credits(rdata->rreq->debug_id,
> > rdata->subreq.debug_index,
> > rdata->credits.value,
> > @@ -323,8 +323,12 @@ static void cifs_free_subrequest(struct netfs_io_subrequest *subreq)
> > rdata->server ? rdata->server->in_flight : 0,
> > -rdata->credits.value,
> > cifs_trace_rw_credits_free_subreq);
> > + if (rdata->server)
> > + add_credits_and_wake_if(rdata->server, &rdata->credits, 0);
> > + else
> > + rdata->credits.value = 0;
> ^^^^^^^^^^^^^^^^^^^^^^^^^
> Why do this?
add_credits_and_wake() has the effect of setting credits->value to 0
so seems reasonable here
(in the case where add_credits_and_wake can not be safely called),
even if an extremely unlikely for rdata->server to be null.
--
Thanks,
Steve
Powered by blists - more mailing lists