From patchwork Mon Nov 7 07:42:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 13033849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B83DC4332F for ; Mon, 7 Nov 2022 07:18:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231437AbiKGHSS (ORCPT ); Mon, 7 Nov 2022 02:18:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231403AbiKGHR5 (ORCPT ); Mon, 7 Nov 2022 02:17:57 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DD8615738 for ; Sun, 6 Nov 2022 23:16:44 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4N5Mwj45r3z4f3mVw for ; Mon, 7 Nov 2022 15:16:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgC329jWsGhjUEl6AA--.47516S4; Mon, 07 Nov 2022 15:16:40 +0800 (CST) From: Hou Tao To: bpf@vger.kernel.org, Hao Luo , Alexei Starovoitov , Stanislav Fomichev Cc: Martin KaFai Lau , Andrii Nakryiko , Song Liu , Yonghong Song , Daniel Borkmann , KP Singh , Jiri Olsa , John Fastabend , Tejun Heo , houtao1@huawei.com Subject: [PATCH bpf 0/3] Pin the start cgroup for cgroup iterator Date: Mon, 7 Nov 2022 15:42:19 +0800 Message-Id: <20221107074222.1323017-1-houtao@huaweic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0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07UWE__UUUUU= X-CM-SenderInfo: xkrx3t3r6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Hou Tao Hi, The patchset tries to fix the potential use-after-free problem in cgroup iterator. The problem is similar with the UAF problem fixed in map iterator and the fixes is also similar: pinning the iterated resource in .init_seq_private() and unpinning in .fini_seq_private(). Also adding a test to demonstrate the problem. Not sure whether or not it will be helpful to add some comments for .init_seq_private() to state that the implementation of .init_seq_private() should not depend on iterator link to guarantee the liveness of iterated object. Comments are always welcome. Hou Tao (3): bpf: Pin the start cgroup in cgroup_iter_seq_init() selftests/bpf: Add cgroup helper remove_cgroup() selftests/bpf: Add test for cgroup iterator on a dead cgroup kernel/bpf/cgroup_iter.c | 14 ++++ tools/testing/selftests/bpf/cgroup_helpers.c | 19 +++++ tools/testing/selftests/bpf/cgroup_helpers.h | 1 + .../selftests/bpf/prog_tests/cgroup_iter.c | 78 +++++++++++++++++++ 4 files changed, 112 insertions(+)