Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net/rds: Fix NULL pointer dereference in rds_tcp_accept_one

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>
Link: https://patch.msgid.link/20260216222643.2391390-1-achender@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Allison Henderson and committed by
Paolo Abeni
6bf45704 45be47bf

+17 -3
+17 -3
net/rds/tcp_listen.c
··· 177 177 struct rds_tcp_connection *rs_tcp = NULL; 178 178 int conn_state; 179 179 struct rds_conn_path *cp; 180 + struct sock *sk; 180 181 struct in6_addr *my_addr, *peer_addr; 181 182 #if !IS_ENABLED(CONFIG_IPV6) 182 183 struct in6_addr saddr, daddr; ··· 299 298 rds_conn_path_drop(cp, 0); 300 299 goto rst_nsk; 301 300 } 301 + /* Save a local pointer to sk and hold a reference before setting 302 + * callbacks. Once callbacks are set, a concurrent 303 + * rds_tcp_conn_path_shutdown() may call sock_release(), which 304 + * sets new_sock->sk to NULL and drops a reference on sk. 305 + * The local pointer lets us safely access sk_state below even 306 + * if new_sock->sk has been nulled, and sock_hold() keeps sk 307 + * itself valid until we are done. 308 + */ 309 + sk = new_sock->sk; 310 + sock_hold(sk); 311 + 302 312 if (rs_tcp->t_sock) { 303 313 /* Duelling SYN has been handled in rds_tcp_accept_one() */ 304 314 rds_tcp_reset_callbacks(new_sock, cp); ··· 328 316 * knowing that "rds_tcp_conn_path_shutdown" will 329 317 * dequeue pending messages. 330 318 */ 331 - if (new_sock->sk->sk_state == TCP_CLOSE_WAIT || 332 - new_sock->sk->sk_state == TCP_LAST_ACK || 333 - new_sock->sk->sk_state == TCP_CLOSE) 319 + if (READ_ONCE(sk->sk_state) == TCP_CLOSE_WAIT || 320 + READ_ONCE(sk->sk_state) == TCP_LAST_ACK || 321 + READ_ONCE(sk->sk_state) == TCP_CLOSE) 334 322 rds_conn_path_drop(cp, 0); 335 323 else 336 324 queue_delayed_work(cp->cp_wq, &cp->cp_recv_w, 0); 325 + 326 + sock_put(sk); 337 327 338 328 new_sock = NULL; 339 329 ret = 0;