From: Mirsad Todorovac <mtodorovac69@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Mykola Lysenko <mykolal@fb.com>,
Shuah Khan <shuah@kernel.org>, Daniel Xu <dxu@dxuuu.xyz>,
Antony Antony <antony.antony@secunet.com>,
Cupertino Miranda <cupertino.miranda@oracle.com>,
Artem Savkov <asavkov@redhat.com>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PROBLEM] selftests/bpf/progs/test_tunnel_kern.c: 678: 41-47: ERROR: application of sizeof to pointer
Date: Sat, 9 Nov 2024 19:53:32 +0100 [thread overview]
Message-ID: <56998f22-004c-4629-bd8b-8b494290f787@gmail.com> (raw)
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
reply other threads:[~2024-11-09 18:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56998f22-004c-4629-bd8b-8b494290f787@gmail.com \
--to=mtodorovac69@gmail.com \
--cc=andrii@kernel.org \
--cc=antony.antony@secunet.com \
--cc=asavkov@redhat.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cupertino.miranda@oracle.com \
--cc=daniel@iogearbox.net \
--cc=dxu@dxuuu.xyz \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox