diff options
author | Cong Wang <[email protected]> | 2020-07-02 11:52:56 -0700 |
---|---|---|
committer | David S. Miller <[email protected]> | 2020-07-07 13:34:11 -0700 |
commit | ad0f75e5f57ccbceec13274e1e242f2b5a6397ed (patch) | |
tree | 0731a3f8fd336dcc5e7724aa5fac075fb842639c /scripts/gen_compile_commands.py | |
parent | aea23c323d89836bcdcee67e49def997ffca043b (diff) |
cgroup: fix cgroup_sk_alloc() for sk_clone_lock()
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
d979a39d7242 ("cgroup: duplicate cgroup reference when cloning sockets")
tried to fix it but not compeletely. It seems not easy to trigger until
the recent commit 090e28b229af
("netprio_cgroup: Fix unlimited memory leak of v2 cgroups") was merged.
Fixes: bd1060a1d671 ("sock, cgroup: add sock->sk_cgroup")
Reported-by: Cameron Berkenpas <[email protected]>
Reported-by: Peter Geis <[email protected]>
Reported-by: Lu Fengqi <[email protected]>
Reported-by: Daniƫl Sonck <[email protected]>
Reported-by: Zhang Qiang <[email protected]>
Tested-by: Cameron Berkenpas <[email protected]>
Tested-by: Peter Geis <[email protected]>
Tested-by: Thomas Lamprecht <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: Zefan Li <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Roman Gushchin <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Diffstat (limited to 'scripts/gen_compile_commands.py')
0 files changed, 0 insertions, 0 deletions