Skip to content

Commit 8d93367

Browse files
Eric Dumazetdavem330
authored andcommitted
ipv6: make icmp6_send() robust against null skb->dev
syzbot was able to crash one host with the following stack trace : kasan: GPF could be caused by NULL-ptr deref or user memory access general protection fault: 0000 [#1] PREEMPT SMP KASAN CPU: 0 PID: 8625 Comm: syz-executor4 Not tainted 4.20.0+ torvalds#8 RIP: 0010:dev_net include/linux/netdevice.h:2169 [inline] RIP: 0010:icmp6_send+0x116/0x2d30 net/ipv6/icmp.c:426 icmpv6_send smack_socket_sock_rcv_skb security_sock_rcv_skb sk_filter_trim_cap __sk_receive_skb dccp_v6_do_rcv release_sock This is because a RX packet found socket owned by user and was stored into socket backlog. Before leaving RCU protected section, skb->dev was cleared in __sk_receive_skb(). When socket backlog was finally handled at release_sock() time, skb was fed to smack_socket_sock_rcv_skb() then icmp6_send() We could fix the bug in smack_socket_sock_rcv_skb(), or simply make icmp6_send() more robust against such possibility. In the future we might provide to icmp6_send() the net pointer instead of infering it. Fixes: d66a8ac ("Smack: Inform peer that IPv6 traffic has been blocked") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Piotr Sawicki <p.sawicki2@partner.samsung.com> Cc: Casey Schaufler <casey@schaufler-ca.com> Reported-by: syzbot <syzkaller@googlegroups.com> Acked-by: Casey Schaufler <casey@schaufler-ca.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3271a48 commit 8d93367

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

net/ipv6/icmp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,10 @@ static int icmp6_iif(const struct sk_buff *skb)
423423
static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
424424
const struct in6_addr *force_saddr)
425425
{
426-
struct net *net = dev_net(skb->dev);
427426
struct inet6_dev *idev = NULL;
428427
struct ipv6hdr *hdr = ipv6_hdr(skb);
429428
struct sock *sk;
429+
struct net *net;
430430
struct ipv6_pinfo *np;
431431
const struct in6_addr *saddr = NULL;
432432
struct dst_entry *dst;
@@ -437,12 +437,16 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
437437
int iif = 0;
438438
int addr_type = 0;
439439
int len;
440-
u32 mark = IP6_REPLY_MARK(net, skb->mark);
440+
u32 mark;
441441

442442
if ((u8 *)hdr < skb->head ||
443443
(skb_network_header(skb) + sizeof(*hdr)) > skb_tail_pointer(skb))
444444
return;
445445

446+
if (!skb->dev)
447+
return;
448+
net = dev_net(skb->dev);
449+
mark = IP6_REPLY_MARK(net, skb->mark);
446450
/*
447451
* Make sure we respect the rules
448452
* i.e. RFC 1885 2.4(e)

0 commit comments

Comments
 (0)