selftests/bpf: Validate UDP length in cls_redirect test
Subsystems (3)
PATCH v2 1/1 selftests/bpf: Validate UDP length in cls_redirect test
From: Suchit <[email protected]>
Add validation step to ensure that the UDP payload is long enough to contain the expected GUE and UNIGUE encapsulation headers
---
Changes since v2:
- Rebase
tools/testing/selftests/bpf/progs/test_cls_redirect.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/test_cls_redirect.c +8 -1
@@ -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 ; }
Signature · 1 line
2.49.0
Quoted 22 lines · Suchit Karunakaran
From: Suchit <[email protected]>
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 <[email protected]>---
Changes since v2:
- Rebasetools/testing/selftests/bpf/progs/test_cls_redirect.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/progs/test_cls_redirect.c +0
-0@@ -978,7 +978,14 @@ int cls_redirect(struct __sk_buff *skb)return TC_ACT_OK ;
tools/testing/selftests/bpf/progs/test_cls_redirect.c int cls_redirect(struct __sk_buff *skb) · line 987
Quoted 10 lines
tools/testing/selftests/bpf/progs/test_cls_redirect.c +7
-1} -/* 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 ; + }
I don't quite see the point.
This is a test prog. It's not supposed to be used as production code.
Quoted 2 lines
I don't quite see the point.
This is a test prog. It's not supposed to be used as production code.
It was marked as a TODO and so I sent a patch for it. I'm sorry I didn't think of the practical implications of it.