linux-stable/net/ipv6
Kuniyuki Iwashima 421e5dd1f1 net: ping6: Fix memleak in ipv6_renew_options().
commit e27326009a upstream.

When we close ping6 sockets, some resources are left unfreed because
pingv6_prot is missing sk->sk_prot->destroy().  As reported by
syzbot [0], just three syscalls leak 96 bytes and easily cause OOM.

    struct ipv6_sr_hdr *hdr;
    char data[24] = {0};
    int fd;

    hdr = (struct ipv6_sr_hdr *)data;
    hdr->hdrlen = 2;
    hdr->type = IPV6_SRCRT_TYPE_4;

    fd = socket(AF_INET6, SOCK_DGRAM, NEXTHDR_ICMP);
    setsockopt(fd, IPPROTO_IPV6, IPV6_RTHDR, data, 24);
    close(fd);

To fix memory leaks, let's add a destroy function.

Note the socket() syscall checks if the GID is within the range of
net.ipv4.ping_group_range.  The default value is [1, 0] so that no
GID meets the condition (1 <= GID <= 0).  Thus, the local DoS does
not succeed until we change the default value.  However, at least
Ubuntu/Fedora/RHEL loosen it.

    $ cat /usr/lib/sysctl.d/50-default.conf
    ...
    -net.ipv4.ping_group_range = 0 2147483647

Also, there could be another path reported with these options, and
some of them require CAP_NET_RAW.

  setsockopt
      IPV6_ADDRFORM (inet6_sk(sk)->pktoptions)
      IPV6_RECVPATHMTU (inet6_sk(sk)->rxpmtu)
      IPV6_HOPOPTS (inet6_sk(sk)->opt)
      IPV6_RTHDRDSTOPTS (inet6_sk(sk)->opt)
      IPV6_RTHDR (inet6_sk(sk)->opt)
      IPV6_DSTOPTS (inet6_sk(sk)->opt)
      IPV6_2292PKTOPTIONS (inet6_sk(sk)->opt)

  getsockopt
      IPV6_FLOWLABEL_MGR (inet6_sk(sk)->ipv6_fl_list)

For the record, I left a different splat with syzbot's one.

  unreferenced object 0xffff888006270c60 (size 96):
    comm "repro2", pid 231, jiffies 4294696626 (age 13.118s)
    hex dump (first 32 bytes):
      01 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00  ....D...........
      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    backtrace:
      [<00000000f6bc7ea9>] sock_kmalloc (net/core/sock.c:2564 net/core/sock.c:2554)
      [<000000006d699550>] do_ipv6_setsockopt.constprop.0 (net/ipv6/ipv6_sockglue.c:715)
      [<00000000c3c3b1f5>] ipv6_setsockopt (net/ipv6/ipv6_sockglue.c:1024)
      [<000000007096a025>] __sys_setsockopt (net/socket.c:2254)
      [<000000003a8ff47b>] __x64_sys_setsockopt (net/socket.c:2265 net/socket.c:2262 net/socket.c:2262)
      [<000000007c409dcb>] do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80)
      [<00000000e939c4a9>] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120)

[0]: https://syzkaller.appspot.com/bug?extid=a8430774139ec3ab7176

