From: Suchit Karunakaran <suchitkarunakaran@gmail.com>
To: andrii@kernel.org, eddyz87@gmail.com, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
mykolal@fb.com, ast@kernel.org, daniel@iogearbox.net
Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
haoluo@google.com, jolsa@kernel.org, shuah@kernel.org,
Suchit <suchitkarunakaran@gmail.com>
Subject: [PATCH v2] selftests/bpf: Validate UDP length in cls_redirect test
Date: Tue, 3 Jun 2025 10:58:05 +0530 [thread overview]
Message-ID: <20250603052805.13042-1-suchitkarunakaran@gmail.com> (raw)
From: Suchit <suchitkarunakaran@gmail.com>
Add validation step to ensure that the UDP payload is
long enough to contain the expected GUE and UNIGUE encapsulation
headers
Signed-off-by: Suchit <suchitkarunakaran@gmail.com>
---
Changes since v2:
- Rebase
tools/testing/selftests/bpf/progs/test_cls_redirect.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/progs/test_cls_redirect.c b/tools/testing/selftests/bpf/progs/test_cls_redirect.c
index f344c6835e84..c1d2eaee2e77 100644
--- a/tools/testing/selftests/bpf/progs/test_cls_redirect.c
+++ b/tools/testing/selftests/bpf/progs/test_cls_redirect.c
@@ -978,7 +978,14 @@ int cls_redirect(struct __sk_buff *skb)
return TC_ACT_OK;
}
- /* TODO Check UDP length? */
+ uint16_t udp_len = bpf_ntohs(encap->udp.len);
+ uint16_t min_encap_len = sizeof(encap->udp) + sizeof(encap->gue) + sizeof(encap->unigue);
+
+ if (udp_len < min_encap_len) {
+ metrics->errors_total_malformed_encapsulation++;
+ return TC_ACT_SHOT;
+ }
+
if (encap->udp.dest != ENCAPSULATION_PORT) {
return TC_ACT_OK;
}
--
2.49.0
next reply other threads:[~2025-06-03 5:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-03 5:28 Suchit Karunakaran [this message]
2025-06-06 18:33 ` [PATCH v2] selftests/bpf: Validate UDP length in cls_redirect test Alexei Starovoitov
2025-06-07 15:54 ` Suchit K
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=20250603052805.13042-1-suchitkarunakaran@gmail.com \
--to=suchitkarunakaran@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--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;
as well as URLs for NNTP newsgroup(s).