ndisc: extend RCU protection in ndisc_send_skb()
[ Upstream commit ed6ae1f325d3c43966ec1b62ac1459e2b8e45640 ]
ndisc_send_skb() can be called without RTNL or RCU held.
Acquire rcu_read_lock() earlier, so that we can use dev_net_rcu()
and avoid a potential UAF.
Fixes: 1762f7e88e ("[NETNS][IPV6] ndisc - make socket control per namespace")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250207135841.1948589-8-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
a849a10de5
commit
789230e5a8
+10
-6
@@ -471,16 +471,20 @@ static void ip6_nd_hdr(struct sk_buff *skb,
|
|||||||
void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,
|
void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,
|
||||||
const struct in6_addr *saddr)
|
const struct in6_addr *saddr)
|
||||||
{
|
{
|
||||||
struct dst_entry *dst = skb_dst(skb);
|
|
||||||
struct net *net = dev_net(skb->dev);
|
|
||||||
struct sock *sk = net->ipv6.ndisc_sk;
|
|
||||||
struct inet6_dev *idev;
|
|
||||||
int err;
|
|
||||||
struct icmp6hdr *icmp6h = icmp6_hdr(skb);
|
struct icmp6hdr *icmp6h = icmp6_hdr(skb);
|
||||||
|
struct dst_entry *dst = skb_dst(skb);
|
||||||
|
struct inet6_dev *idev;
|
||||||
|
struct net *net;
|
||||||
|
struct sock *sk;
|
||||||
|
int err;
|
||||||
u8 type;
|
u8 type;
|
||||||
|
|
||||||
type = icmp6h->icmp6_type;
|
type = icmp6h->icmp6_type;
|
||||||
|
|
||||||
|
rcu_read_lock();
|
||||||
|
|
||||||
|
net = dev_net_rcu(skb->dev);
|
||||||
|
sk = net->ipv6.ndisc_sk;
|
||||||
if (!dst) {
|
if (!dst) {
|
||||||
struct flowi6 fl6;
|
struct flowi6 fl6;
|
||||||
int oif = skb->dev->ifindex;
|
int oif = skb->dev->ifindex;
|
||||||
@@ -488,6 +492,7 @@ void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,
|
|||||||
icmpv6_flow_init(sk, &fl6, type, saddr, daddr, oif);
|
icmpv6_flow_init(sk, &fl6, type, saddr, daddr, oif);
|
||||||
dst = icmp6_dst_alloc(skb->dev, &fl6);
|
dst = icmp6_dst_alloc(skb->dev, &fl6);
|
||||||
if (IS_ERR(dst)) {
|
if (IS_ERR(dst)) {
|
||||||
|
rcu_read_unlock();
|
||||||
kfree_skb(skb);
|
kfree_skb(skb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -502,7 +507,6 @@ void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,
|
|||||||
|
|
||||||
ip6_nd_hdr(skb, saddr, daddr, READ_ONCE(inet6_sk(sk)->hop_limit), skb->len);
|
ip6_nd_hdr(skb, saddr, daddr, READ_ONCE(inet6_sk(sk)->hop_limit), skb->len);
|
||||||
|
|
||||||
rcu_read_lock();
|
|
||||||
idev = __in6_dev_get(dst->dev);
|
idev = __in6_dev_get(dst->dev);
|
||||||
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
|
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user