bpf: use bpf_capable() instead of CAP_SYS_ADMIN for blinding decision
Subsystems (4)
RFC PATCH 1/1 bpf: use bpf_capable() instead of CAP_SYS_ADMIN for blinding decision
I'm wodering about the cap check against CAP_SYS_ADMIN. Is it intentional to provide more security or oversight in commit 2c78ee898d8f ("bpf: Implement CAP_BPF")?
--- include/linux/filter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/filter.h +1 -1
@@ -1100,7 +1100,7 @@ static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog)return false;if (!bpf_jit_harden)return false; -if (bpf_jit_harden ==1 &&capable (CAP_SYS_ADMIN )) +if (bpf_jit_harden ==1 &&bpf_capable ())return false;return true;
Signature · 1 line
2.34.1
RFC PATCH v2 1/1 bpf: use bpf_capable() instead of CAP_SYS_ADMIN for blinding decision
The capability check can cause SELinux denial.
For example, in ptp4l, setsockopt() with the SO_ATTACH_FILTER option raises sk_attach_filter() to run a bpf program. SELinux hooks into capable() calls and performs an additional check if the task's SELinux domain has permission to "use" the given capability. ptp4l_t already has CAP_BPF granted by SELinux, so if the function used bpf_capable() as most BPF code does, there would be no change needed in selinux-policy.
---
v2: put the reasoning in the commit message
--- include/linux/filter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/filter.h +1 -1
@@ -1100,7 +1100,7 @@ static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog)return false;if (!bpf_jit_harden)return false; -if (bpf_jit_harden ==1 &&capable (CAP_SYS_ADMIN )) +if (bpf_jit_harden ==1 &&bpf_capable ())return false;return true;
Signature · 1 line
2.34.1
Serge E. Hallyn
maintainerQuoted 9 lines · Yauheni Kaliuta
The capability check can cause SELinux denial.
For example, in ptp4l,
setsockopt()with theSO_ATTACH_FILTERoption raisessk_attach_filter()to run a bpf program. SELinux hooks intocapable()calls and performs an additional check if the task's SELinux domain has permission to "use" the given capability.ptp4l_talready hasCAP_BPFgranted by SELinux, so if the function usedbpf_capable()as most BPF code does, there would be no change needed in selinux-policy.
The selinux mentions probably aren't really necessary. The more concise way to say it is that bpf_jit_blinding_enabled() should be permitted with CAP_BPF, that full CAP_SYS_ADMIN is not needed. (Assuming that that is the case)
Quoted 24 lines
Signed-off-by Yauheni Kaliuta <[email protected]>---
v2: put the reasoning in the commit message
--- include/linux/filter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/filter.h +1
-1@@ -1100,7 +1100,7 @@ static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog)return false;if (!bpf_jit_harden)return false; -if (bpf_jit_harden ==1 &&capable (CAP_SYS_ADMIN )) +if (bpf_jit_harden ==1 &&bpf_capable ())return false;return true;Signature · 1 line
2.34.1
Daniel Borkmann
maintainerQuoted 25 lines · Serge E. Hallyn
Quoted 9 lines · Yauheni Kaliuta
The capability check can cause SELinux denial.
For example, in ptp4l,
setsockopt()with theSO_ATTACH_FILTERoption raisessk_attach_filter()to run a bpf program. SELinux hooks intocapable()calls and performs an additional check if the task's SELinux domain has permission to "use" the given capability.ptp4l_talready hasCAP_BPFgranted by SELinux, so if the function usedbpf_capable()as most BPF code does, there would be no change needed in selinux-policy.The selinux mentions probably aren't really necessary. The more concise way to say it is that
bpf_jit_blinding_enabled()should be permitted withCAP_BPF, that fullCAP_SYS_ADMINis not needed. (Assuming that that is the case)Quoted 9 lines
Signed-off-by Yauheni Kaliuta <[email protected]>---
v2: put the reasoning in the commit message
--- include/linux/filter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines
include/linux/filter.h static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog) · line 1103
Quoted 10 lines
include/linux/filter.h +1
-1@@ -1100,7 +1100,7 @@ static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog)return false;if (!bpf_jit_harden)return false; -if (bpf_jit_harden ==1 &&capable (CAP_SYS_ADMIN )) +if (bpf_jit_harden ==1 &&bpf_capable ())
I think lowering this requirement is fine here. These days given unpriv eBPF is disabled by default, I see the main users for constant blinding coming from unpriv in particular via cBPF -> eBPF migration (e.g. old-style socket filters).
Quoted 3 lines
include/linux/filter.h static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog) · line 1106
Quoted 3 lines
include/linux/filter.h +0
-0return false;return true;
Please also update Documentation/admin-guide/sysctl/net.rst to clarify cap details.
Thanks,
Daniel
PATCH 1/1 bpf: use bpf_capable() instead of CAP_SYS_ADMIN for blinding decision
In reply to Yauheni KaliutaThe full CAP_SYS_ADMIN requirement for blining looks too strict nowadays. These days given unpriv eBPF is disabled by default, the main users for constant blinding coming from unpriv in particular via cBPF -> eBPF migration (e.g. old-style socket filters).
Discussion: https://lore.kernel.org/bpf/[email protected]/
--- Documentation/admin-guide/sysctl/net.rst | 3 +++ include/linux/filter.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
Documentation/admin-guide/sysctl/net.rst +3 -0
@@ -101,6 +101,9 @@ Values: - 1 - enable JIT hardening for unprivileged users only - 2 - enable JIT hardening for all users +where "privileged user" in this context means a process having +CAP_BPF or CAP_SYS_ADMIN in the root user name space. + bpf_jit_kallsyms ----------------
include/linux/filter.h +1 -1
@@ -1099,7 +1099,7 @@ static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog)return false;if (!bpf_jit_harden)return false; -if (bpf_jit_harden ==1 &&capable (CAP_SYS_ADMIN )) +if (bpf_jit_harden ==1 &&bpf_capable ())return false;return true;
Signature · 1 line
2.34.1
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 8 lines · On Mon, 5 Sep 2022 12:01:49 +0300 you wrote:
The full
CAP_SYS_ADMINrequirement for blining looks too strict nowadays. These days given unpriv eBPF is disabled by default, the main users for constant blinding coming from unpriv in particular via cBPF -> eBPF migration (e.g. old-style socket filters).Discussion: https://lore.kernel.org/bpf/[email protected]/
[...]
Here is the summary with links:
- [bpf-next] bpf: use bpf_capable() instead of CAP_SYS_ADMIN for blinding decision
https://git.kernel.org/bpf/bpf-next/c/bfeb7e399bac
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html