Skip to content

Commit

Permalink
kernel: auto backport get_cred_rcu
Browse files Browse the repository at this point in the history
  • Loading branch information
rifsxd committed Jan 16, 2025
1 parent 7314c8e commit 6f6dd29
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,27 @@ $(info -- KernelSU-Next Manager signature hash: $(KSU_NEXT_EXPECTED_HASH))
ccflags-y += -DEXPECTED_NEXT_SIZE=$(KSU_NEXT_EXPECTED_SIZE)
ccflags-y += -DEXPECTED_NEXT_HASH=\"$(KSU_NEXT_EXPECTED_HASH)\"

ccflags-y += -DKSU_COMPAT_GET_CRED_RCU

ccflags-y += -DKSU_UMOUNT

# This feature is introduced in linux 5.0-rc1
ifeq ($(shell grep -q "get_cred_rcu" $(srctree)/include/linux/cred.h; echo $$?),0)
ccflags-y += -DKSU_COMPAT_GET_CRED_RCU
else
$(info -- Your kernel does not support get_cred_rcu, please backport it.)
$(info -- How to backport: https://github.com/tiann/KernelSU/pull/2320#issuecomment-2564232958)
$(info -- Fallback to old changes.)
ifneq ($(shell grep -Eq "^static inline const struct cred \*get_cred_rcu" $(srctree)/include/linux/cred.h; echo $$?),0)
$(info -- KSU_NEXT: adding function 'static inline const struct cred *get_cred_rcu(const struct cred *cred);' to $(srctree)/include/linux/cred.h)
GET_CRED_RCU = static inline const struct cred *get_cred_rcu(const struct cred *cred)\n\
{\n\t\
struct cred *nonconst_cred = (struct cred *) cred;\n\t\
if (!cred)\n\t\t\
return NULL;\n\t\
if (!atomic_inc_not_zero(&nonconst_cred->usage))\n\t\t\
return NULL;\n\t\
validate_creds(cred);\n\t\
return cred;\n\
}\n
$(shell grep -qF "$(GET_CRED_RCU)" $(srctree)/include/linux/cred.h || sed -i '/^static inline void put_cred/i $(GET_CRED_RCU)' $(srctree)/include/linux/cred.h)

$(info -- KSU_NEXT: modifying 'get_task_cred' function in $(srctree)/kernel/cred.c)
$(shell sed -i 's/!atomic_inc_not_zero(&((struct cred \*)cred)->usage)/!get_cred_rcu(cred)/g' $(srctree)/kernel/cred.c)
endif

ifneq ($(shell grep -Eq "^static int can_umount" $(srctree)/fs/namespace.c; echo $$?),0)
Expand Down

1 comment on commit 6f6dd29

@LeeBinder
Copy link

@LeeBinder LeeBinder commented on 6f6dd29 Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rifsxd. Quoting from rsuntk/KernelSU@3a16da0#commitcomment-151554133 f.f. (+ slight adjustments of non-native English):

Auto backport get_cred_rcu depends on atomic_ or atomic_long availability.
Also ksu next auto backports path_umount.

We don't need to auto backport stuff because get_cred_rcu is inside core_hook.c now.

I don't use auto backport for path_umount, only get_cred_rcu since a few kernels may have some difficulties with this path_umount patch.

So, you must backport path_umount to your kernel; get_cred_rcu is not necessary now.

I'm sharing in case this could be relevant or at least helpful in some way?

Please sign in to comment.