From: Wen Gu <guwen@linux.alibaba.com>
To: kgraul@linux.ibm.com, davem@davemloft.net, kuba@kernel.org
Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH net] net/smc: Reset conn->lgr when link group registration fails
Date: Tue, 28 Dec 2021 15:49:30 +0800 [thread overview]
Message-ID: <1640677770-112053-1-git-send-email-guwen@linux.alibaba.com> (raw)
SMC connections might fail to be registered to a link group due to
things like unable to find a link to assign to in its creation. As
a result, connection creation will return a failure and most
resources related to the connection won't be applied or initialized,
such as conn->abort_work or conn->lnk.
If smc_conn_free() is invoked later, it will try to access the
resources related to the connection, which wasn't initialized, thus
causing a panic.
Here is an example, a SMC-R connection failed to be registered
to a link group and conn->lnk is NULL. The following crash will
happen if smc_conn_free() tries to access conn->lnk in
smc_cdc_tx_dismiss_slots().
BUG: kernel NULL pointer dereference, address: 0000000000000168
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
PGD 0 P4D 0
Oops: 0000 [#1] PREEMPT SMP PTI
CPU: 4 PID: 68 Comm: kworker/4:1 Kdump: loaded Tainted: G E 5.16.0-rc5+ #52
Workqueue: smc_hs_wq smc_listen_work [smc]
RIP: 0010:smc_wr_tx_dismiss_slots+0x1e/0xc0 [smc]
Call Trace:
<TASK>
smc_conn_free+0xd8/0x100 [smc]
smc_lgr_cleanup_early+0x15/0x90 [smc]
smc_listen_work+0x302/0x1230 [smc]
? process_one_work+0x25c/0x600
process_one_work+0x25c/0x600
worker_thread+0x4f/0x3a0
? process_one_work+0x600/0x600
kthread+0x15d/0x1a0
? set_kthread_struct+0x40/0x40
ret_from_fork+0x1f/0x30
</TASK>
This patch tries to fix this by resetting conn->lgr to NULL if an
abnormal exit due to lgr register failure occurs in smc_conn_create(),
thus avoiding the crash caused by accessing the uninitialized resources
in smc_conn_free().
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
---
net/smc/smc_core.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 412bc85..1f40b8e 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1815,7 +1815,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
}
spin_unlock_bh(lgr_lock);
if (rc)
- return rc;
+ goto out_unreg;
if (role == SMC_CLNT && !ini->first_contact_peer &&
ini->first_contact_local) {
@@ -1836,7 +1836,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
rc = smc_lgr_register_conn(conn, true);
write_unlock_bh(&lgr->conns_lock);
if (rc)
- goto out;
+ goto out_unreg;
}
conn->local_tx_ctrl.common.type = SMC_CDC_MSG_TYPE;
conn->local_tx_ctrl.len = SMC_WR_TX_SIZE;
@@ -1855,6 +1855,12 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
out:
return rc;
+out_unreg:
+ /* fail to register connection into a link group */
+ if (!lgr->conns_num && !delayed_work_pending(&lgr->free_work))
+ smc_lgr_schedule_free_work(lgr);
+ conn->lgr = NULL;
+ return rc;
}
#define SMCD_DMBE_SIZES 6 /* 0 -> 16KB, 1 -> 32KB, .. 6 -> 1MB */
--
1.8.3.1
next reply other threads:[~2021-12-28 7:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-28 7:49 Wen Gu [this message]
2021-12-29 13:07 ` [RFC PATCH net] net/smc: Reset conn->lgr when link group registration fails Karsten Graul
2021-12-30 3:50 ` Wen Gu
2022-01-03 10:52 ` Karsten Graul
2022-01-04 2:13 ` Wen Gu
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=1640677770-112053-1-git-send-email-guwen@linux.alibaba.com \
--to=guwen@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=kgraul@linux.ibm.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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