[PATCH 10/14] bpf: Only sys admin can set no charge flag for bpf prog

From
Yafang Shao <hidden>
Date
2022-03-19 17:31:04
Also in
bpf, linux-kselftest
Reply to
Yafang Shao, 2022-03-19
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
Thread (19 messages) 19 messages, 2 authors, last reply 2022-03-23
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help