android_kernel_motorola_sm6375/net
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Kuniyuki Iwashima 9c99aacfb4 tcp: Fix potential use-after-free due to double kfree()
commit c89dffc70b340780e5b933832d8c3e045ef3791e upstream.

Receiving ACK with a valid SYN cookie, cookie_v4_check() allocates struct
request_sock and then can allocate inet_rsk(req)->ireq_opt. After that,
tcp_v4_syn_recv_sock() allocates struct sock and copies ireq_opt to
inet_sk(sk)->inet_opt. Normally, tcp_v4_syn_recv_sock() inserts the full
socket into ehash and sets NULL to ireq_opt. Otherwise,
tcp_v4_syn_recv_sock() has to reset inet_opt by NULL and free the full
socket.

The commit 01770a1661657 ("tcp: fix race condition when creating child
sockets from syncookies") added a new path, in which more than one cores
create full sockets for the same SYN cookie. Currently, the core which
loses the race frees the full socket without resetting inet_opt, resulting
in that both sock_put() and reqsk_put() call kfree() for the same memory:

  sock_put
    sk_free
      __sk_free
        sk_destruct
          __sk_destruct
            sk->sk_destruct/inet_sock_destruct
              kfree(rcu_dereference_protected(inet->inet_opt, 1));

  reqsk_put
    reqsk_free
      __reqsk_free
        req->rsk_ops->destructor/tcp_v4_reqsk_destructor
          kfree(rcu_dereference_protected(inet_rsk(req)->ireq_opt, 1));

Calling kmalloc() between the double kfree() can lead to use-after-free, so
this patch fixes it by setting NULL to inet_opt before sock_put().

As a side note, this kind of issue does not happen for IPv6. This is
because tcp_v6_syn_recv_sock() clones both ipv6_opt and pktopts which
correspond to ireq_opt in IPv4.

Fixes: 01770a166165 ("tcp: fix race condition when creating child sockets from syncookies")
CC: Ricardo Dias <rdias@singlestore.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Reviewed-by: Benjamin Herrenschmidt <benh@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20210118055920.82516-1-kuniyu@amazon.co.jp
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-04-27 13:50:46 +02:00
..
6lowpan
9p xen/9p: use alloc/free_pages_exact() 2022-03-11 11:22:39 +01:00
802
8021q
appletalk
atm
ax25 ax25: Fix UAF bugs in ax25 timers 2022-04-20 09:19:40 +02:00
batman-adv ipv6: make mc_forwarding atomic 2022-04-15 14:18:32 +02:00
bluetooth Bluetooth: Fix use after free in hci_send_acl 2022-04-15 14:18:34 +02:00
bpf
bpfilter
bridge net: bridge: fix stale eth hdr pointer in br_dev_xmit 2022-02-16 12:52:50 +01:00
caif
can
ceph
core net/sched: flower: fix parsing of ethertype following VLAN header 2022-04-20 09:19:34 +02:00
dcb net: dcb: disable softirqs in dcbnl_flush_dev() 2022-03-08 19:07:51 +01:00
dccp tcp: fix race condition when creating child sockets from syncookies 2022-04-27 13:50:45 +02:00
decnet
dns_resolver
dsa net: dsa: Add missing of_node_put() in dsa_port_parse_of 2022-03-23 09:12:07 +01:00
ethernet
hsr
ieee802154 net: ieee802154: Return meaningful error codes from the netlink helpers 2022-02-08 18:24:31 +01:00
ife
ipv4 tcp: Fix potential use-after-free due to double kfree() 2022-04-27 13:50:46 +02:00
ipv6 tcp: fix race condition when creating child sockets from syncookies 2022-04-27 13:50:45 +02:00
iucv
kcm
key af_key: add __GFP_ZERO flag for compose_sadb_supported in function pfkey_register 2022-04-15 14:17:56 +02:00
l2tp
l3mdev
lapb
llc llc: only change llc->dev when bind() succeeds 2022-03-28 08:46:48 +02:00
mac80211 mac80211: fix potential double free on mesh join 2022-03-28 08:46:48 +02:00
mac802154
mpls
ncsi
netfilter netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options 2022-04-15 14:18:20 +02:00
netlabel netlabel: fix out-of-bounds memory accesses 2022-04-15 14:18:35 +02:00
netlink af_netlink: Fix shift out of bounds in group mask calculation 2022-04-15 14:18:16 +02:00
netrom
nfc nfc: nci: add flush_workqueue to prevent uaf 2022-04-20 09:19:35 +02:00
nsh
openvswitch net: openvswitch: don't send internal clone attribute to the userspace. 2022-04-15 14:18:37 +02:00
packet net/packet: fix slab-out-of-bounds access in packet_recvmsg() 2022-03-23 09:12:06 +01:00
phonet
psample
qrtr
rds
rfkill
rose
rxrpc rxrpc: fix a race in rxrpc_exit_net() 2022-04-15 14:18:38 +02:00
sched net/sched: cls_u32: fix netns refcount changes in u32_change() 2022-04-27 13:50:46 +02:00
sctp sctp: Initialize daddr on peeled off socket 2022-04-20 09:19:35 +02:00
smc net/smc: Fix NULL pointer dereference in smc_pnet_find_ib() 2022-04-20 09:19:35 +02:00
strparser
sunrpc SUNRPC: Handle low memory situations in call_status() 2022-04-15 14:18:38 +02:00
switchdev
tipc tipc: fix the timer expires after interval 100ms 2022-04-15 14:18:17 +02:00
tls net/tls: fix slab-out-of-bounds bug in decrypt_internal 2022-04-15 14:18:37 +02:00
unix
vmw_vsock vsock: remove vsock from connected table when connect is interrupted by a signal 2022-02-23 11:59:57 +01:00
wimax
wireless cfg80211: hold bss_lock while updating nontrans_list 2022-04-20 09:19:35 +02:00
x25 net/x25: Fix null-ptr-deref caused by x25_disconnect 2022-04-15 14:18:21 +02:00
xdp
xfrm xfrm: fix tunnel model fragmentation behavior 2022-04-15 14:17:56 +02:00
compat.c
Kconfig
Makefile
socket.c
sysctl_net.c