Skip to content

Commit c5c1a03

Browse files
kcp-gitdavem330
authored andcommitted
net/rds: An rds_sock is added too early to the hash table
In rds_bind(), an rds_sock is added to the RDS bind hash table before rs_transport is set. This means that the socket can be found by the receive code path when rs_transport is NULL. And the receive code path de-references rs_transport for congestion update check. This can cause a panic. An rds_sock should not be added to the bind hash table before all the needed fields are set. Reported-by: syzbot+4b4f8163c2e246df3c4c@syzkaller.appspotmail.com Signed-off-by: Ka-Cheong Poon <ka-cheong.poon@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3e49317 commit c5c1a03

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

‎net/rds/bind.c‎

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2019 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This software is available to you under a choice of one of two
55
* licenses. You may choose to be licensed under the terms of the GNU
@@ -239,34 +239,30 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
239239
goto out;
240240
}
241241

242-
sock_set_flag(sk, SOCK_RCU_FREE);
243-
ret = rds_add_bound(rs, binding_addr, &port, scope_id);
244-
if (ret)
245-
goto out;
246-
247-
if (rs->rs_transport) { /* previously bound */
242+
/* The transport can be set using SO_RDS_TRANSPORT option before the
243+
* socket is bound.
244+
*/
245+
if (rs->rs_transport) {
248246
trans = rs->rs_transport;
249247
if (trans->laddr_check(sock_net(sock->sk),
250248
binding_addr, scope_id) != 0) {
251249
ret = -ENOPROTOOPT;
252-
rds_remove_bound(rs);
253-
} else {
254-
ret = 0;
250+
goto out;
255251
}
256-
goto out;
257-
}
258-
trans = rds_trans_get_preferred(sock_net(sock->sk), binding_addr,
259-
scope_id);
260-
if (!trans) {
261-
ret = -EADDRNOTAVAIL;
262-
rds_remove_bound(rs);
263-
pr_info_ratelimited("RDS: %s could not find a transport for %pI6c, load rds_tcp or rds_rdma?\n",
264-
__func__, binding_addr);
265-
goto out;
252+
} else {
253+
trans = rds_trans_get_preferred(sock_net(sock->sk),
254+
binding_addr, scope_id);
255+
if (!trans) {
256+
ret = -EADDRNOTAVAIL;
257+
pr_info_ratelimited("RDS: %s could not find a transport for %pI6c, load rds_tcp or rds_rdma?\n",
258+
__func__, binding_addr);
259+
goto out;
260+
}
261+
rs->rs_transport = trans;
266262
}
267263

268-
rs->rs_transport = trans;
269-
ret = 0;
264+
sock_set_flag(sk, SOCK_RCU_FREE);
265+
ret = rds_add_bound(rs, binding_addr, &port, scope_id);
270266

271267
out:
272268
release_sock(sk);

0 commit comments

Comments
 (0)