linux-stable/net
Cong Wang 82fd2138a5 cgroup: fix cgroup_sk_alloc() for sk_clone_lock()
[ Upstream commit ad0f75e5f5 ]

When we clone a socket in sk_clone_lock(), its sk_cgrp_data is
copied, so the cgroup refcnt must be taken too. And, unlike the
sk_alloc() path, sock_update_netprioidx() is not called here.
Therefore, it is safe and necessary to grab the cgroup refcnt
even when cgroup_sk_alloc is disabled.

sk_clone_lock() is in BH context anyway, the in_interrupt()
would terminate this function if called there. And for sk_alloc()
skcd->val is always zero. So it's safe to factor out the code
to make it more readable.

The global variable 'cgroup_sk_alloc_disabled' is used to determine
whether to take these reference counts. It is impossible to make
the reference counting correct unless we save this bit of information
in skcd->val. So, add a new bit there to record whether the socket
has already taken the reference counts. This obviously relies on
kmalloc() to align cgroup pointers to at least 4 bytes,
ARCH_KMALLOC_MINALIGN is certainly larger than that.

This bug seems to be introduced since the beginning, commit
d979a39d72 ("cgroup: duplicate cgroup reference when cloning sockets")
tried to fix it but not compeletely. It seems not easy to trigger until
the recent commit 090e28b229
("netprio_cgroup: Fix unlimited memory leak of v2 cgroups") was merged.

Fixes: bd1060a1d6 ("sock, cgroup: add sock->sk_cgroup")
Reported-by: Cameron Berkenpas <cam@neo-zeon.de>
Reported-by: Peter Geis <pgwipeout@gmail.com>
Reported-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Reported-by: Daniël Sonck <dsonck92@gmail.com>
Reported-by: Zhang Qiang <qiang.zhang@windriver.com>
Tested-by: Cameron Berkenpas <cam@neo-zeon.de>
Tested-by: Peter Geis <pgwipeout@gmail.com>
Tested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Zefan Li <lizefan@huawei.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Roman Gushchin <guro@fb.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-07-22 09:22:21 +02:00
..
6lowpan 6lowpan: Off by one handling ->nexthdr 2020-01-27 14:46:30 +01:00
9p 9p/virtio: Add cleanup path in p9_virtio_init 2019-07-31 07:28:39 +02:00
802
8021q vlan: fix memory leak in vlan_dev_set_egress_priority 2020-01-12 12:12:09 +01:00
appletalk appletalk: Set error code if register_snap_client failed 2019-12-17 20:38:59 +01:00
atm net: use skb_queue_empty_lockless() in poll() handlers 2019-11-10 11:25:34 +01:00
ax25 ax25: fix setsockopt(SO_BINDTODEVICE) 2020-06-03 08:17:31 +02:00
batman-adv batman-adv: Fix refcnt leak in batadv_v_ogm_process 2020-05-20 08:16:59 +02:00
bluetooth Bluetooth: Add SCO fallback for invalid LMP parameters error 2020-06-20 10:25:08 +02:00
bpf
bridge net: bridge: enfore alignment for ethernet address 2020-06-30 15:37:58 -04:00
caif net: use skb_queue_empty_lockless() in poll() handlers 2019-11-10 11:25:34 +01:00
can can: af_can: Fix error path of can_init() 2019-07-21 09:04:22 +02:00
ceph libceph: ignore pool overlay and cache logic on redirects 2020-06-03 08:18:02 +02:00
core cgroup: fix cgroup_sk_alloc() for sk_clone_lock() 2020-07-22 09:22:21 +02:00
dcb
dccp net: ipv6: add net argument to ip6_dst_lookup_flow 2020-05-20 08:17:02 +02:00
decnet net: add bool confirm_neigh parameter for dst_ops.update_pmtu 2020-01-04 14:00:14 +01:00
dns_resolver KEYS: Don't write out to userspace while holding key semaphore 2020-04-24 08:01:25 +02:00
dsa net: dsa: Fix duplicate frames flooded by learning 2020-04-02 16:34:24 +02:00
ethernet net: add annotations on hh->hh_len lockless accesses 2020-01-09 10:17:59 +01:00
hsr hsr: check protocol version in hsr_newlink() 2020-04-24 08:00:52 +02:00
ieee802154 nl802154: add missing attribute validation for dev_type 2020-03-20 10:54:10 +01:00
ife
ipv4 tcp: md5: do not send silly options in SYNCOOKIES 2020-07-22 09:22:20 +02:00
ipv6 ip6_gre: fix use-after-free in ip6gre_tunnel_lookup() 2020-06-30 15:38:00 -04:00
ipx
iucv net/af_iucv: always register net_device notifier 2020-01-27 14:46:38 +01:00
kcm kcm: switch order of device registration to fix a crash 2019-04-17 08:37:45 +02:00
key xfrm: clean up xfrm protocol checks 2019-09-16 08:20:44 +02:00
l2tp l2tp: remove skb_dst_set() from l2tp_xmit_skb() 2020-07-22 09:22:19 +02:00
l3mdev
lapb lapb: fixed leak of control-blocks. 2019-06-22 08:16:14 +02:00
llc llc: make sure applications use ARPHRD_ETHER 2020-07-22 09:22:20 +02:00
mac80211 mac80211: mesh: fix discovery timer re-arming issue / crash 2020-06-03 08:18:04 +02:00
mac802154
mpls net: ipv6_stub: use ip6_dst_lookup_flow instead of ip6_dst_lookup 2020-05-20 08:17:02 +02:00
ncsi
netfilter netfilter: ipset: fix unaligned atomic access 2020-06-30 15:38:05 -04:00
netlabel netlabel: cope with NULL catmap 2020-05-20 08:17:12 +02:00
netlink genetlink: remove genl_bind 2020-07-22 09:22:19 +02:00
netrom net: netrom: Fix potential nr_neigh refcnt leak in nr_add_node 2020-05-02 17:24:17 +02:00
nfc nfc: add missing attribute validation for vendor subcommand 2020-03-20 10:54:12 +01:00
nsh
openvswitch openvswitch: support asymmetric conntrack 2019-12-21 10:47:34 +01:00
packet net/packet: tpacket_rcv: avoid a producer race condition 2020-04-02 16:34:24 +02:00
phonet net: use skb_queue_empty_lockless() in poll() handlers 2019-11-10 11:25:34 +01:00
psample net: psample: fix skb_over_panic 2019-12-05 15:38:15 +01:00
qrtr net: qrtr: Fix passing invalid reference to qrtr_local_enqueue() 2020-06-03 08:17:38 +02:00
rds net/rds: Fix 'ib_evt_handler_call' element in 'rds_ib_stat_names' 2020-01-27 14:46:47 +01:00
rfkill rfkill: Fix incorrect check to avoid NULL pointer dereference 2020-01-12 12:11:57 +01:00
rose net/rose: fix unbound loop in rose_loopback_timer() 2019-05-02 09:40:34 +02:00
rxrpc rxrpc: Fix handling of rwind from an ACK packet 2020-06-30 15:38:04 -04:00
sched net_sched: fix a memory leak in atm_tc_init() 2020-07-22 09:22:20 +02:00
sctp sctp: Don't advertise IPv4 addresses if ipv6only is set on the socket 2020-06-30 15:37:59 -04:00
smc net/smc: check for valid ib_client_data 2020-03-20 10:54:20 +01:00
strparser
sunrpc SUNRPC: Properly set the @subbuf parameter of xdr_buf_subsegment() 2020-06-30 15:38:09 -04:00
switchdev
tipc net: ipv6_stub: use ip6_dst_lookup_flow instead of ip6_dst_lookup 2020-05-20 08:17:02 +02:00
tls
unix af_unix: add compat_ioctl support 2020-01-17 19:45:49 +01:00
vmw_vsock vsock: fix timeout in vsock_accept() 2020-06-11 09:22:59 +02:00
wimax
wireless cfg80211: check reg_rule for NULL in handle_channel_custom() 2020-03-20 10:54:24 +01:00
x25 net/x25: Fix x25_neigh refcnt leak when receiving frame 2020-05-02 17:24:17 +02:00
xfrm xfrm: fix a NULL-ptr deref in xfrm_local_error 2020-06-03 08:18:06 +02:00
compat.c
Kconfig
Makefile
socket.c compat_ioctl: handle SIOCOUTQNSD 2020-01-17 19:45:49 +01:00
sysctl_net.c