Commit 5179b266 authored by Xin Long's avatar Xin Long Committed by David S. Miller

sctp: call rcu_read_lock before checking for duplicate transport nodes

Commit cd2b7087 ("sctp: check duplicate node before inserting a
new transport") called rhltable_lookup() to check for the duplicate
transport node in transport rhashtable.

But rhltable_lookup() doesn't call rcu_read_lock inside, it could cause
a use-after-free issue if it tries to dereference the node that another
cpu has freed it. Note that sock lock can not avoid this as it is per
sock.

This patch is to fix it by calling rcu_read_lock before checking for
duplicate transport nodes.

Fixes: cd2b7087 ("sctp: check duplicate node before inserting a new transport")
Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
Acked-by: default avatarNeil Horman <nhorman@tuxdriver.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 540b1c48
...@@ -884,14 +884,17 @@ int sctp_hash_transport(struct sctp_transport *t) ...@@ -884,14 +884,17 @@ int sctp_hash_transport(struct sctp_transport *t)
arg.paddr = &t->ipaddr; arg.paddr = &t->ipaddr;
arg.lport = htons(t->asoc->base.bind_addr.port); arg.lport = htons(t->asoc->base.bind_addr.port);
rcu_read_lock();
list = rhltable_lookup(&sctp_transport_hashtable, &arg, list = rhltable_lookup(&sctp_transport_hashtable, &arg,
sctp_hash_params); sctp_hash_params);
rhl_for_each_entry_rcu(transport, tmp, list, node) rhl_for_each_entry_rcu(transport, tmp, list, node)
if (transport->asoc->ep == t->asoc->ep) { if (transport->asoc->ep == t->asoc->ep) {
rcu_read_unlock();
err = -EEXIST; err = -EEXIST;
goto out; goto out;
} }
rcu_read_unlock();
err = rhltable_insert_key(&sctp_transport_hashtable, &arg, err = rhltable_insert_key(&sctp_transport_hashtable, &arg,
&t->node, sctp_hash_params); &t->node, sctp_hash_params);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment