mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 02:50:49 +09:00
ndisc: use RCU protection in ndisc_alloc_skb()
[ Upstream commit 628e6d18930bbd21f2d4562228afe27694f66da9 ]
ndisc_alloc_skb() can be called without RTNL or RCU being held.
Add RCU protection to avoid possible UAF.
Fixes: de09334b93 ("ndisc: Introduce ndisc_alloc_skb() helper.")
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-3-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
84212387ca
commit
3c2d705f5a
@@ -418,15 +418,11 @@ static struct sk_buff *ndisc_alloc_skb(struct net_device *dev,
|
|||||||
{
|
{
|
||||||
int hlen = LL_RESERVED_SPACE(dev);
|
int hlen = LL_RESERVED_SPACE(dev);
|
||||||
int tlen = dev->needed_tailroom;
|
int tlen = dev->needed_tailroom;
|
||||||
struct sock *sk = dev_net(dev)->ipv6.ndisc_sk;
|
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
|
|
||||||
skb = alloc_skb(hlen + sizeof(struct ipv6hdr) + len + tlen, GFP_ATOMIC);
|
skb = alloc_skb(hlen + sizeof(struct ipv6hdr) + len + tlen, GFP_ATOMIC);
|
||||||
if (!skb) {
|
if (!skb)
|
||||||
ND_PRINTK(0, err, "ndisc: %s failed to allocate an skb\n",
|
|
||||||
__func__);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
skb->protocol = htons(ETH_P_IPV6);
|
skb->protocol = htons(ETH_P_IPV6);
|
||||||
skb->dev = dev;
|
skb->dev = dev;
|
||||||
@@ -437,7 +433,9 @@ static struct sk_buff *ndisc_alloc_skb(struct net_device *dev,
|
|||||||
/* Manually assign socket ownership as we avoid calling
|
/* Manually assign socket ownership as we avoid calling
|
||||||
* sock_alloc_send_pskb() to bypass wmem buffer limits
|
* sock_alloc_send_pskb() to bypass wmem buffer limits
|
||||||
*/
|
*/
|
||||||
skb_set_owner_w(skb, sk);
|
rcu_read_lock();
|
||||||
|
skb_set_owner_w(skb, dev_net_rcu(dev)->ipv6.ndisc_sk);
|
||||||
|
rcu_read_unlock();
|
||||||
|
|
||||||
return skb;
|
return skb;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user