bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 bpf 1/2] bpf: verifier: check for packet data access based on target prog
@ 2020-08-21  0:28 Udip Pant
  2020-08-21  0:28 ` [PATCH v2 bpf 2/2] selftests/bpf: add test for freplace program with write access Udip Pant
  2020-08-21  6:13 ` [PATCH v2 bpf 1/2] bpf: verifier: check for packet data access based on target prog Yonghong Song
  0 siblings, 2 replies; 8+ messages in thread
From: Udip Pant @ 2020-08-21  0:28 UTC (permalink / raw)
  To: Udip Pant, Alexei Starovoitov, Martin KaFai Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, David S . Miller
  Cc: netdev, bpf, linux-kernel

While using dynamic program extension (of type BPF_PROG_TYPE_EXT), we
need to check the program type of the target program to grant the read /
write access to the packet data.

The BPF_PROG_TYPE_EXT type can be used to extend types such as XDP, SKB
and others. Since the BPF_PROG_TYPE_EXT program type on itself is just a
placeholder for those, we need this extended check for those target
programs to actually work while using this option.

Tested this with a freplace xdp program. Without this patch, the
verifier fails with error 'cannot write into packet'.

Signed-off-by: Udip Pant <udippant@fb.com>
---
 kernel/bpf/verifier.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index ef938f17b944..4d7604430994 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2629,7 +2629,11 @@ static bool may_access_direct_pkt_data(struct bpf_verifier_env *env,
 				       const struct bpf_call_arg_meta *meta,
 				       enum bpf_access_type t)
 {
-	switch (env->prog->type) {
+	struct bpf_prog *prog = env->prog;
+	enum bpf_prog_type prog_type = prog->aux->linked_prog ?
+	      prog->aux->linked_prog->type : prog->type;
+
+	switch (prog_type) {
 	/* Program types only with direct read access go here! */
 	case BPF_PROG_TYPE_LWT_IN:
 	case BPF_PROG_TYPE_LWT_OUT:
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-08-21 21:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21  0:28 [PATCH v2 bpf 1/2] bpf: verifier: check for packet data access based on target prog Udip Pant
2020-08-21  0:28 ` [PATCH v2 bpf 2/2] selftests/bpf: add test for freplace program with write access Udip Pant
2020-08-21  6:19   ` Yonghong Song
2020-08-21  6:13 ` [PATCH v2 bpf 1/2] bpf: verifier: check for packet data access based on target prog Yonghong Song
2020-08-21  6:17   ` Yonghong Song
2020-08-21 19:07     ` Udip Pant
2020-08-21 20:53       ` Yonghong Song
2020-08-21 21:05         ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).