-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import existing files into repository
- Loading branch information
0 parents
commit d27745a
Showing
5 changed files
with
142 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
*.o |
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,25 @@ | ||
#! /bin/bash | ||
|
||
set -e | ||
|
||
export TEMPDIR=${TEMPDIR:-/scratch/local} | ||
|
||
releases=( | ||
5.10.110-433 | ||
) | ||
|
||
for release in "${releases[@]}"; do | ||
test -d $TMPDIR/linux-$release.x86_64 || (cd $TMPDIR && tar xf /src/mariux/beeroot/build-archives/linux-$release.x86_64.beebuild.tar.bz2) | ||
( | ||
cd fix-uring | ||
KERNEL=$TMPDIR/linux-$release.x86_64/build make clean | ||
KERNEL=$TMPDIR/linux-$release.x86_64/build make | ||
) | ||
ver=${release%-*} # 5.10.92 | ||
build=${release#*-} # 421 | ||
echo "release $release ver $ver build $build" | ||
mkdir -p out/$ver.mx64.$build | ||
cp fix-uring/fix-uring.ko out/$ver.mx64.$build/fix-uring.ko | ||
done | ||
|
||
|
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,6 @@ | ||
*.cmd | ||
Module.symvers | ||
*.ko | ||
*.mod | ||
*.mod.c | ||
modules.order |
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,7 @@ | ||
obj-m += fix-uring.o | ||
|
||
all: | ||
make -C $(KERNEL) M=$(PWD) modules | ||
|
||
clean: | ||
make -C $(KERNEL) M=$(PWD) clean |
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,102 @@ | ||
#include <linux/init.h> | ||
#include <linux/module.h> | ||
#include <linux/kernel.h> | ||
#include <linux/ftrace.h> | ||
#include <linux/printk.h> | ||
#include <linux/kprobes.h> | ||
|
||
#include <uapi/linux/io_uring.h> | ||
|
||
MODULE_LICENSE("GPL"); | ||
MODULE_AUTHOR("Donald Buczek <buczek@molgen.mpg.de>"); | ||
MODULE_DESCRIPTION("fix-uring"); | ||
MODULE_VERSION("0.01"); | ||
|
||
/* | ||
* General concept to hook a kernel function with ftrace: | ||
* | ||
* https://www.codeproject.com/Articles/1275114/Hooking-Linux-Kernel-Functions-Part-2-How-to-Hook | ||
* | ||
* Idea to hack around the no longer exported kallsyms_lookup_name with register_kprobe | ||
* originally from AMD developers in the comments of this thread: | ||
* | ||
* https://lwn.net/Articles/813350/ | ||
*/ | ||
|
||
/* function signature as defined in kernel source */ | ||
|
||
typedef long io_uring_setup_fn_type(u32 entries, struct io_uring_params __user *params); | ||
|
||
static io_uring_setup_fn_type *io_uring_setup; | ||
static io_uring_setup_fn_type io_uring_setup_wrapper; | ||
|
||
static long io_uring_setup_wrapper(u32 entries, struct io_uring_params __user *params) { | ||
printk("wrapper"); | ||
return -ENOSYS; | ||
} | ||
|
||
static void ftrace_callback(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *ops, struct pt_regs *regs) | ||
{ | ||
printk("trace callback"); | ||
if (!within_module(parent_ip, THIS_MODULE)) | ||
regs->ip = (unsigned long)io_uring_setup_wrapper; | ||
} | ||
|
||
static int get_symbol_via_kprobe(char *name, void **addr) | ||
{ | ||
struct kprobe kp; | ||
int err; | ||
memset(&kp, 0, sizeof(kp)); | ||
kp.symbol_name = name; | ||
err = register_kprobe(&kp); | ||
if (err) { | ||
return err; | ||
} | ||
*addr = kp.addr; | ||
unregister_kprobe(&kp); | ||
return 0; | ||
} | ||
|
||
static struct ftrace_ops ops = { | ||
.func = ftrace_callback, | ||
.flags = FTRACE_OPS_FL_SAVE_REGS|FTRACE_OPS_FL_IPMODIFY | ||
}; | ||
|
||
static int __init fix_uring_init(void) | ||
{ | ||
int err; | ||
|
||
err = get_symbol_via_kprobe("io_uring_setup", (void **)&io_uring_setup); | ||
if (err) { | ||
pr_err("fix_uring: can't find io_uring_setup: %d\n", err); | ||
return(err); | ||
} | ||
|
||
err = ftrace_set_filter_ip(&ops, (unsigned long)io_uring_setup, 0, 0); | ||
if (err) { | ||
pr_err("fix_uring: ftrace_set_filter_ip failed: %d\n", err); | ||
return(err); | ||
|
||
} | ||
err = register_ftrace_function(&ops); | ||
if (err) { | ||
pr_err("fix_uring: register_ftrace_function failed: %d\n", err); | ||
return(err); | ||
|
||
} | ||
pr_info("fix-uring: installed\n"); | ||
return 0; | ||
} | ||
|
||
static void __exit fix_uring_exit(void) | ||
{ | ||
int err; | ||
err = unregister_ftrace_function(&ops); | ||
if (err) { | ||
pr_err("fix_uring: unregister_ftrace_function failed: %d\n", err); | ||
} | ||
pr_info("fix-uring: removed\n"); | ||
} | ||
|
||
module_init(fix_uring_init); | ||
module_exit(fix_uring_exit); |