OSDN Git Service

bpf: Pin the start cgroup in cgroup_iter_seq_init()
authorHou Tao <houtao1@huawei.com>
Mon, 21 Nov 2022 07:34:38 +0000 (15:34 +0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 21 Nov 2022 16:40:42 +0000 (17:40 +0100)
commit1a5160d4d8fe63ba4964cfff4a85831b6af75f2d
tree1d025ef563a411d8cf432ae492f239dd9bf77aec
parentceb35b666d42c2e91b1f94aeca95bb5eb0943268
bpf: Pin the start cgroup in cgroup_iter_seq_init()

bpf_iter_attach_cgroup() has already acquired an extra reference for the
start cgroup, but the reference may be released if the iterator link fd
is closed after the creation of iterator fd, and it may lead to
user-after-free problem when reading the iterator fd.

An alternative fix is pinning iterator link when opening iterator,
but it will make iterator link being still visible after the close of
iterator link fd and the behavior is different with other link types, so
just fixing it by acquiring another reference for the start cgroup.

Fixes: d4ccaf58a847 ("bpf: Introduce cgroup iter")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20221121073440.1828292-2-houtao@huaweicloud.com
kernel/bpf/cgroup_iter.c