From aa0064306bf31fd83686cd841e024bb0996e43df Mon Sep 17 00:00:00 2001 From: TheSola10 Date: Mon, 8 Aug 2022 10:32:25 +0200 Subject: [PATCH 1/2] Patches for kernel 5.19 --- binder/binder.c | 4 +++- binder/deps.c | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/binder/binder.c b/binder/binder.c index 1b97cfc..8901fd2 100644 --- a/binder/binder.c +++ b/binder/binder.c @@ -2236,7 +2236,9 @@ static void binder_deferred_fd_close(int fd) if (!twcb) return; init_task_work(&twcb->twork, binder_do_fd_close); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)) + twcb->file = close_fd_get_file(fd); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0)) close_fd_get_file(fd, &twcb->file); #else __close_fd_get_file(fd, &twcb->file); diff --git a/binder/deps.c b/binder/deps.c index 726b1b1..a7c5763 100644 --- a/binder/deps.c +++ b/binder/deps.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -69,10 +70,15 @@ static unsigned long kallsyms_lookup_name_wrapper(const char *name) #endif } +static int (*close_fd_get_file_ptr)(unsigned int fd +#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0)) + , struct file **res +#endif + ) = NULL; -static int (*close_fd_get_file_ptr)(unsigned int fd, struct file **res) = NULL; - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)) +struct file *close_fd_get_file(unsigned int fd) +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0)) int close_fd_get_file(unsigned int fd, struct file **res) #else int __close_fd_get_file(unsigned int fd, struct file **res) @@ -84,7 +90,12 @@ int __close_fd_get_file(unsigned int fd, struct file **res) #else close_fd_get_file_ptr = kallsyms_lookup_name_wrapper("__close_fd_get_file"); #endif + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)) + return close_fd_get_file_ptr(fd); +#else return close_fd_get_file_ptr(fd, res); +#endif } static int (*can_nice_ptr)(const struct task_struct *, const int) = NULL; From 9510d2549e2deaa0e73c761b10c4211155ebd6b1 Mon Sep 17 00:00:00 2001 From: TheSola10 Date: Tue, 9 Aug 2022 17:39:31 +0200 Subject: [PATCH 2/2] Fixed page fault by matching in-tree binder behavior --- binder/binder.c | 3 +++ binder/deps.c | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/binder/binder.c b/binder/binder.c index 8901fd2..a7e620b 100644 --- a/binder/binder.c +++ b/binder/binder.c @@ -2244,6 +2244,9 @@ static void binder_deferred_fd_close(int fd) __close_fd_get_file(fd, &twcb->file); #endif if (twcb->file) { +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)) + get_file(twcb->file); +#endif filp_close(twcb->file, current->files); task_work_add(current, &twcb->twork, TWA_RESUME); } else { diff --git a/binder/deps.c b/binder/deps.c index a7c5763..319e82f 100644 --- a/binder/deps.c +++ b/binder/deps.c @@ -70,11 +70,12 @@ static unsigned long kallsyms_lookup_name_wrapper(const char *name) #endif } -static int (*close_fd_get_file_ptr)(unsigned int fd -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0)) - , struct file **res +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)) +static struct file *(*close_fd_get_file_ptr)(unsigned int fd) +#else +static int (*close_fd_get_file_ptr)(unsigned int fd, struct file **res) #endif - ) = NULL; + = NULL; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)) struct file *close_fd_get_file(unsigned int fd)