Fixes: 6d0bfe2261 ("net: ipv6: Add IPv6 support to the ping socket.")
Reported-by: syzbot+a8430774139ec3ab7176@syzkaller.appspotmail.com
Reported-by: Ayushman Dutta <ayudutta@amazon.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20220728012220.46918-1-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-08-03 11:59:39 +02:00
..
ila
netfilter netfilter: ip6_tables: zero-initialize fragment offset 2021-10-17 10:42:33 +02:00
addrconf.c ipv6: take care of disable_policy when restoring routes 2022-07-07 17:36:47 +02:00
addrconf_core.c net: ipv6_stub: use ip6_dst_lookup_flow instead of ip6_dst_lookup 2019-12-18 16:08:42 +01:00
addrlabel.c ipv6: addrlabel: fix possible memory leak in ip6addrlbl_net_init 2020-12-08 10:40:23 +01:00
af_inet6.c ip: Fix data-races around sysctl_ip_no_pmtu_disc. 2022-07-29 17:14:10 +02:00
ah6.c ah6: fix error return code in ah6_input() 2020-11-24 13:28:55 +01:00
anycast.c ipv6: fix memory leaks on IPV6_ADDRFORM path 2020-08-11 15:33:39 +02:00
calipso.c cipso,calipso: resolve a number of problems with the DOI refcounts 2021-03-17 17:03:35 +01:00
datagram.c net: ipv6: add net argument to ip6_dst_lookup_flow 2019-12-18 16:08:40 +01:00
esp6.c esp: limit skb_page_frag_refill use to a single page 2022-07-12 16:30:45 +02:00
esp6_offload.c esp: delete NETIF_F_SCTP_CRC bit from features for esp offload 2021-04-14 08:24:13 +02:00
exthdrs.c ipv6: fix out-of-bound access in ip6_parse_tlv() 2021-07-14 16:53:33 +02:00
exthdrs_core.c
exthdrs_offload.c
fib6_notifier.c
fib6_rules.c ipv6: fix memory leak in fib6_rule_suppress 2021-12-08 09:01:13 +01:00
fou6.c
icmp.c net: icmp: pass zeroed opts from icmp{,v6}_ndo_send before sending 2021-03-04 10:26:53 +01:00
inet6_connection_sock.c net: add bool confirm_neigh parameter for dst_ops.update_pmtu 2020-01-04 19:18:58 +01:00
inet6_hashtables.c secure_seq: use the 64 bits of the siphash for port offset calculation 2022-06-06 08:33:49 +02:00
ip6_checksum.c
ip6_fib.c ipv6: annotate accesses to fn->fn_sernum 2022-02-01 17:24:38 +01:00
ip6_flowlabel.c
ip6_gre.c erspan: do not assume transport header is always set 2022-06-29 08:58:46 +02:00
ip6_icmp.c net: icmp: pass zeroed opts from icmp{,v6}_ndo_send before sending 2021-03-04 10:26:53 +01:00
ip6_input.c ipv6: make mc_forwarding atomic 2022-04-15 14:18:32 +02:00
ip6_offload.c gso: do not skip outer ip header in case of ipip and net_failover 2022-03-02 11:41:06 +01:00
ip6_offload.h
ip6_output.c ipv6: fix panic when forwarding a pkt with no in6 dev 2022-04-20 09:19:38 +02:00
ip6_tunnel.c ipv6_tunnel: Rate limit warning messages 2022-02-01 17:24:36 +01:00
ip6_udp_tunnel.c
ip6_vti.c ip6_vti: initialize __ip6_tnl_parm struct in vti6_siocdevprivate 2022-01-11 15:23:33 +01:00
ip6mr.c ipv6: make mc_forwarding atomic 2022-04-15 14:18:32 +02:00
ipcomp6.c
ipv6_sockglue.c ipv6: fix memory leaks on IPV6_ADDRFORM path 2020-08-11 15:33:39 +02:00
Kconfig net: ipv6: fix kconfig dependency warning for IPV6_SEG6_HMAC 2020-09-26 18:03:13 +02:00
Makefile
mcast.c mld: fix panic in mld_newpack() 2021-06-03 08:59:14 +02:00
mcast_snoop.c net: bridge: mcast: fix broken length + header check for MRDv6 Adv. 2021-05-14 09:44:32 +02:00
mip6.c
ndisc.c Exempt multicast addresses from five-second neighbor lifetime 2020-11-24 13:28:56 +01:00
netfilter.c netfilter: use actual socket sk rather than skb sk when routing harder 2020-11-18 19:20:17 +01:00
output_core.c ipv6: use prandom_u32() for ID generation 2021-07-19 08:53:09 +02:00
ping.c net: ping6: Fix memleak in ipv6_renew_options(). 2022-08-03 11:59:39 +02:00
proc.c
protocol.c
raw.c net-ipv6: bugfix - raw & sctp - switch to ipv6_can_nonlocal_bind() 2021-04-14 08:24:12 +02:00
reassembly.c ipv6: record frag_max_size in atomic fragments in input path 2021-06-03 08:59:15 +02:00
route.c ipv6: take care of disable_policy when restoring routes 2022-07-07 17:36:47 +02:00
seg6.c
seg6_hmac.c net: ipv6: unexport __init-annotated seg6_hmac_net_init() 2022-07-07 17:36:49 +02:00
seg6_iptunnel.c seg6: fix skb checksum evaluation in SRH encapsulation/insertion 2022-07-21 20:59:23 +02:00
seg6_local.c seg6: fix skb checksum in SRv6 End.B6 and End.B6.Encaps behaviors 2022-07-21 20:59:23 +02:00
sit.c ipv6/sit: fix ipip6_tunnel_get_prl return value 2022-07-07 17:36:51 +02:00
syncookies.c tcp: Fix data-races around sysctl_tcp_syncookies. 2022-07-29 17:14:13 +02:00
sysctl_net_ipv6.c ipv6: Fix sysctl max for fib_multipath_hash_policy 2020-09-12 14:18:55 +02:00
tcp_ipv6.c tcp: make sure treq->af_specific is initialized 2022-05-12 12:23:50 +02:00
tcpv6_offload.c
tunnel6.c
udp.c udp: call udp_encap_enable for v6 sockets when enabling encap 2022-04-15 14:18:01 +02:00
udp_impl.h
udp_offload.c
udplite.c
xfrm6_input.c
xfrm6_output.c xfrm: fix tunnel model fragmentation behavior 2022-04-15 14:17:56 +02:00
xfrm6_policy.c net: add bool confirm_neigh parameter for dst_ops.update_pmtu 2020-01-04 19:18:58 +01:00
xfrm6_protocol.c
xfrm6_state.c
xfrm6_tunnel.c