netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sctp: Add rcu lock to protect dst entry in sctp_transport_route
@ 2019-06-10  3:20 Su Yanjun
  2019-06-10 11:12 ` Neil Horman
  0 siblings, 1 reply; 6+ messages in thread
From: Su Yanjun @ 2019-06-10  3:20 UTC (permalink / raw)
  To: vyasevich, nhorman, marcelo.leitner, davem
  Cc: linux-sctp, netdev, linux-kernel, Su Yanjun

syzbot found a crash in rt_cache_valid. Problem is that when more
threads release dst in sctp_transport_route, the route cache can
be freed.

As follows,
p1:
sctp_transport_route
  dst_release
  get_dst

p2:
sctp_transport_route
  dst_release
  get_dst
...

If enough threads calling dst_release will cause dst->refcnt==0
then rcu softirq will reclaim the dst entry,get_dst then use
the freed memory.

This patch adds rcu lock to protect the dst_entry here.

Fixes: 6e91b578bf3f("sctp: re-use sctp_transport_pmtu in sctp_transport_route")
Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
Reported-by: syzbot+a9e23ea2aa21044c2798@syzkaller.appspotmail.com
---
 net/sctp/transport.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index ad158d3..5ad7e20 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -308,8 +308,13 @@ void sctp_transport_route(struct sctp_transport *transport,
 	struct sctp_association *asoc = transport->asoc;
 	struct sctp_af *af = transport->af_specific;
 
+	/* When dst entry is being released, route cache may be referred
+	 * again. Add rcu lock here to protect dst entry.
+	 */
+	rcu_read_lock();
 	sctp_transport_dst_release(transport);
 	af->get_dst(transport, saddr, &transport->fl, sctp_opt2sk(opt));
+	rcu_read_unlock();
 
 	if (saddr)
 		memcpy(&transport->saddr, saddr, sizeof(union sctp_addr));
-- 
2.7.4




^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-13 16:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10  3:20 [PATCH] sctp: Add rcu lock to protect dst entry in sctp_transport_route Su Yanjun
2019-06-10 11:12 ` Neil Horman
     [not found]   ` <08f76a75-9e5b-2434-9175-e5371fa9cb7e@cn.fujitsu.com>
2019-06-12 13:13     ` Neil Horman
2019-06-13  2:37       ` Su Yanjun
2019-06-13 11:35         ` Neil Horman
2019-06-13 12:52           ` Marcelo Ricardo Leitner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).