linux-stable/include
Kuniyuki Iwashima dd04213138 tcp/udp: Call inet6_destroy_sock() in IPv6 sk->sk_destruct().
commit d38afeec26 upstream.

Originally, inet6_sk(sk)->XXX were changed under lock_sock(), so we were
able to clean them up by calling inet6_destroy_sock() during the IPv6 ->
IPv4 conversion by IPV6_ADDRFORM.  However, commit 03485f2adc ("udpv6:
Add lockless sendmsg() support") added a lockless memory allocation path,
which could cause a memory leak:

setsockopt(IPV6_ADDRFORM)                 sendmsg()
+-----------------------+                 +-------+
- do_ipv6_setsockopt(sk, ...)             - udpv6_sendmsg(sk, ...)
  - sockopt_lock_sock(sk)                   ^._ called via udpv6_prot
    - lock_sock(sk)                             before WRITE_ONCE()
  - WRITE_ONCE(sk->sk_prot, &tcp_prot)
  - inet6_destroy_sock()                    - if (!corkreq)
  - sockopt_release_sock(sk)                  - ip6_make_skb(sk, ...)
    - release_sock(sk)                          ^._ lockless fast path for
                                                    the non-corking case

                                                - __ip6_append_data(sk, ...)
                                                  - ipv6_local_rxpmtu(sk, ...)
                                                    - xchg(&np->rxpmtu, skb)
                                                      ^._ rxpmtu is never freed.

                                                - goto out_no_dst;

                                            - lock_sock(sk)

For now, rxpmtu is only the case, but not to miss the future change
and a similar bug fixed in commit e27326009a ("net: ping6: Fix
memleak in ipv6_renew_options()."), let's set a new function to IPv6
sk->sk_destruct() and call inet6_cleanup_sock() there.  Since the
conversion does not change sk->sk_destruct(), we can guarantee that
we can clean up IPv6 resources finally.

We can now remove all inet6_destroy_sock() calls from IPv6 protocol
specific ->destroy() functions, but such changes are invasive to
backport.  So they can be posted as a follow-up later for net-next.

Fixes: 03485f2adc ("udpv6: Add lockless sendmsg() support")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-26 13:51:54 +02:00
..
acpi ACPI: APEI: Fix integer overflow in ghes_estatus_pool_init() 2022-11-10 18:15:34 +01:00
asm-generic arch: fix broken BuildID for arm64 and riscv 2023-03-17 08:49:03 +01:00
clocksource
crypto crypto: blake2s - remove shash module 2022-08-17 14:24:19 +02:00
drm drm/bridge: Fix returned array size name for atomic_get_input_bus_fmts kdoc 2023-03-22 13:31:26 +01:00
dt-bindings clk: imx8mn: rename vpu_pll to m7_alt_pll 2022-12-31 13:14:12 +01:00
keys
kunit
kvm
linux netfilter: nf_tables: fix ifdef to also consider nf_tables=m 2023-04-26 13:51:48 +02:00
math-emu
media media: dvbdev: fix build warning due to comments 2022-12-31 13:14:47 +01:00
memory
misc
net tcp/udp: Call inet6_destroy_sock() in IPv6 sk->sk_destruct(). 2023-04-26 13:51:54 +02:00
pcmcia
ras Revert "mm/memory-failure.c: fix race with changing page compound again" 2022-07-12 16:35:17 +02:00
rdma
scsi scsi: iscsi_tcp: Fix UAF during logout when accessing the shost ipaddress 2023-02-09 11:26:39 +01:00
soc ARM: at91: pm: avoid soft resetting AC DLL 2022-11-26 09:24:34 +01:00
sound ASoC: soc-dapm.h: fixup warning struct snd_pcm_substream not declared 2023-03-10 09:39:31 +01:00
target
trace f2fs: Fix f2fs_truncate_partial_nodes ftrace event 2023-04-26 13:51:49 +02:00
uapi usb: uvc: Enumerate valid values for color matching 2023-03-11 13:57:37 +01:00
vdso
video video: of_display_timing.h: include errno.h 2022-07-12 16:35:10 +02:00
xen x86/PVH: obtain VGA console info in Dom0 2023-04-05 11:24:52 +02:00