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: 33d2961b05

Signed-off-by: Rissu <90097027+rsuntk@users.noreply.github.com>
This commit is contained in:
Rissu
2025-03-25 13:41:48 +00:00
committed by ShirkNeko
parent 150ad66925
commit f28d4b9f39
2 changed files with 23 additions and 22 deletions

View File

@@ -80,12 +80,11 @@ endif
ifeq ($(shell grep -q "get_cred_rcu" $(srctree)/include/linux/cred.h; echo $$?),0) ifeq ($(shell grep -q "get_cred_rcu" $(srctree)/include/linux/cred.h; echo $$?),0)
ccflags-y += -DKSU_COMPAT_HAS_GET_CRED_RCU ccflags-y += -DKSU_COMPAT_HAS_GET_CRED_RCU
else else
# https://github.com/gregkh/linux/commit/123e44b9a49a42ff5313ec65256f1540d7c52fa0
ifeq ($(shell grep -q "atomic_long_t\s\+\usage" $(srctree)/include/linux/cred.h; echo $$?),0) 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 ccflags-y += -DKSU_COMPAT_ATOMIC_LONG
else endif
$(info -- KernelSU compat: atomic_t detected.) ifeq ($(shell grep -q "int\s\+\non_rcu" $(srctree)/include/linux/cred.h; echo $$?),0)
ccflags-y += -DKSU_COMPAT_HAS_NONCONST_CRED
endif endif
endif endif

View File

@@ -8,23 +8,25 @@
#include "linux/key.h" #include "linux/key.h"
// for kernel without get_cred_rcu // for kernel without get_cred_rcu
#ifndef KSU_COMPAT_HAS_GET_CRED_RCU #ifndef KSU_COMPAT_HAS_GET_CRED_RCU
static inline const struct cred *get_cred_rcu(const struct cred *cred) static inline const struct cred *get_cred_rcu(const struct cred *cred)
{ {
struct cred *nonconst_cred = (struct cred *) cred; struct cred *nonconst_cred = (struct cred *) cred;
if (!cred) if (!cred)
return NULL; return NULL;
#ifdef KSU_COMPAT_ATOMIC_LONG #ifdef KSU_COMPAT_ATOMIC_LONG
if (!atomic_long_inc_not_zero(&nonconst_cred->usage)) if (!atomic_long_inc_not_zero(&nonconst_cred->usage))
#else #else
if (!atomic_inc_not_zero(&nonconst_cred->usage)) if (!atomic_inc_not_zero(&nonconst_cred->usage))
#endif #endif
return NULL; return NULL;
validate_creds(cred); validate_creds(cred);
nonconst_cred->non_rcu = 0; #ifdef KSU_COMPAT_HAS_NONCONST_CRED
return cred; nonconst_cred->non_rcu = 0;
} #endif
#endif return cred;
}
#endif
/* /*
* Adapt to Huawei HISI kernel without affecting other kernels , * Adapt to Huawei HISI kernel without affecting other kernels ,