Skip to content

Commit

Permalink
Fix kconfig string loading
Browse files Browse the repository at this point in the history
  • Loading branch information
davibe committed Nov 5, 2024
1 parent d95a456 commit 8179853
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions aya/src/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,11 @@ fn compute_kconfig_definition(features: &Features) -> HashMap<String, Vec<u8>> {
Some('y') => 1_u64.to_ne_bytes().to_vec(),
Some('m') => 2_u64.to_ne_bytes().to_vec(),
Some('"') => {
if raw_value.len() > 2 || raw_value.ends_with('"') {
if raw_value.len() < 2 || !raw_value.ends_with('"') {
continue;
}

let raw_value = &raw_value[1..raw_value.len() - 1];

raw_value.as_bytes().to_vec()
}
Some(_) => {
Expand Down
8 changes: 8 additions & 0 deletions test/integration-test/bpf/kconfig.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ extern unsigned int CONFIG_BPF __kconfig;
extern unsigned int CONFIG_PANIC_TIMEOUT __kconfig;
// CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=120
extern unsigned int CONFIG_DEFAULT_HUNG_TASK_TIMEOUT __kconfig;
// CONFIG_DEFAULT_HOSTNAME
extern char CONFIG_DEFAULT_HOSTNAME[] __kconfig;

SEC("xdp")
int kconfig(struct xdp_md *ctx) {
Expand All @@ -24,6 +26,12 @@ int kconfig(struct xdp_md *ctx) {
return XDP_DROP;
}

for (int i = 0; i < 7; i++) {
if ("(none)"[i] != CONFIG_DEFAULT_HOSTNAME[i]) {
return XDP_DROP;
}
}

return XDP_PASS;
}

Expand Down

0 comments on commit 8179853

Please sign in to comment.