[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231229081409.1276386-3-menglong8.dong@gmail.com>
Date: Fri, 29 Dec 2023 16:14:09 +0800
From: Menglong Dong <menglong8.dong@...il.com>
To: andrii@...nel.org
Cc: ast@...nel.org,
daniel@...earbox.net,
martin.lau@...ux.dev,
song@...nel.org,
yonghong.song@...ux.dev,
john.fastabend@...il.com,
kpsingh@...nel.org,
sdf@...gle.com,
haoluo@...gle.com,
jolsa@...nel.org,
davem@...emloft.net,
edumazet@...gle.com,
kuba@...nel.org,
pabeni@...hat.com,
mykolal@...com,
shuah@...nel.org,
horms@...nel.org,
dhowells@...hat.com,
linyunsheng@...wei.com,
aleksander.lobakin@...el.com,
joannelkoong@...il.com,
laoar.shao@...il.com,
kuifeng@...a.com,
menglong8.dong@...il.com,
bjorn@...osinc.com,
linux-kernel@...r.kernel.org,
bpf@...r.kernel.org,
netdev@...r.kernel.org,
linux-kselftest@...r.kernel.org
Subject: [PATCH bpf-next 2/2] testcases/bpf: add testcases for skb->csum to ctx_skb.c
The testcases for read/write access of skb->csum is added to ctx_skb.c.
And the read access testing for skb->ip_summed is also added.
Signed-off-by: Menglong Dong <menglong8.dong@...il.com>
---
.../testing/selftests/bpf/verifier/ctx_skb.c | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/tools/testing/selftests/bpf/verifier/ctx_skb.c b/tools/testing/selftests/bpf/verifier/ctx_skb.c
index 0b394a7f7a2d..f15301686843 100644
--- a/tools/testing/selftests/bpf/verifier/ctx_skb.c
+++ b/tools/testing/selftests/bpf/verifier/ctx_skb.c
@@ -1193,3 +1193,46 @@
.prog_type = BPF_PROG_TYPE_SK_SKB,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
+{
+ "valid access __sk_buff csum",
+ .insns = {
+ BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+ offsetof(struct __sk_buff, csum)),
+ BPF_EXIT_INSN(),
+ },
+ .result = ACCEPT,
+ .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+},
+{
+ "valid access __sk_buff ip_summed",
+ .insns = {
+ BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+ offsetof(struct __sk_buff, ip_summed)),
+ BPF_EXIT_INSN(),
+ },
+ .result = ACCEPT,
+ .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+},
+{
+ "check skb->csum is writeable by CLS/ACT",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
+ offsetof(struct __sk_buff, csum)),
+ BPF_EXIT_INSN(),
+ },
+ .result = ACCEPT,
+ .prog_type = BPF_PROG_TYPE_SCHED_CLS,
+ .errstr = "invalid bpf_context access",
+},
+{
+ "check skb->ip_summed is not writeable",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
+ offsetof(struct __sk_buff, csum)),
+ BPF_EXIT_INSN(),
+ },
+ .result = REJECT,
+ .errstr = "invalid bpf_context access",
+},
--
2.39.2
Powered by blists - more mailing lists