When a bpf prog is loaded by a proccess running in a container (with memcg),
only sys admin has privilege not to charge bpf prog memory into this
container while account it to root memcg only.
Signed-off-by: Yafang Shao <redacted>
---
kernel/bpf/syscall.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 346f3df9fa1d..ecc5de216f50 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2234,6 +2234,9 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr)
BPF_F_PROG_NO_CHARGE))
return -EINVAL;
+ if (attr->prog_flags & BPF_F_PROG_NO_CHARGE && !capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) &&
(attr->prog_flags & BPF_F_ANY_ALIGNMENT) &&
!bpf_capable())
--
2.17.1