From 95136c606e255f711ebe6716f573fb477b6eb702 Mon Sep 17 00:00:00 2001 From: backslashxx <118538522+backslashxx@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:28:58 +0800 Subject: [PATCH] kernel: require easy backports NON-GKI kernel builders have to touch their kernel source code anyway so we might as well tell them to backport things to achieve some sort of feature parity. Another thing is that on NON-GKI, we mostly do NOT care about ABI stability. Required: - path_umount: context: https://github.com/tiann/KernelSU/pull/1464#issue-2190561852 apply: https://github.com/xiaomi-sdm678/android_kernel_xiaomi_mojito/commit/2d514220cd262a772b35fae79358167ae1de9872 - get_cred_rcu: context: https://github.com/tiann/KernelSU/pull/2320#issuecomment-2564232958 apply: https://github.com/torvalds/linux/commit/97d0fb239c041f5f99655af74812c3ab75cc4346 if above conflicts, try: https://github.com/xiaomi-sdm678/android_kernel_xiaomi_mojito/commit/3fbad8b02a82d424dcf43bbf59a05a1edae705b8 Optional: - kernel_read / kernel_write < 4.14, backport chain, tested on 4.9 https://github.com/torvalds/linux/commit/e13ec939e96b13e664bb6cee361cc976a0ee621a https://github.com/torvalds/linux/commit/bdd1d2d3d251c65b74ac4493e08db18971c09240 https://github.com/torvalds/linux/commit/c41fbad015dabb0a40ecca50c3ff5658eb6471ff https://github.com/torvalds/linux/commit/ac452acae1caa1a451142a30b4e1ea09cfac4410 - strncpy_from_user_nofault for 5.4, apply: https://github.com/torvalds/linux/commit/bd88bb5d4007949be7154deae7cef7173c751a95 for 4.x, apply: https://github.com/xiaomi-sdm678/android_kernel_xiaomi_mojito/commit/424e21f3b01ddaeb86cef7efd3f519a7e342fb67 for any failures, just SKIP THIS or check dependency chain of, https://github.com/gregkh/linux/commit/3d7081822f7f9eab867d9bcc8fd635208ec438e0 this got backported to v4.4.236, v4.9.236, v4.14.197, v4.19.144 - hint, `curl $url.patch | git am` Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com> --- kernel/Makefile | 23 ++++++++++++++++++----- kernel/kernel_compat.c | 6 +++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 669297563b1d..5ce0b9423cf3 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -56,11 +56,24 @@ $(info -- KernelSU Manager signature hash: $(KSU_EXPECTED_HASH)) ccflags-y += -DEXPECTED_SIZE=$(KSU_EXPECTED_SIZE) ccflags-y += -DEXPECTED_HASH=\"$(KSU_EXPECTED_HASH)\" -ifeq ($(shell grep -q "int path_umount" $(srctree)/fs/namespace.c; echo $$?),0) -ccflags-y += -DKSU_UMOUNT -else -$(info -- Did you know you can backport path_umount to fs/namespace.c from 5.9?) -$(info -- Read: https://kernelsu.org/guide/how-to-integrate-for-non-gki.html#how-to-backport-path-umount) +ifneq ($(shell grep -q "int path_umount" $(srctree)/fs/namespace.c; echo $$?),0) +$(error You must backport path_umount - https://github.com/tiann/KernelSU/pull/1464 ) +endif + +ifneq ($(shell grep -q "get_cred_rcu" $(srctree)/include/linux/cred.h; echo $$?),0) +$(error You must backport get_cred_rcu - https://github.com/tiann/KernelSU/pull/2320#issuecomment-2564232958 ) +endif + +ifeq ($(shell grep -q "strncpy_from_user_nofault" $(srctree)/include/linux/uaccess.h; echo $$?),0) +ccflags-y += -DKSU_STRNCPY_FROM_USER_NOFAULT +endif + +ifeq ($(shell grep -q "ssize_t kernel_read" $(srctree)/fs/read_write.c; echo $$?),0) +ccflags-y += -DKSU_KERNEL_READ +endif + +ifeq ($(shell grep "ssize_t kernel_write" $(srctree)/fs/read_write.c | grep -q "const void" ; echo $$?),0) +ccflags-y += -DKSU_KERNEL_WRITE endif ccflags-y += -Wno-implicit-function-declaration -Wno-strict-prototypes -Wno-int-conversion -Wno-gcc-compat diff --git a/kernel/kernel_compat.c b/kernel/kernel_compat.c index 3d42d56ca4a2..7c90938f32cb 100644 --- a/kernel/kernel_compat.c +++ b/kernel/kernel_compat.c @@ -107,7 +107,7 @@ struct file *ksu_filp_open_compat(const char *filename, int flags, umode_t mode) ssize_t ksu_kernel_read_compat(struct file *p, void *buf, size_t count, loff_t *pos) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) || defined(KSU_KERNEL_READ) return kernel_read(p, buf, count, pos); #else loff_t offset = pos ? *pos : 0; @@ -122,7 +122,7 @@ ssize_t ksu_kernel_read_compat(struct file *p, void *buf, size_t count, ssize_t ksu_kernel_write_compat(struct file *p, const void *buf, size_t count, loff_t *pos) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) || defined(KSU_KERNEL_WRITE) return kernel_write(p, buf, count, pos); #else loff_t offset = pos ? *pos : 0; @@ -134,7 +134,7 @@ ssize_t ksu_kernel_write_compat(struct file *p, const void *buf, size_t count, #endif } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0) || defined(KSU_STRNCPY_FROM_USER_NOFAULT) long ksu_strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, long count) {