final (hopefully) fixes

This commit is contained in:
Sebastian Moser
2024-08-16 15:49:38 +02:00
parent 349b792c18
commit 748b7e4aa1
3 changed files with 28 additions and 11 deletions

View File

@@ -275,7 +275,11 @@ def cmd_starter():
pid = os.getpid() pid = os.getpid()
print("starter process running with pid", pid) 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: while True:
print("file:", __file__) print("file:", __file__)

View File

@@ -7,6 +7,8 @@ in stdenv.mkDerivation {
src = ./.; src = ./.;
# Use $CC as it allows for stdenv to reference the correct C compiler # 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 = '' buildPhase = ''
gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 read-helper.c -o read-helper gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 read-helper.c -o read-helper
''; '';

View File

@@ -25,6 +25,25 @@ struct file_operations unkillable_fops = {
int unkillable_major = 117; 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) int unkillable_init(void)
{ {
if (register_chrdev(unkillable_major, "unkillable", &unkillable_fops) < 0 ) { 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) 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 */ /* interpret count to read as target pid */
printk("Unkillable: Got pid %d", (int) count); printk("Unkillable: Got pid %d", (int) count);
/* get the pid struct */ make_unkillable(count);
pid_struct = find_get_pid((int) 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) { if (*f_pos == 0) {
*f_pos+=1; *f_pos+=1;
@@ -91,6 +101,7 @@ ssize_t unkillable_write(struct file *filp, const char *buf, size_t count, loff_
return ret; return ret;
} else { } else {
pr_info("ok ... pid: %llu\n", res); pr_info("ok ... pid: %llu\n", res);
make_unkillable( (int) res);
return count; return count;
} }
} }