From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379736; b=UfwsYh1ZI8DJe8Oh5uMRAzleAuBw2hzT/ydy6FRa7ta9Dpo9mFc1eJXdj5W2PMpdBrmk r3UC8FeTkkTn8qxzZuT1CoiaSIlYhEab1/aoEo7YynPdkt/K4xmEwH3FOEBuooelT8pi+ t3GSMbDfEQGv5GLTW4IBpWxWwnR7c01saeIqNzcNgIIU84HFGEpj/ZXvCp8F7yHXUX+en mjV/U55S+54xZ0Sw6TRMcf1zUOiFmEocmres7OA3Aa5SUj/i1orT6/d3+NFgVpxTpRZEL q6rOgQVEgeO7CrraNfU1VnZvvyprUZMdjaSG8hH3R0eAzCVSj3zfTEGbtR1GHTGJ7/A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379736; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=qCSHRaoQHjqZIN0Fy6Fg0rwwd15KwyXU/oddElsyMWI=; b=U73feD46VCfNsYoIwlXM6EiFw30cxYeXfpFg54o3Hy0KWwcDSvzu6XiIwwlJaGmJOv+q e9xy2XJCZJiVIFNYkn2K37WRWDEay+DA7n3l8I8QOtQ5RPBcGXbCCsK/3kXDSs/mASVhE 93TQDHezqivrU3irZIKu7YzwgXZkkU4tvgbS2OuSUWuFcEKT+HKu0bhsDnB+DTrQSqt5L 7Q7GQNWt3dW/wdLDUqDvOWHL0tw5nFXw06eA5VDi9S4swRMXX1bEJliUpWF/4rgvG6USM /3qPG9ZjNqdGlQLgE/bzAbp4TIopwFSH09qXuTdOY/KagkYBGO+5NKU5hugIlH2CFuw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=E4tT2y5a; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 504E2606A322; Fri, 4 Dec 2026 10:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=E4tT2y5a Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3D5E1F000C2; Fri, 4 Dec 2026 10:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379736; bh=qCSHRaoQHjqZIN0Fy6Fg0rwwd15KwyXU/oddElsyMWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E4tT2y5aU4IE5aDR564yqogKOMW0rjstJgtOR+DQltn292qDhsqV8C4eYliTorEr/ AhMnw2lTndy1kiVK8fM+x9K+U/f0DH27Whhn4Dopi3Tp7K2MMqfqbSFW7+aIgpfYcd fkAHdcFcCjaa1OV28QK1nvL7stathtX8Ibn59aog= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.6 0065/1167] bpf: Require prog fd or capability for cgroup detach Date: Fri, 4 Dec 2026 18:51:32 +0900 Message-ID: <20261204100703.775124467@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit 2962329f7c86fc51c177d4049c0f15a95ebd270c ] Since the commit below a cgroup prog detach does not require CAP_NET_ADMIN. The fd of the attached prog gives the permission instead. But the detach requires this fd only with BPF_F_ALLOW_MULTI. Without this flag a cgroup has only one prog per attach type. Then find_detach_entry() returns this prog and does not compare it with the prog of the caller. Thus the kernel detaches this prog for a caller with neither the fd nor a capability. Compare the two progs. If they are different, require CAP_NET_ADMIN or CAP_SYS_ADMIN in the initial user namespace. The error is -EPERM. A detach from tcx or netkit without a prog fd already requires these capabilities. With BPF_F_ALLOW_MULTI nothing changes. Without these capabilities, a caller of bpf_prog_detach() of libbpf must now use bpf_prog_detach2() with the fd of the attached prog. Fixes: 2c78ee898d8f ("bpf: Implement CAP_BPF") Signed-off-by: Chris Mason Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261101190535.1454146-14-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/cgroup.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 433ecc6579b1a..1fb1831d102ac 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -954,9 +954,14 @@ static struct bpf_prog_list *find_detach_entry(struct hlist_head *progs, return ERR_PTR(-ENOENT); /* to maintain backward compatibility NONE and OVERRIDE cgroups - * allow detaching with invalid FD (prog==NULL) in legacy mode + * allow detaching with invalid FD (prog==NULL) in legacy mode. + * Without the FD of the attached program the caller needs + * CAP_NET_ADMIN or CAP_SYS_ADMIN in the initial user namespace. */ - return hlist_entry(progs->first, typeof(*pl), node); + pl = hlist_entry(progs->first, typeof(*pl), node); + if (pl->prog != prog && !bpf_net_capable()) + return ERR_PTR(-EPERM); + return pl; } if (!prog && !link) -- 2.53.0