From f47eca8860d4096df73648ca237463b815c5bc69 Mon Sep 17 00:00:00 2001 From: Mohammad Javad Pooladkhay Date: Sat, 25 Nov 2023 01:07:25 +0000 Subject: [PATCH] integration-test: add tc_name_limit_exceeded This test is to ensure that attaching a tc program that has a name longer than the maximum allowed length by the kernel will fail. Signed-off-by: Mohammad Javad Pooladkhay --- test/integration-ebpf/Cargo.toml | 4 +++ .../src/tc_name_limit_exceeded.rs | 25 +++++++++++++++++++ test/integration-test/src/lib.rs | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 test/integration-ebpf/src/tc_name_limit_exceeded.rs diff --git a/test/integration-ebpf/Cargo.toml b/test/integration-ebpf/Cargo.toml index eb6615b2..43dae8ac 100644 --- a/test/integration-ebpf/Cargo.toml +++ b/test/integration-ebpf/Cargo.toml @@ -48,6 +48,10 @@ path = "src/two_progs.rs" name = "tc_name_limit" path = "src/tc_name_limit.rs" +[[bin]] +name = "tc_name_limit_exceeded" +path = "src/tc_name_limit_exceeded.rs" + [[bin]] name = "redirect" path = "src/redirect.rs" diff --git a/test/integration-ebpf/src/tc_name_limit_exceeded.rs b/test/integration-ebpf/src/tc_name_limit_exceeded.rs new file mode 100644 index 00000000..ade769f5 --- /dev/null +++ b/test/integration-ebpf/src/tc_name_limit_exceeded.rs @@ -0,0 +1,25 @@ +#![no_std] +#![no_main] + +use aya_bpf::{macros::classifier, programs::TcContext}; + +/* +A function with a 257-byte-long name (all 'a's) to be used as the name of +the ebpf program. This name must match the name passed to userspace side +of the program (i.e. test/integration-test/src/tests/load.rs). + +256 is the maximum length allowed by the kernel, so this test should fail. +https://github.com/torvalds/linux/blob/02aee814/net/sched/cls_bpf.c#L28 +*/ +#[classifier] +pub fn aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( + _ctx: TcContext, +) -> i32 { + 0 +} + +#[cfg(not(test))] +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} diff --git a/test/integration-test/src/lib.rs b/test/integration-test/src/lib.rs index 354c95a8..17175a4e 100644 --- a/test/integration-test/src/lib.rs +++ b/test/integration-test/src/lib.rs @@ -15,6 +15,8 @@ pub const MAP_TEST: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/ma pub const NAME_TEST: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/name_test")); pub const TC_NAME_LIMIT_TEST: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/tc_name_limit")); +pub const TC_NAME_LIMIT_EXCEEDED_TEST: &[u8] = + include_bytes_aligned!(concat!(env!("OUT_DIR"), "/tc_name_limit_exceeded")); pub const PASS: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/pass")); pub const TEST: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/test")); pub const RELOCATIONS: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/relocations"));