Skip to content

Commit

Permalink
kernel: handle backports
Browse files Browse the repository at this point in the history
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: tiann#1464 (comment)
	apply: xiaomi-sdm678/android_kernel_xiaomi_mojito@2d51422
 - get_cred_rcu:
	context: tiann#2320 (comment)
	apply: torvalds/linux@97d0fb2
	if above conflicts, try: xiaomi-sdm678/android_kernel_xiaomi_mojito@3fbad8b

Optional:
 - kernel_read / kernel_write
 	< 4.14, backport chain, tested on 4.9
 	torvalds/linux@e13ec93
	torvalds/linux@bdd1d2d
	torvalds/linux@c41fbad
	torvalds/linux@ac452ac

 - strncpy_from_user_nofault
 	for 5.4, apply: torvalds/linux@bd88bb5
 	for 4.x, apply: xiaomi-sdm678/android_kernel_xiaomi_mojito@424e21f
 	for any failures, just SKIP THIS or check dependency chain of, gregkh/linux@3d70818
 		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>
  • Loading branch information
backslashxx committed Mar 3, 2025
1 parent 65993e0 commit eab13a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
23 changes: 18 additions & 5 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions kernel/kernel_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
{
Expand Down

0 comments on commit eab13a4

Please sign in to comment.