From f28d4b9f3933e24880880e97e2d36a232a67246c Mon Sep 17 00:00:00 2001 From: Rissu <90097027+rsuntk@users.noreply.github.com> Date: Tue, 25 Mar 2025 13:41:48 +0000 Subject: [PATCH] kernel: fix prebuilt get_cred_rcu on certain linux version Previously, i think non_rcu not available on 4.4.186 and below but, apparently 4.9 too. Fix: https://github.com/luyanci/KernelSU/commit/33d2961b057d87909887c49f80358e8bfd328e72 Signed-off-by: Rissu <90097027+rsuntk@users.noreply.github.com> --- kernel/Makefile | 7 +++---- kernel/kernel_compat.h | 38 ++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 5d4c5852..7b6effb9 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -80,12 +80,11 @@ endif ifeq ($(shell grep -q "get_cred_rcu" $(srctree)/include/linux/cred.h; echo $$?),0) ccflags-y += -DKSU_COMPAT_HAS_GET_CRED_RCU else -# https://github.com/gregkh/linux/commit/123e44b9a49a42ff5313ec65256f1540d7c52fa0 ifeq ($(shell grep -q "atomic_long_t\s\+\usage" $(srctree)/include/linux/cred.h; echo $$?),0) -$(info -- KernelSU compat: atomic_long_t detected.) ccflags-y += -DKSU_COMPAT_ATOMIC_LONG -else -$(info -- KernelSU compat: atomic_t detected.) +endif +ifeq ($(shell grep -q "int\s\+\non_rcu" $(srctree)/include/linux/cred.h; echo $$?),0) +ccflags-y += -DKSU_COMPAT_HAS_NONCONST_CRED endif endif diff --git a/kernel/kernel_compat.h b/kernel/kernel_compat.h index d4170355..36501246 100644 --- a/kernel/kernel_compat.h +++ b/kernel/kernel_compat.h @@ -8,24 +8,26 @@ #include "linux/key.h" // for kernel without get_cred_rcu - #ifndef KSU_COMPAT_HAS_GET_CRED_RCU - static inline const struct cred *get_cred_rcu(const struct cred *cred) - { - struct cred *nonconst_cred = (struct cred *) cred; - if (!cred) - return NULL; - #ifdef KSU_COMPAT_ATOMIC_LONG - if (!atomic_long_inc_not_zero(&nonconst_cred->usage)) - #else - if (!atomic_inc_not_zero(&nonconst_cred->usage)) - #endif - return NULL; - validate_creds(cred); - nonconst_cred->non_rcu = 0; - return cred; - } - #endif - +#ifndef KSU_COMPAT_HAS_GET_CRED_RCU +static inline const struct cred *get_cred_rcu(const struct cred *cred) +{ + struct cred *nonconst_cred = (struct cred *) cred; + if (!cred) + return NULL; +#ifdef KSU_COMPAT_ATOMIC_LONG + if (!atomic_long_inc_not_zero(&nonconst_cred->usage)) +#else + if (!atomic_inc_not_zero(&nonconst_cred->usage)) +#endif + return NULL; + validate_creds(cred); +#ifdef KSU_COMPAT_HAS_NONCONST_CRED + nonconst_cred->non_rcu = 0; +#endif + return cred; +} +#endif + /* * Adapt to Huawei HISI kernel without affecting other kernels , * Huawei Hisi Kernel EBITMAP Enable or Disable Flag ,