Skip to content

Commit f10b4cf

Browse files
sowminivdavem330
authored andcommitted
rds: tcp: atomically purge entries from rds_tcp_conn_list during netns delete
The rds_tcp_kill_sock() function parses the rds_tcp_conn_list to find the rds_connection entries marked for deletion as part of the netns deletion under the protection of the rds_tcp_conn_lock. Since the rds_tcp_conn_list tracks rds_tcp_connections (which have a 1:1 mapping with rds_conn_path), multiple tc entries in the rds_tcp_conn_list will map to a single rds_connection, and will be deleted as part of the rds_conn_destroy() operation that is done outside the rds_tcp_conn_lock. The rds_tcp_conn_list traversal done under the protection of rds_tcp_conn_lock should not leave any doomed tc entries in the list after the rds_tcp_conn_lock is released, else another concurrently executiong netns delete (for a differnt netns) thread may trip on these entries. Reported-by: syzbot <[email protected]> Signed-off-by: Sowmini Varadhan <[email protected]> Acked-by: Santosh Shilimkar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 681648e commit f10b4cf

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

net/rds/tcp.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ static void rds_tcp_conn_free(void *arg)
306306
rdsdebug("freeing tc %p\n", tc);
307307

308308
spin_lock_irqsave(&rds_tcp_conn_lock, flags);
309-
list_del(&tc->t_tcp_node);
309+
if (!tc->t_tcp_node_detached)
310+
list_del(&tc->t_tcp_node);
310311
spin_unlock_irqrestore(&rds_tcp_conn_lock, flags);
311312

312313
kmem_cache_free(rds_tcp_conn_slab, tc);
@@ -510,8 +511,12 @@ static void rds_tcp_kill_sock(struct net *net)
510511

511512
if (net != c_net || !tc->t_sock)
512513
continue;
513-
if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn))
514+
if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn)) {
514515
list_move_tail(&tc->t_tcp_node, &tmp_list);
516+
} else {
517+
list_del(&tc->t_tcp_node);
518+
tc->t_tcp_node_detached = true;
519+
}
515520
}
516521
spin_unlock_irq(&rds_tcp_conn_lock);
517522
list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node)

net/rds/tcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct rds_tcp_incoming {
1212
struct rds_tcp_connection {
1313

1414
struct list_head t_tcp_node;
15+
bool t_tcp_node_detached;
1516
struct rds_conn_path *t_cpath;
1617
/* t_conn_path_lock synchronizes the connection establishment between
1718
* rds_tcp_accept_one and rds_tcp_conn_path_connect

0 commit comments

Comments
 (0)