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

sctp: sctp_epaddr_lookup_transport should be protected by rcu_read_lock

Since commit 7fda702f9315 ("sctp: use new rhlist interface on sctp transport
rhashtable"), sctp has changed to use rhlist_lookup to look up transport, but
rhlist_lookup doesn't call rcu_read_lock inside, unlike rhashtable_lookup_fast.

It is called in sctp_epaddr_lookup_transport and sctp_addrs_lookup_transport.
sctp_addrs_lookup_transport is always in the protection of rcu_read_lock(),
as __sctp_lookup_association is called in rx path or sctp_lookup_association
which are in the protection of rcu_read_lock() already.

But sctp_epaddr_lookup_transport is called by sctp_endpoint_lookup_assoc, it
doesn't call rcu_read_lock, which may cause "suspicious rcu_dereference_check
usage' in __rhashtable_lookup.

This patch is to fix it by adding rcu_read_lock in sctp_endpoint_lookup_assoc
before calling sctp_epaddr_lookup_transport.

Fixes: 7fda702f9315 ("sctp: use new rhlist interface on sctp transport rhashtable")
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Xin Long and committed by
David S. Miller
5cb2cd68 10a3ecf4

+4 -1
+4 -1
net/sctp/endpointola.c
··· 331 331 * on this endpoint. 332 332 */ 333 333 if (!ep->base.bind_addr.port) 334 - goto out; 334 + return NULL; 335 + 336 + rcu_read_lock(); 335 337 t = sctp_epaddr_lookup_transport(ep, paddr); 336 338 if (!t) 337 339 goto out; ··· 341 339 *transport = t; 342 340 asoc = t->asoc; 343 341 out: 342 + rcu_read_unlock(); 344 343 return asoc; 345 344 } 346 345