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

net/rds: do proper house keeping if connection fails in rds_tcp_conn_connect

I see two problems if we consider the sock->ops->connect attempt to fail in
rds_tcp_conn_connect. The first issue is that for example we don't remove the
previously added rds_tcp_connection item to rds_tcp_tc_list at
rds_tcp_set_callbacks, which means that on a next reconnect attempt for the
same rds_connection, when rds_tcp_conn_connect is called we can again call
rds_tcp_set_callbacks, resulting in duplicated items on rds_tcp_tc_list,
leading to list corruption: to avoid this just make sure we call
properly rds_tcp_restore_callbacks before we exit. The second issue
is that we should also release the sock properly, by setting sock = NULL
only if we are returning without error.

Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Herton R. Krzesinski and committed by
David S. Miller
eb74cc97 310886dd

+4 -1
+4 -1
net/rds/tcp_connect.c
··· 106 106 rds_tcp_set_callbacks(sock, conn); 107 107 ret = sock->ops->connect(sock, (struct sockaddr *)&dest, sizeof(dest), 108 108 O_NONBLOCK); 109 - sock = NULL; 110 109 111 110 rdsdebug("connect to address %pI4 returned %d\n", &conn->c_faddr, ret); 112 111 if (ret == -EINPROGRESS) 113 112 ret = 0; 113 + if (ret == 0) 114 + sock = NULL; 115 + else 116 + rds_tcp_restore_callbacks(sock, conn->c_transport_data); 114 117 115 118 out: 116 119 if (sock)