From 748b7e4aa121a7210fed0d0a29f8e53e91d3fbf9 Mon Sep 17 00:00:00 2001 From: Sebastian Moser Date: Fri, 16 Aug 2024 15:49:38 +0200 Subject: [PATCH] final (hopefully) fixes --- scripts/yt-block/main.py | 6 +++++- scripts/yt-block/read-helper.nix | 2 ++ scripts/yt-block/unkillable.c | 31 +++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/scripts/yt-block/main.py b/scripts/yt-block/main.py index 0b36742..92c92b5 100644 --- a/scripts/yt-block/main.py +++ b/scripts/yt-block/main.py @@ -275,7 +275,11 @@ def cmd_starter(): pid = os.getpid() print("starter process running with pid", pid) - os.system(f"$READ_HELPER {pid}") + #os.system(f"$READ_HELPER {}", pid) + # for some strange reason this does not work + with open("/dev/unkillable", "w") as file: + file.write(str(pid)) + #pass while True: print("file:", __file__) diff --git a/scripts/yt-block/read-helper.nix b/scripts/yt-block/read-helper.nix index c71bbbf..a380c7a 100644 --- a/scripts/yt-block/read-helper.nix +++ b/scripts/yt-block/read-helper.nix @@ -7,6 +7,8 @@ in stdenv.mkDerivation { src = ./.; # Use $CC as it allows for stdenv to reference the correct C compiler + # i cant get this to not trigger buffer oferflow protection on the read() call with the pid + # so let mod the kernel module, to be able to 'echo $pid > /dev/unkillable' buildPhase = '' gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 read-helper.c -o read-helper ''; diff --git a/scripts/yt-block/unkillable.c b/scripts/yt-block/unkillable.c index 7a61b64..fd4eee5 100644 --- a/scripts/yt-block/unkillable.c +++ b/scripts/yt-block/unkillable.c @@ -25,6 +25,25 @@ struct file_operations unkillable_fops = { int unkillable_major = 117; +void make_unkillable(int pid) { + + struct pid *pid_struct; + struct task_struct *p; + + pr_info("ok ... pid in fn: %d \n", pid); + + /* get the pid struct */ + pid_struct = find_get_pid((int) pid); + + /* get the task_struct from the pid */ + p = pid_task(pid_struct, PIDTYPE_PID); + + /* add the flag */ + p->signal->flags = p->signal->flags | SIGNAL_UNKILLABLE; + printk("Unkillable: pid %d marked as unkillable\n", (int) pid); +} + + int unkillable_init(void) { if (register_chrdev(unkillable_major, "unkillable", &unkillable_fops) < 0 ) { @@ -54,21 +73,12 @@ int unkillable_release(struct inode *inode, struct file *filp) ssize_t unkillable_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { - struct pid *pid_struct; - struct task_struct *p; /* interpret count to read as target pid */ printk("Unkillable: Got pid %d", (int) count); - /* get the pid struct */ - pid_struct = find_get_pid((int) count); + make_unkillable(count); - /* get the task_struct from the pid */ - p = pid_task(pid_struct, PIDTYPE_PID); - - /* add the flag */ - p->signal->flags = p->signal->flags | SIGNAL_UNKILLABLE; - printk("Unkillable: pid %d marked as unkillable\n", (int) count); if (*f_pos == 0) { *f_pos+=1; @@ -91,6 +101,7 @@ ssize_t unkillable_write(struct file *filp, const char *buf, size_t count, loff_ return ret; } else { pr_info("ok ... pid: %llu\n", res); + make_unkillable( (int) res); return count; } }