* [PATCH net] net/rds: Fix NULL pointer dereference in rds_tcp_accept_one
@ 2026-02-16 22:26 Allison Henderson
2026-02-19 15:10 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Allison Henderson @ 2026-02-16 22:26 UTC (permalink / raw)
To: netdev
Cc: linux-kselftest, pabeni, edumazet, rds-devel, kuba, horms,
linux-rdma, allison.henderson
Save a local pointer to new_sock->sk and hold a reference before
installing callbacks in rds_tcp_accept_one. After
rds_tcp_set_callbacks() or rds_tcp_reset_callbacks(), tc->t_sock is
set to new_sock which may race with the shutdown path. A concurrent
rds_tcp_conn_path_shutdown() may call sock_release(), which sets
new_sock->sk = NULL and may eventually free sk when the refcount
reaches zero.
Subsequent accesses to new_sock->sk->sk_state would dereference NULL,
causing the crash. The fix saves a local sk pointer before callbacks
are installed so that sk_state can be accessed safely even after
new_sock->sk is nulled, and uses sock_hold()/sock_put() to ensure
sk itself remains valid for the duration.
Fixes: 826c1004d4ae ("net/rds: rds_tcp_conn_path_shutdown must not discard messages")
Reported-by: syzbot+96046021045ffe6d7709@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=96046021045ffe6d7709
Signed-off-by: Allison Henderson <achender@kernel.org>
---
net/rds/tcp_listen.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index 6fb5c928b8fd..b4ab68a1da6d 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -177,6 +177,7 @@ int rds_tcp_accept_one(struct rds_tcp_net *rtn)
struct rds_tcp_connection *rs_tcp = NULL;
int conn_state;
struct rds_conn_path *cp;
+ struct sock *sk;
struct in6_addr *my_addr, *peer_addr;
#if !IS_ENABLED(CONFIG_IPV6)
struct in6_addr saddr, daddr;
@@ -298,6 +299,17 @@ int rds_tcp_accept_one(struct rds_tcp_net *rtn)
rds_conn_path_drop(cp, 0);
goto rst_nsk;
}
+ /* Save a local pointer to sk and hold a reference before setting
+ * callbacks. Once callbacks are set, a concurrent
+ * rds_tcp_conn_path_shutdown() may call sock_release(), which
+ * sets new_sock->sk to NULL and drops a reference on sk.
+ * The local pointer lets us safely access sk_state below even
+ * if new_sock->sk has been nulled, and sock_hold() keeps sk
+ * itself valid until we are done.
+ */
+ sk = new_sock->sk;
+ sock_hold(sk);
+
if (rs_tcp->t_sock) {
/* Duelling SYN has been handled in rds_tcp_accept_one() */
rds_tcp_reset_callbacks(new_sock, cp);
@@ -316,13 +328,15 @@ int rds_tcp_accept_one(struct rds_tcp_net *rtn)
* knowing that "rds_tcp_conn_path_shutdown" will
* dequeue pending messages.
*/
- if (new_sock->sk->sk_state == TCP_CLOSE_WAIT ||
- new_sock->sk->sk_state == TCP_LAST_ACK ||
- new_sock->sk->sk_state == TCP_CLOSE)
+ if (READ_ONCE(sk->sk_state) == TCP_CLOSE_WAIT ||
+ READ_ONCE(sk->sk_state) == TCP_LAST_ACK ||
+ READ_ONCE(sk->sk_state) == TCP_CLOSE)
rds_conn_path_drop(cp, 0);
else
queue_delayed_work(cp->cp_wq, &cp->cp_recv_w, 0);
+ sock_put(sk);
+
new_sock = NULL;
ret = 0;
if (conn->c_npaths == 0)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net/rds: Fix NULL pointer dereference in rds_tcp_accept_one
2026-02-16 22:26 [PATCH net] net/rds: Fix NULL pointer dereference in rds_tcp_accept_one Allison Henderson
@ 2026-02-19 15:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-02-19 15:10 UTC (permalink / raw)
To: Allison Henderson
Cc: netdev, linux-kselftest, pabeni, edumazet, rds-devel, kuba, horms,
linux-rdma, allison.henderson
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Mon, 16 Feb 2026 15:26:43 -0700 you wrote:
> Save a local pointer to new_sock->sk and hold a reference before
> installing callbacks in rds_tcp_accept_one. After
> rds_tcp_set_callbacks() or rds_tcp_reset_callbacks(), tc->t_sock is
> set to new_sock which may race with the shutdown path. A concurrent
> rds_tcp_conn_path_shutdown() may call sock_release(), which sets
> new_sock->sk = NULL and may eventually free sk when the refcount
> reaches zero.
>
> [...]
Here is the summary with links:
- [net] net/rds: Fix NULL pointer dereference in rds_tcp_accept_one
https://git.kernel.org/netdev/net/c/6bf45704a92a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-19 15:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-16 22:26 [PATCH net] net/rds: Fix NULL pointer dereference in rds_tcp_accept_one Allison Henderson
2026-02-19 15:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox