test: Reproduce relocation bug

Users have reported issues with programs failing the verifier when they
are attempting to read or write to variables that the compiler places in
the .bss section. Add a test that places variables in each section and
exercises read and write operations on them.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/1073/head
Dave Tucker 3 months ago
parent f9b34fe76f
commit adf16e2102

@ -0,0 +1,21 @@
// clang-format off
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
// clang-format on
volatile unsigned int key1 = 0; // .bss
volatile unsigned int key2 = 1; // .data
volatile const unsigned int key3 = 2; // .rodata
SEC("xdp")
int variables_reloc(struct xdp_md *ctx) {
if (key1 == 0 && key2 != 1 && key3 != 2) {
key1 += 1;
key2 += 1;
return XDP_DROP;
} else {
return XDP_PASS;
}
}
char _license[] SEC("license") = "GPL";

@ -71,6 +71,7 @@ fn main() {
("multimap-btf.bpf.c", false),
("reloc.bpf.c", true),
("text_64_64_reloc.c", false),
("variables_reloc.bpf.c", false),
];
if build_integration_bpf {

@ -9,6 +9,8 @@ pub const RELOC_BTF: &[u8] =
include_bytes_aligned!(concat!(env!("OUT_DIR"), "/reloc.bpf.target.o"));
pub const TEXT_64_64_RELOC: &[u8] =
include_bytes_aligned!(concat!(env!("OUT_DIR"), "/text_64_64_reloc.o"));
pub const VARIABLES_RELOC: &[u8] =
include_bytes_aligned!(concat!(env!("OUT_DIR"), "/variables_reloc.bpf.o"));
pub const LOG: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/log"));
pub const MAP_TEST: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/map_test"));

@ -1,4 +1,8 @@
use aya::{programs::UProbe, util::KernelVersion, Ebpf};
use aya::{
programs::{UProbe, Xdp},
util::KernelVersion,
Ebpf,
};
use test_log::test;
#[test]
@ -33,6 +37,17 @@ fn text_64_64_reloc() {
assert_eq!(m.get(&1, 0).unwrap(), 3);
}
#[test]
fn variables_reloc() {
let mut bpf = Ebpf::load(crate::VARIABLES_RELOC).unwrap();
let prog: &mut Xdp = bpf
.program_mut("variables_reloc")
.unwrap()
.try_into()
.unwrap();
prog.load().unwrap();
}
fn load_and_attach(name: &str, bytes: &[u8]) -> Ebpf {
let mut bpf = Ebpf::load(bytes).unwrap();

Loading…
Cancel
Save