From: Greg KH <greg@kroah.com>
To: Connor O'Brien <connor.obrien@crowdstrike.com>
Cc: stable@vger.kernel.org, martin.kelly@crowdstrike.com,
Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH 1/2] bpf, cgroups: Fix cgroup v2 fallback on v1/v2 mixed mode
Date: Thu, 5 Sep 2024 09:42:54 +0200 [thread overview]
Message-ID: <2024090546-surcharge-eternal-45fe@gregkh> (raw)
In-Reply-To: <20240904012851.58167-1-connor.obrien@crowdstrike.com>
On Tue, Sep 03, 2024 at 06:28:50PM -0700, Connor O'Brien wrote:
> From: Daniel Borkmann <daniel@iogearbox.net>
>
> commit 8520e224f547cd070c7c8f97b1fc6d58cff7ccaa upstream.
>
> Fix cgroup v1 interference when non-root cgroup v2 BPF programs are used.
> Back in the days, commit bd1060a1d671 ("sock, cgroup: add sock->sk_cgroup")
> embedded per-socket cgroup information into sock->sk_cgrp_data and in order
> to save 8 bytes in struct sock made both mutually exclusive, that is, when
> cgroup v1 socket tagging (e.g. net_cls/net_prio) is used, then cgroup v2
> falls back to the root cgroup in sock_cgroup_ptr() (&cgrp_dfl_root.cgrp).
>
> The assumption made was "there is no reason to mix the two and this is in line
> with how legacy and v2 compatibility is handled" as stated in bd1060a1d671.
> However, with Kubernetes more widely supporting cgroups v2 as well nowadays,
> this assumption no longer holds, and the possibility of the v1/v2 mixed mode
> with the v2 root fallback being hit becomes a real security issue.
>
> Many of the cgroup v2 BPF programs are also used for policy enforcement, just
> to pick _one_ example, that is, to programmatically deny socket related system
> calls like connect(2) or bind(2). A v2 root fallback would implicitly cause
> a policy bypass for the affected Pods.
>
> In production environments, we have recently seen this case due to various
> circumstances: i) a different 3rd party agent and/or ii) a container runtime
> such as [0] in the user's environment configuring legacy cgroup v1 net_cls
> tags, which triggered implicitly mentioned root fallback. Another case is
> Kubernetes projects like kind [1] which create Kubernetes nodes in a container
> and also add cgroup namespaces to the mix, meaning programs which are attached
> to the cgroup v2 root of the cgroup namespace get attached to a non-root
> cgroup v2 path from init namespace point of view. And the latter's root is
> out of reach for agents on a kind Kubernetes node to configure. Meaning, any
> entity on the node setting cgroup v1 net_cls tag will trigger the bypass
> despite cgroup v2 BPF programs attached to the namespace root.
>
> Generally, this mutual exclusiveness does not hold anymore in today's user
> environments and makes cgroup v2 usage from BPF side fragile and unreliable.
> This fix adds proper struct cgroup pointer for the cgroup v2 case to struct
> sock_cgroup_data in order to address these issues; this implicitly also fixes
> the tradeoffs being made back then with regards to races and refcount leaks
> as stated in bd1060a1d671, and removes the fallback, so that cgroup v2 BPF
> programs always operate as expected.
>
> [0] https://github.com/nestybox/sysbox/
> [1] https://kind.sigs.k8s.io/
>
> Fixes: bd1060a1d671 ("sock, cgroup: add sock->sk_cgroup")
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> Acked-by: Stanislav Fomichev <sdf@google.com>
> Acked-by: Tejun Heo <tj@kernel.org>
> Link: https://lore.kernel.org/bpf/20210913230759.2313-1-daniel@iogearbox.net
> [resolve trivial conflicts]
> Signed-off-by: Connor O'Brien <connor.obrien@crowdstrike.com>
> ---
>
> Hello,
>
> Requesting that these patches be applied to 5.10-stable. Tested to confirm that
> the cgroup_v1v2 bpf selftest for this issue passes on 5.10 with the first patch
> applied and fails without it. The syzkaller crash referenced in the second patch
> reproduces on 5.10 after applying just the first patch, but not with both
> patches applied.
>
> Conflicts were due to unrelated changes to the surrounding context; the actual
> code change remains the same as in the upstream patch.
Both now queued up, thanks.
greg k-h
prev parent reply other threads:[~2024-09-05 7:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-04 1:28 [PATCH 1/2] bpf, cgroups: Fix cgroup v2 fallback on v1/v2 mixed mode Connor O'Brien
2024-09-04 1:28 ` [PATCH 2/2] bpf, cgroup: Assign cgroup in cgroup_sk_alloc when called from interrupt Connor O'Brien
2024-09-05 7:42 ` Greg KH [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2024090546-surcharge-eternal-45fe@gregkh \
--to=greg@kroah.com \
--cc=connor.obrien@crowdstrike.com \
--cc=daniel@iogearbox.net \
--cc=martin.kelly@crowdstrike.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox