From abead1debfae56e8d0307c642865ec23aaa854d3 Mon Sep 17 00:00:00 2001 From: TheSola10 Date: Fri, 5 May 2023 22:35:17 +0200 Subject: [PATCH] Fixes for kernel 6.3+ --- binder/binder.c | 4 ++++ binder/binder_alloc.c | 4 ++++ binder/binderfs.c | 12 ++++++++++-- binder/deps.c | 11 +++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/binder/binder.c b/binder/binder.c index b0906d9..99f47c3 100644 --- a/binder/binder.c +++ b/binder/binder.c @@ -5234,8 +5234,12 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma) proc->pid, vma->vm_start, vma->vm_end, "bad vm_flags", -EPERM); return -EPERM; } +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6,3,0)) + vm_flags_mod(vma, VM_DONTCOPY | VM_MIXEDMAP, VM_MAYWRITE); +#else vma->vm_flags |= VM_DONTCOPY | VM_MIXEDMAP; vma->vm_flags &= ~VM_MAYWRITE; +#endif vma->vm_ops = &binder_vm_ops; vma->vm_private_data = proc; diff --git a/binder/binder_alloc.c b/binder/binder_alloc.c index dbd96fa..13b8b32 100644 --- a/binder/binder_alloc.c +++ b/binder/binder_alloc.c @@ -1011,7 +1011,11 @@ enum lru_status binder_alloc_free_page(struct list_head *item, if (vma) { trace_binder_unmap_user_start(alloc, index); +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6,3,0)) + zap_page_range_single(vma, page_addr, PAGE_SIZE, NULL); +#else zap_page_range(vma, page_addr, PAGE_SIZE); +#endif trace_binder_unmap_user_end(alloc, index); } diff --git a/binder/binderfs.c b/binder/binderfs.c index 2677ce5..0a51426 100644 --- a/binder/binderfs.c +++ b/binder/binderfs.c @@ -357,7 +357,12 @@ static inline bool is_binderfs_control_device(const struct dentry *dentry) return info->control_dentry == dentry; } -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,12,0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6,3,0)) +static int binderfs_rename(struct mnt_idmap *idmap, + struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5,12,0)) static int binderfs_rename(struct user_namespace *namespace, struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) @@ -371,7 +376,10 @@ static int binderfs_rename(struct inode *old_dir, struct dentry *old_dentry, is_binderfs_control_device(new_dentry)) return -EPERM; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,12,0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6,3,0)) + return simple_rename(idmap, old_dir, old_dentry, new_dir, + new_dentry, flags); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5,12,0)) return simple_rename(namespace, old_dir, old_dentry, new_dir, new_dentry, flags); #else return simple_rename(old_dir, old_dentry, new_dir, new_dentry, flags); diff --git a/binder/deps.c b/binder/deps.c index 319e82f..232bded 100644 --- a/binder/deps.c +++ b/binder/deps.c @@ -164,6 +164,16 @@ int task_work_add(struct task_struct *task, struct callback_head *work, return task_work_add_ptr(task, work, notify); } +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6,3,0)) +static void (*zap_page_range_single_ptr)(struct vm_area_struct *, unsigned long, unsigned long, struct zap_details *) = NULL; + +void zap_page_range_single(struct vm_area_struct *vma, unsigned long address, unsigned long size, struct zap_details *details) +{ + if (!zap_page_range_single_ptr) + zap_page_range_single_ptr = kallsyms_lookup_name_wrapper("zap_page_range_single"); + zap_page_range_single_ptr(vma, address, size, details); +} +#else static void (*zap_page_range_ptr)(struct vm_area_struct *, unsigned long, unsigned long) = NULL; void zap_page_range(struct vm_area_struct *vma, unsigned long address, unsigned long size) @@ -172,6 +182,7 @@ void zap_page_range(struct vm_area_struct *vma, unsigned long address, unsigned zap_page_range_ptr = kallsyms_lookup_name_wrapper("zap_page_range"); zap_page_range_ptr(vma, address, size); } +#endif static void (*put_ipc_ns_ptr)(struct ipc_namespace *ns) = NULL;