From 77f53012c283b593efd7cad503ad5fd38402f444 Mon Sep 17 00:00:00 2001 From: Niklas Elsbrock Date: Tue, 14 May 2024 22:35:30 +0200 Subject: [PATCH] initial commit --- literally_null.patch | 96 +++++++++++++++++++++++++++++++++ print_on_clone_and_execve.patch | 35 ++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 literally_null.patch create mode 100644 print_on_clone_and_execve.patch diff --git a/literally_null.patch b/literally_null.patch new file mode 100644 index 0000000..b0d53e0 --- /dev/null +++ b/literally_null.patch @@ -0,0 +1,96 @@ +diff --git a/drivers/char/mem.c b/drivers/char/mem.c +index 3c6670cf905f..ec176debb778 100644 +--- a/drivers/char/mem.c ++++ b/drivers/char/mem.c +@@ -30,6 +30,8 @@ + #include + #include + #include ++#include ++#include + + #define DEVMEM_MINOR 1 + #define DEVPORT_MINOR 4 +@@ -428,7 +430,20 @@ static ssize_t write_port(struct file *file, const char __user *buf, + static ssize_t read_null(struct file *file, char __user *buf, + size_t count, loff_t *ppos) + { +- return 0; ++ static const char content[] = "null\n"; ++ size_t content_length = sizeof(content); ++ ++ if (*ppos >= content_length) ++ return 0; ++ ++ size_t copy_len = min(content_length - *ppos, count); ++ if (copy_to_user(buf, content + *ppos, copy_len)) { ++ pr_err("null: User copy failed\n"); ++ return -EFAULT; ++ } ++ ++ *ppos += copy_len; ++ return copy_len; + } + + static ssize_t write_null(struct file *file, const char __user *buf, +@@ -437,33 +452,23 @@ static ssize_t write_null(struct file *file, const char __user *buf, + return count; + } + +-static ssize_t read_iter_null(struct kiocb *iocb, struct iov_iter *to) +-{ +- return 0; +-} +- +-static ssize_t write_iter_null(struct kiocb *iocb, struct iov_iter *from) ++static ssize_t write_iter_zero(struct kiocb *iocb, struct iov_iter *from) + { + size_t count = iov_iter_count(from); + iov_iter_advance(from, count); + return count; + } + +-static int pipe_to_null(struct pipe_inode_info *info, struct pipe_buffer *buf, ++static int pipe_to_zero(struct pipe_inode_info *info, struct pipe_buffer *buf, + struct splice_desc *sd) + { + return sd->len; + } + +-static ssize_t splice_write_null(struct pipe_inode_info *pipe, struct file *out, ++static ssize_t splice_write_zero(struct pipe_inode_info *pipe, struct file *out, + loff_t *ppos, size_t len, unsigned int flags) + { +- return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_null); +-} +- +-static int uring_cmd_null(struct io_uring_cmd *ioucmd, unsigned int issue_flags) +-{ +- return 0; ++ return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_zero); + } + + static ssize_t read_iter_zero(struct kiocb *iocb, struct iov_iter *iter) +@@ -627,8 +632,6 @@ static int open_port(struct inode *inode, struct file *filp) + #define zero_lseek null_lseek + #define full_lseek null_lseek + #define write_zero write_null +-#define write_iter_zero write_iter_null +-#define splice_write_zero splice_write_null + #define open_mem open_port + + static const struct file_operations __maybe_unused mem_fops = { +@@ -644,13 +647,8 @@ static const struct file_operations __maybe_unused mem_fops = { + }; + + static const struct file_operations null_fops = { +- .llseek = null_lseek, + .read = read_null, + .write = write_null, +- .read_iter = read_iter_null, +- .write_iter = write_iter_null, +- .splice_write = splice_write_null, +- .uring_cmd = uring_cmd_null, + }; + + static const struct file_operations __maybe_unused port_fops = { diff --git a/print_on_clone_and_execve.patch b/print_on_clone_and_execve.patch new file mode 100644 index 0000000..d48514c --- /dev/null +++ b/print_on_clone_and_execve.patch @@ -0,0 +1,35 @@ +diff --git a/fs/exec.c b/fs/exec.c +index 5ee2545c3e18..39739119d148 100644 +--- a/fs/exec.c ++++ b/fs/exec.c +@@ -1939,6 +1939,8 @@ static int do_execveat_common(int fd, struct filename *filename, + goto out_ret; + } + ++ pr_info("Task (pid: %d, comm: '%s') executed '%s'\n", current->pid, current->comm, bprm->filename); ++ + retval = count(argv, MAX_ARG_STRINGS); + if (retval == 0) + pr_warn_once("process '%s' launched '%s' with NULL argv: empty string added\n", +diff --git a/kernel/fork.c b/kernel/fork.c +index 3b9cdb42e757..11c52d81e0c3 100644 +--- a/kernel/fork.c ++++ b/kernel/fork.c +@@ -2867,6 +2867,7 @@ pid_t kernel_clone(struct kernel_clone_args *args) + struct task_struct *p; + int trace = 0; + pid_t nr; ++ char comm[TASK_COMM_LEN]; + + /* + * For legacy clone() calls, CLONE_PIDFD uses the parent_tid argument +@@ -2915,6 +2916,9 @@ pid_t kernel_clone(struct kernel_clone_args *args) + pid = get_task_pid(p, PIDTYPE_PID); + nr = pid_vnr(pid); + ++ get_task_comm(comm, p); ++ pr_info("Task (pid: %d, comm: '%s') cloned to new task (pid: %d, comm: '%.*s')\n", current->pid, current->comm, nr, TASK_COMM_LEN, comm); ++ + if (clone_flags & CLONE_PARENT_SETTID) + put_user(nr, args->parent_tid); +