From: Dan Carpenter <dan.carpenter@linaro.org>
To: Su Hui <suhui@nfschina.com>, David Howells <dhowells@redhat.com>
Cc: sfrench@samba.org, pc@manguebit.com, ronniesahlberg@gmail.com,
sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com,
nathan@kernel.org, ndesaulniers@google.com, morbo@google.com,
justinstitt@google.com, linux-cifs@vger.kernel.org,
samba-technical@lists.samba.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] smb/client: avoid possible NULL dereference in cifs_free_subrequest()
Date: Fri, 9 Aug 2024 18:00:26 +0300 [thread overview]
Message-ID: <893f2ebb-2979-4e34-bdab-a7cbb0c7e7b8@stanley.mountain> (raw)
In-Reply-To: <20240808122331.342473-1-suhui@nfschina.com>
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@nfschina.com>
Needs 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?
regards,
dan carpenter
next prev parent reply other threads:[~2024-08-09 15:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-08 12:23 [PATCH] smb/client: avoid possible NULL dereference in cifs_free_subrequest() Su Hui
2024-08-08 21:51 ` Steve French
2024-08-09 15:00 ` Dan Carpenter [this message]
2024-08-09 15:11 ` Dan Carpenter
2024-08-09 15:42 ` Steve French
2024-08-09 15:46 ` Steve French
2024-08-09 15:38 ` Steve French
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=893f2ebb-2979-4e34-bdab-a7cbb0c7e7b8@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=bharathsm@microsoft.com \
--cc=dhowells@redhat.com \
--cc=justinstitt@google.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=pc@manguebit.com \
--cc=ronniesahlberg@gmail.com \
--cc=samba-technical@lists.samba.org \
--cc=sfrench@samba.org \
--cc=sprasad@microsoft.com \
--cc=suhui@nfschina.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox