inject(8)
π inject(8) β¨ System Manager's Manual
inject(8), bestie, and it's giving main character energy π π¦
β¨ NAME β¨
okay so inject is the tool that injects the right error into a function when your input call chain and predicates all line up π«Ά It runs on Linux eBPF/bcc, so it's giving low-level and I'm obsessed π§
πΈ SYNOPSIS πΈ
inject -h [-I header] [-P probability] [-v] [-c count] <mode> <spec>
π DESCRIPTION π
okay so inject breaks things on purpose: it injects errors into the kernel functionality you pick, but only when your call chain and its predicates are satisfied πβ¨
β οΈ WARNING: this tool injects failures into key kernel functions and may crash the kernel π Know what you're doing before you touch it, bestie. Seriously.
This one leans on a Linux 4.16 feature, bpf_override_return() π₯
Since it's built on BPF, only the root user can run it. No cap π
π OPTIONS π
-hβ prints the usage message π-vβ shows you the generated BPF program, so you can debug it or tweak it π-I headerβ the headers you need included π-P probabilityβ the optional chance of failure. It defaults to1π²-c countβ how many errors to inject before it stops. By default it never stops, iykyk π
π¦ MODE π¦
kmallocβ makes the following function report failure:
int should_failslab(struct kmem_cache *s, gfp_t gfpflags)
bioβ makes the following function report failure:
int should_fail_bio(struct bio *bio)
alloc_pageβ makes the following function report failure:
bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
π§ SPEC π§
the spec is shaped like this π
FUNCTION([ARGS])[(TEST)] [=> ...]
It's a list of predicates separated by "=>". Each predicate is a function signature (name plus arguments) sitting in a call stack, along with a test on that function's arguments π
Missing predicates are implicitly true, and so are missing tests π«Ά You only have to spell out the function arguments if your test actually uses them. And if the error injection function isn't listed as the first predicate, it gets added automatically, periodt β¨
Functions are listed in the reverse order they get called. So if a() calls b(), the spec is "b() => a()" π
π₯ REQUIREMENTS π₯
you'll need CONFIG_BPF, CONFIG_BPF_KPROBE_OVERRIDE, and bcc π
π EXAMPLES π
inject kmalloc -v 'SyS_mount()'
inject kmalloc -v 'mount_subtree() => btrfs_mount()'
inject -P 0.5 -c 100 alloc_page "should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) (order == 1) => qlge_refill_bq()"
For more, run -h and check out tools/inject_example.txt π§
π SOURCE π
this is from bcc π«Ά
https://github.com/iovisor/bcc
Also look in the bcc distribution for a companion _examples.txt file. It has example usage, output, and commentary for this tool π
πΈ OS πΈ
Linux only, bestie π§
β STABILITY β
Unstable, it's still in development π§
π AUTHOR π
written by Howard McLauchlan π
okay that's the whole thing, bestie π This page is from the USER COMMANDS section, dated 2018-03-16, and it's the inject(8) page πβ¨
π¦ where this page comes from
- debian bookworm: bpfcc-tools 0.26.0+ds-1 Β· Apache-2.0
- debian trixie: bpfcc-tools 0.31.0+ds-7 Β· Apache-2.0
- ubuntu jammy: bpfcc-tools 0.18.0+ds-2 Β· Apache-2.0
- ubuntu noble: bpfcc-tools 0.29.1+ds-1ubuntu7 Β· Apache-2.0
- ubuntu questing: bpfcc-tools 0.31.0+ds-7ubuntu2 Β· Apache-2.0
- ubuntu resolute: bpfcc-tools 0.35.0+ds-1ubuntu2 Β· Apache-2.0
- ubuntu stonking: bpfcc-tools 0.35.0+ds-1ubuntu4 Β· Apache-2.0
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms