Skip to content

Commit cd2b708

Browse files
lxindavem330
authored andcommitted
sctp: check duplicate node before inserting a new transport
sctp has changed to use rhlist for transport rhashtable since commit 7fda702 ("sctp: use new rhlist interface on sctp transport rhashtable"). But rhltable_insert_key doesn't check the duplicate node when inserting a node, unlike rhashtable_lookup_insert_key. It may cause duplicate assoc/transport in rhashtable. like: client (addr A, B) server (addr X, Y) connect to X INIT (1) ------------> connect to Y INIT (2) ------------> INIT_ACK (1) <------------ INIT_ACK (2) <------------ After sending INIT (2), one transport will be created and hashed into rhashtable. But when receiving INIT_ACK (1) and processing the address params, another transport will be created and hashed into rhashtable with the same addr Y and EP as the last transport. This will confuse the assoc/transport's lookup. This patch is to fix it by returning err if any duplicate node exists before inserting it. Fixes: 7fda702 ("sctp: use new rhlist interface on sctp transport rhashtable") Reported-by: Fabio M. Di Nitto <[email protected]> Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7e1392f commit cd2b708

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

net/sctp/input.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,8 @@ void sctp_transport_hashtable_destroy(void)
872872

873873
int sctp_hash_transport(struct sctp_transport *t)
874874
{
875+
struct sctp_transport *transport;
876+
struct rhlist_head *tmp, *list;
875877
struct sctp_hash_cmp_arg arg;
876878
int err;
877879

@@ -882,8 +884,19 @@ int sctp_hash_transport(struct sctp_transport *t)
882884
arg.paddr = &t->ipaddr;
883885
arg.lport = htons(t->asoc->base.bind_addr.port);
884886

887+
list = rhltable_lookup(&sctp_transport_hashtable, &arg,
888+
sctp_hash_params);
889+
890+
rhl_for_each_entry_rcu(transport, tmp, list, node)
891+
if (transport->asoc->ep == t->asoc->ep) {
892+
err = -EEXIST;
893+
goto out;
894+
}
895+
885896
err = rhltable_insert_key(&sctp_transport_hashtable, &arg,
886897
&t->node, sctp_hash_params);
898+
899+
out:
887900
if (err)
888901
pr_err_once("insert transport fail, errno %d\n", err);
889902

0 commit comments

Comments
 (0)