Hi, all!
In the linux-next tree, next-20241108, coccinelle found an error.
In the line 617, ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(local_gopt));
In the line 678, ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(gopt));
when
592 struct local_geneve_opt local_gopt;
593 struct geneve_opt *gopt = (struct geneve_opt *) &local_gopt;
and
652 struct local_geneve_opt local_gopt;
653 struct geneve_opt *gopt = (struct geneve_opt *) &local_gopt;
So, in all other call to bpf_skb_set_tunnel_opt(), the third parameter is the size of
the struct, not the size of the pointer:
./tools/testing/selftests/bpf/progs/test_tunnel_kern.c:193: ret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md));
./tools/testing/selftests/bpf/progs/test_tunnel_kern.c:273: ret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md));
./tools/testing/selftests/bpf/progs/test_tunnel_kern.c:349: ret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md));
./tools/testing/selftests/bpf/progs/test_tunnel_kern.c:388: ret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md));
./tools/testing/selftests/bpf/progs/test_tunnel_kern.c:617: ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(local_gopt));
./tools/testing/selftests/bpf/progs/test_tunnel_kern.c:678: ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(gopt));
===========================================
587 SEC("tc")
588 int geneve_set_tunnel(struct __sk_buff *skb)
589 {
590 int ret;
591 struct bpf_tunnel_key key;
592 struct local_geneve_opt local_gopt;
593 struct geneve_opt *gopt = (struct geneve_opt *) &local_gopt;
594
595 __builtin_memset(&key, 0x0, sizeof(key));
596 key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */
597 key.tunnel_id = 2;
598 key.tunnel_tos = 0;
599 key.tunnel_ttl = 64;
600
601 __builtin_memset(gopt, 0x0, sizeof(local_gopt));
602 gopt->opt_class = bpf_htons(0x102); /* Open Virtual Networking (OVN) */
603 gopt->type = 0x08;
604 gopt->r1 = 0;
605 gopt->r2 = 0;
606 gopt->r3 = 0;
607 gopt->length = 2; /* 4-byte multiple */
608 *(int *) &gopt->opt_data = bpf_htonl(0xdeadbeef);
609
610 ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key),
611 BPF_F_ZERO_CSUM_TX);
612 if (ret < 0) {
613 log_err(ret);
614 return TC_ACT_SHOT;
615 }
616
617 → ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(local_gopt));
618 if (ret < 0) {
619 log_err(ret);
620 return TC_ACT_SHOT;
621 }
622
623 return TC_ACT_OK;
624 }
648 SEC("tc")
649 int ip6geneve_set_tunnel(struct __sk_buff *skb)
650 {
651 struct bpf_tunnel_key key;
652 struct local_geneve_opt local_gopt;
653 struct geneve_opt *gopt = (struct geneve_opt *) &local_gopt;
654 int ret;
655
656 __builtin_memset(&key, 0x0, sizeof(key));
657 key.remote_ipv6[3] = bpf_htonl(0x11); /* ::11 */
658 key.tunnel_id = 22;
659 key.tunnel_tos = 0;
660 key.tunnel_ttl = 64;
661
662 ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key),
663 BPF_F_TUNINFO_IPV6);
664 if (ret < 0) {
665 log_err(ret);
666 return TC_ACT_SHOT;
667 }
668
669 __builtin_memset(gopt, 0x0, sizeof(local_gopt));
670 gopt->opt_class = bpf_htons(0x102); /* Open Virtual Networking (OVN) */
671 gopt->type = 0x08;
672 gopt->r1 = 0;
673 gopt->r2 = 0;
674 gopt->r3 = 0;
675 gopt->length = 2; /* 4-byte multiple */
676 *(int *) &gopt->opt_data = bpf_htonl(0xfeedbeef);
677
678 → ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(gopt));
679 if (ret < 0) {
680 log_err(ret);
681 return TC_ACT_SHOT;
682 }
683
684 return TC_ACT_OK;
685 }
SOLUTION:
Fixes: 5ddafcc377f98 ("selftests/bpf: Fix a few tests for GCC related warnings.")
------------------
diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
index 32127f1cd687..b53d367451b2 100644
--- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
@@ -675,7 +675,7 @@ int ip6geneve_set_tunnel(struct __sk_buff *skb)
gopt->length = 2; /* 4-byte multiple */
*(int *) &gopt->opt_data = bpf_htonl(0xfeedbeef);
- ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(gopt));
+ ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(local_gopt));
if (ret < 0) {
log_err(ret);
return TC_ACT_SHOT;
--
Best regards,
MT
© 2016 - 2024 Red Hat, Inc.