android_kernel_samsung_msm8976/net/ipv4
Eric Dumazet c627e24f97 igmp: fix memory leak in igmpv3_del_delrec()
commit e5b1c6c6277d5a283290a8c033c72544746f9b5b upstream.

im->tomb and/or im->sources might not be NULL, but we
currently overwrite their values blindly.

Using swap() will make sure the following call to kfree_pmc(pmc)
will properly free the psf structures.

Tested with the C repro provided by syzbot, which basically does :

 socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
 setsockopt(3, SOL_IP, IP_ADD_MEMBERSHIP, "\340\0\0\2\177\0\0\1\0\0\0\0", 12) = 0
 ioctl(3, SIOCSIFFLAGS, {ifr_name="lo", ifr_flags=0}) = 0
 setsockopt(3, SOL_IP, IP_MSFILTER, "\340\0\0\2\177\0\0\1\1\0\0\0\1\0\0\0\377\377\377\377", 20) = 0
 ioctl(3, SIOCSIFFLAGS, {ifr_name="lo", ifr_flags=IFF_UP}) = 0
 exit_group(0)                    = ?

BUG: memory leak
unreferenced object 0xffff88811450f140 (size 64):
  comm "softirq", pid 0, jiffies 4294942448 (age 32.070s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00  ................
    00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
  backtrace:
    [<00000000c7bad083>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline]
    [<00000000c7bad083>] slab_post_alloc_hook mm/slab.h:439 [inline]
    [<00000000c7bad083>] slab_alloc mm/slab.c:3326 [inline]
    [<00000000c7bad083>] kmem_cache_alloc_trace+0x13d/0x280 mm/slab.c:3553
    [<000000009acc4151>] kmalloc include/linux/slab.h:547 [inline]
    [<000000009acc4151>] kzalloc include/linux/slab.h:742 [inline]
    [<000000009acc4151>] ip_mc_add1_src net/ipv4/igmp.c:1976 [inline]
    [<000000009acc4151>] ip_mc_add_src+0x36b/0x400 net/ipv4/igmp.c:2100
    [<000000004ac14566>] ip_mc_msfilter+0x22d/0x310 net/ipv4/igmp.c:2484
    [<0000000052d8f995>] do_ip_setsockopt.isra.0+0x1795/0x1930 net/ipv4/ip_sockglue.c:959
    [<000000004ee1e21f>] ip_setsockopt+0x3b/0xb0 net/ipv4/ip_sockglue.c:1248
    [<0000000066cdfe74>] udp_setsockopt+0x4e/0x90 net/ipv4/udp.c:2618
    [<000000009383a786>] sock_common_setsockopt+0x38/0x50 net/core/sock.c:3126
    [<00000000d8ac0c94>] __sys_setsockopt+0x98/0x120 net/socket.c:2072
    [<000000001b1e9666>] __do_sys_setsockopt net/socket.c:2083 [inline]
    [<000000001b1e9666>] __se_sys_setsockopt net/socket.c:2080 [inline]
    [<000000001b1e9666>] __x64_sys_setsockopt+0x26/0x30 net/socket.c:2080
    [<00000000420d395e>] do_syscall_64+0x76/0x1a0 arch/x86/entry/common.c:301
    [<000000007fd83a4b>] entry_SYSCALL_64_after_hwframe+0x44/0xa9

Fixes: 24803f38a5c0 ("igmp: do not remove igmp souce list info when set link down")
Change-Id: I01882debe8d62ab933db82a435386a5387c02a1a
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Hangbin Liu <liuhangbin@gmail.com>
Reported-by: syzbot+6ca1abd0db68b5173a4f@syzkaller.appspotmail.com
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
2019-10-27 19:33:52 +01:00
..
netfilter Revert "netfilter: have ip*t REJECT set the sock err when an icmp is to be sent" 2019-07-27 21:51:03 +02:00
Kconfig
Makefile
af_inet.c udp: ipv4: Add udp early demux 2019-07-27 22:07:48 +02:00
ah4.c ipv4: properly refresh rtable entries on pmtu/redirect events 2019-07-27 21:45:24 +02:00
arp.c ipv4: add option to drop gratuitous ARP packets 2019-08-03 00:23:56 +02:00
cipso_ipv4.c netlabel: fix out-of-bounds memory accesses 2019-07-27 22:10:24 +02:00
datagram.c
devinet.c ipv4: add option to drop gratuitous ARP packets 2019-08-03 00:23:56 +02:00
esp4.c xfrm: Return error on unknown encap_type in init_state 2019-07-27 21:46:27 +02:00
fib_frontend.c ipv4: remove BUG_ON() from fib_compute_spec_dst 2019-07-27 21:52:57 +02:00
fib_lookup.h
fib_rules.c
fib_semantics.c ipv4: fix a race in update_or_create_fnhe() 2019-07-27 22:10:30 +02:00
fib_trie.c
gre.c
icmp.c net: inet: Support UID-based routing in IP protocols. 2019-07-27 21:50:59 +02:00
igmp.c igmp: fix memory leak in igmpv3_del_delrec() 2019-10-27 19:33:52 +01:00
inet_connection_sock.c net: inet: Support UID-based routing in IP protocols. 2019-07-27 21:50:59 +02:00
inet_diag.c net: inet: diag: expose the socket mark to privileged processes. 2019-07-27 21:50:56 +02:00
inet_fragment.c
inet_hashtables.c
inet_lro.c
inet_timewait_sock.c soreuseport: initialise timewait reuseport field 2019-07-27 21:52:18 +02:00
inetpeer.c net: ipv4: use a dedicated counter for icmp_v4 redirect packets 2019-07-27 22:07:53 +02:00
ip_forward.c
ip_fragment.c ANDROID: Revert "net: increase fragment memory usage limits" 2019-07-27 21:51:06 +02:00
ip_gre.c
ip_input.c ipv4: add option to drop unicast encapsulated in L2 multicast 2019-08-03 00:23:48 +02:00
ip_options.c
ip_output.c ipv4: ip_do_fragment: Preserve skb_iif during fragmentation 2019-07-27 22:10:35 +02:00
ip_sockglue.c net: add build-time checks for msg->msg_name size 2019-08-16 03:55:59 +02:00
ip_tunnel.c ipv4: igmp: guard against silly MTU values 2019-07-27 22:08:52 +02:00
ip_vti.c Make the VTI code compile. 2019-07-27 21:51:05 +02:00
ipcomp.c ipv4: properly refresh rtable entries on pmtu/redirect events 2019-07-27 21:45:24 +02:00
ipconfig.c
ipip.c
ipmr.c ipv4: Fix potential Spectre v1 vulnerability 2019-07-27 21:53:29 +02:00
netfilter.c
ping.c net: add build-time checks for msg->msg_name size 2019-08-16 03:55:59 +02:00
proc.c tcp: tcp_fragment() should apply sane memory limits 2019-07-27 22:11:09 +02:00
protocol.c
raw.c ipv4: Use return value of inet_iif() for __raw_v4_lookup in the while loop 2019-09-24 21:55:44 +02:00
route.c ipv4: fix a race in update_or_create_fnhe() 2019-07-27 22:10:30 +02:00
syncookies.c net: inet: Support UID-based routing in IP protocols. 2019-07-27 21:50:59 +02:00
sysctl_net_ipv4.c BACKPORT: tcp: add tcp_min_snd_mss sysctl 2019-07-27 22:11:10 +02:00
sysfs_net_ipv4.c
tcp.c tcp: limit payload size of sacked skbs 2019-07-27 22:11:09 +02:00
tcp_bic.c
tcp_cong.c tcp: disallow cwnd undo when switching congestion control 2019-07-27 21:44:29 +02:00
tcp_cubic.c
tcp_diag.c
tcp_fastopen.c
tcp_highspeed.c
tcp_htcp.c
tcp_hybla.c
tcp_illinois.c
tcp_input.c tcp: limit payload size of sacked skbs 2019-07-27 22:11:09 +02:00
tcp_ipv4.c net: Replace more instances of ACCESS_ONCE w/ READ_ONCE 2019-07-27 22:08:51 +02:00
tcp_lp.c tcp: fix wraparound issue in tcp_lp 2019-07-27 21:44:45 +02:00
tcp_memcontrol.c
tcp_metrics.c
tcp_minisocks.c tcp: remove BUG_ON() in tcp_check_req() 2019-07-27 21:51:29 +02:00
tcp_output.c tcp: be more careful in tcp_fragment() 2019-08-15 21:02:46 +02:00
tcp_probe.c
tcp_scalable.c
tcp_timer.c BACKPORT: tcp: enforce tcp_min_snd_mss in tcp_mtu_probing() 2019-07-27 22:11:10 +02:00
tcp_vegas.c
tcp_vegas.h
tcp_veno.c
tcp_westwood.c
tcp_yeah.c
tunnel4.c
udp.c net: add build-time checks for msg->msg_name size 2019-08-16 03:55:59 +02:00
udp_diag.c net: inet: diag: expose the socket mark to privileged processes. 2019-07-27 21:50:56 +02:00
udp_impl.h
udplite.c
xfrm4_input.c xfrm: Reinject transport-mode packets through tasklet 2019-07-27 21:46:20 +02:00
xfrm4_mode_beet.c
xfrm4_mode_transport.c
xfrm4_mode_tunnel.c
xfrm4_output.c
xfrm4_policy.c xfrm4: Fix uninitialized memory read in _decode_session4 2019-08-15 21:02:28 +02:00
xfrm4_state.c
xfrm4_tunnel.c