Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QoL improvements for inject #1682

Merged
merged 2 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
More helpful help message
  • Loading branch information
Howard McLauchlan committed Apr 13, 2018
commit 45bcfb7ca13f37b8e51117364b025d47550dec3c
22 changes: 19 additions & 3 deletions tools/inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ def attach(self, bpf):


class Tool:

examples ="""
EXAMPLES:
# ./inject.py kmalloc -v 'SyS_mount()'
Fails all calls to syscall mount
# ./inject.py kmalloc -v '(true) => SyS_mount()(true)'
Explicit rewriting of above
# ./inject.py kmalloc -v 'mount_subtree() => btrfs_mount()'
Fails btrfs mounts only
# ./inject.py kmalloc -v 'd_alloc_parallel(struct dentry *parent, const struct \\
qstr *name)(STRCMP(name->name, 'bananas'))'
Fails dentry allocations of files named 'bananas'
# ./inject.py kmalloc -v -P 0.01 'SyS_mount()'
Fails calls to syscall mount with 1% probability
"""
# add cases as necessary
error_injection_mapping = {
"kmalloc": "should_failslab(struct kmem_cache *s, gfp_t gfpflags)",
Expand All @@ -304,8 +319,9 @@ class Tool:
def __init__(self):
parser = argparse.ArgumentParser(description="Fail specified kernel" +
" functionality when call chain and predicates are met",
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(metavar="mode", dest="mode",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=Tool.examples)
parser.add_argument(dest="mode", choices=['kmalloc','bio'],
help="indicate which base kernel function to fail")
parser.add_argument(metavar="spec", dest="spec",
help="specify call chain")
Expand All @@ -316,7 +332,7 @@ def __init__(self):
metavar="probability", type=float,
help="probability that this call chain will fail")
parser.add_argument("-v", "--verbose", action="store_true",
help="print BPF program")
help="print BPF program")
self.args = parser.parse_args()

self.program = ""
Expand Down
17 changes: 15 additions & 2 deletions tools/inject_example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ fail our mounts half the time:
# ./inject.py kmalloc -v -P 0.01 'SyS_mount()'

USAGE message:
usage: inject.py [-h] [-I header] [-P probability] [-v] mode spec
usage: inject.py [-h] [-I header] [-P probability] [-v] {kmalloc,bio} spec

Fail specified kernel functionality when call chain and predicates are met

positional arguments:
mode indicate which base kernel function to fail
{kmalloc,bio} indicate which base kernel function to fail
spec specify call chain

optional arguments:
Expand All @@ -130,3 +130,16 @@ optional arguments:
-P probability, --probability probability
probability that this call chain will fail
-v, --verbose print BPF program

EXAMPLES:
# ./inject.py kmalloc -v 'SyS_mount()'
Fails all calls to syscall mount
# ./inject.py kmalloc -v '(true) => SyS_mount()(true)'
Explicit rewriting of above
# ./inject.py kmalloc -v 'mount_subtree() => btrfs_mount()'
Fails btrfs mounts only
# ./inject.py kmalloc -v 'd_alloc_parallel(struct dentry *parent, const struct \
qstr *name)(STRCMP(name->name, 'bananas'))'
Fails dentry allocations of files named 'bananas'
# ./inject.py kmalloc -v -P 0.01 'SyS_mount()'
Fails calls to syscall mount with 1% probability