From: asmadeus@codewreck.org
To: Tuo Li <islituo@gmail.com>
Cc: ericvh@kernel.org, lucho@ionkov.net, linux_oss@crudebyte.com,
v9fs@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: 9p: Fix a possible null-pointer dereference in p9_cm_event_handler()
Date: Thu, 18 Dec 2025 21:56:04 +0900 [thread overview]
Message-ID: <aUP55AOY3L_TLkE3@codewreck.org> (raw)
In-Reply-To: <20251218071012.7740-1-islituo@gmail.com>
Tuo Li wrote on Thu, Dec 18, 2025 at 03:10:12PM +0800:
> In p9_cm_event_handler(), rdma is checked in the RDMA_CM_EVENT_DISCONNECTED
> case, indicating that it may be NULL. If this happens, a null-pointer
> dereference can occur when complete() is called:
>
> complete(&rdma->cm_done);
>
> To prevent such a potential null-pointer dereference, add a defensive check
> before invoking complete().
In practice it doesn't really make sense for rdma to be NULL here
though -- and we can make sure of it by assigning client->trans before
creating the cm_id and get rid of the other null check instead:
-----
diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c
index b5ceae1cccbb..f2d81f3ef255 100644
--- a/net/9p/trans_rdma.c
+++ b/net/9p/trans_rdma.c
@@ -145,8 +145,7 @@ p9_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
break;
case RDMA_CM_EVENT_DISCONNECTED:
- if (rdma)
- rdma->state = P9_RDMA_CLOSED;
+ rdma->state = P9_RDMA_CLOSED;
c->status = Disconnected;
break;
@@ -541,15 +540,15 @@ rdma_create_trans(struct p9_client *client, struct fs_context *fc)
if (!rdma)
return -ENOMEM;
+ /* Associate the client with the transport */
+ client->trans = rdma;
+
/* Create the RDMA CM ID */
rdma->cm_id = rdma_create_id(&init_net, p9_cm_event_handler, client,
RDMA_PS_TCP, IB_QPT_RC);
if (IS_ERR(rdma->cm_id))
goto error;
- /* Associate the client with the transport */
- client->trans = rdma;
-
/* Bind to a privileged port if we need to */
if (opts.privport) {
err = p9_rdma_bind_privport(rdma);
-----
What do you think?
--
Dominique
next prev parent reply other threads:[~2025-12-18 12:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 7:10 [PATCH] net: 9p: Fix a possible null-pointer dereference in p9_cm_event_handler() Tuo Li
2025-12-18 10:54 ` Christian Schoenebeck
2025-12-18 12:56 ` asmadeus [this message]
2025-12-18 13:13 ` Tuo Li
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=aUP55AOY3L_TLkE3@codewreck.org \
--to=asmadeus@codewreck.org \
--cc=ericvh@kernel.org \
--cc=islituo@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux_oss@crudebyte.com \
--cc=lucho@ionkov.net \
--cc=v9fs@lists.linux.dev \
/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