diff mbox series

[net,v6,08/10] ip6mr: Lock RCU before ip6mr_get_table() call in ip6_mroute_getsockopt()

Message ID 20241017174109.85717-9-stefan.wiehler@nokia.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Lock RCU before calling ip6mr_get_table() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/apply fail Patch does not apply to net-0

Commit Message

Stefan Wiehler Oct. 17, 2024, 5:37 p.m. UTC
When IPV6_MROUTE_MULTIPLE_TABLES is enabled, multicast routing tables
must be read under RCU or RTNL lock.

Fixes: d1db275dd3f6 ("ipv6: ip6mr: support multiple tables")
Signed-off-by: Stefan Wiehler <stefan.wiehler@nokia.com>
---
 net/ipv6/ip6mr.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 4726b9e156c7..b169b27de7e1 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -1878,9 +1878,12 @@  int ip6_mroute_getsockopt(struct sock *sk, int optname, sockptr_t optval,
 	    inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
 		return -EOPNOTSUPP;
 
+	rcu_read_lock();
 	mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT);
-	if (!mrt)
+	if (!mrt) {
+		rcu_read_unlock();
 		return -ENOENT;
+	}
 
 	switch (optname) {
 	case MRT6_VERSION:
@@ -1895,9 +1898,12 @@  int ip6_mroute_getsockopt(struct sock *sk, int optname, sockptr_t optval,
 		val = mrt->mroute_do_assert;
 		break;
 	default:
+		rcu_read_unlock();
 		return -ENOPROTOOPT;
 	}
 
+	rcu_read_unlock();
+
 	if (copy_from_sockptr(&olr, optlen, sizeof(int)))
 		return -EFAULT;