-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's to prevent running --output-skb or --output-skb-shared-info on kernel which does not support bpf_snprintf_btf() helper. Meanwhile, avoid verifier roaring on Ubuntu 20.04: ; instruction poisoned by CO-RE 938: (85) call unknown#195896080 invalid func unknown#195896080 processed 519 insns (limit 1000000) max_states_per_insn 0 total_states 29 peak_states 29 mark_read 27 Signed-off-by: Leon Hwang <hffilwlqm@gmail.com>
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ release | |
tags | ||
kprobepwru_* | ||
kprobemultipwru_* | ||
featurespwru_* | ||
!pwru/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | ||
/* Copyright Leon Hwang */ | ||
|
||
#include "vmlinux.h" | ||
#include "bpf/bpf_helpers.h" | ||
#include "bpf/bpf_core_read.h" | ||
|
||
struct pwru_features { | ||
bool kprobe_happened; | ||
bool has_snprintf_btf; | ||
} features; | ||
|
||
SEC("kprobe") | ||
int kprobe__map_lookup_elem(struct pt_regs *ctx) | ||
{ | ||
features.kprobe_happened = true; | ||
|
||
/* Detect if bpf_snprintf_btf is available. | ||
* Since: c4d0bfb45068 ("bpf: Add bpf_snprintf_btf helper") | ||
*/ | ||
features.has_snprintf_btf = bpf_core_enum_value_exists(enum bpf_func_id, BPF_FUNC_snprintf_btf); | ||
|
||
return BPF_OK; | ||
} | ||
|
||
char __license[] SEC("license") = "Dual BSD/GPL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* Copyright Leon Hwang */ | ||
|
||
package pwru | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/cilium/ebpf" | ||
"github.com/cilium/ebpf/btf" | ||
"github.com/cilium/ebpf/link" | ||
) | ||
|
||
func DetectFeatures(spec *ebpf.CollectionSpec, btfSpec *btf.Spec, f *Flags) { | ||
bssMap, err := ebpf.NewMap(spec.Maps[".bss"]) | ||
if err != nil { | ||
log.Fatalf("Failed to create bss map: %v", err) | ||
} | ||
defer bssMap.Close() | ||
|
||
coll, err := ebpf.NewCollectionWithOptions(spec, ebpf.CollectionOptions{ | ||
Programs: ebpf.ProgramOptions{ | ||
KernelTypes: btfSpec, | ||
}, | ||
MapReplacements: map[string]*ebpf.Map{ | ||
".bss": bssMap, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Fatalf("Failed to create collection: %v", err) | ||
} | ||
defer coll.Close() | ||
|
||
kp, err := link.Kprobe("map_lookup_elem", coll.Programs["kprobe__map_lookup_elem"], nil) | ||
if err != nil { | ||
log.Fatalf("Failed to kprobe map_lookup_elem: %v", err) | ||
} | ||
defer kp.Close() | ||
|
||
var features struct { | ||
Happened uint8 | ||
HasSnprintfBtf uint8 | ||
} | ||
|
||
// Trigger kprobe and retrieve features data | ||
err = bssMap.Lookup(uint32(0), &features) | ||
if err != nil { | ||
log.Fatalf("Failed to lookup features data: %v", err) | ||
} | ||
|
||
if features.Happened == 0 { | ||
log.Fatalf("Features detection was not triggered") | ||
} | ||
|
||
if (f.OutputSkb || f.OutputShinfo) && features.HasSnprintfBtf == 0 { | ||
log.Fatalf("Unsupported to output skb or shinfo because bpf_snprintf_btf() is unavailable") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters