Skip to content

Commit 6ea6ed8

Browse files
committed
kernel: safe and small changes for UL support
Safe Ultra-Legacy changes that don't deserve their own commit d_is_reg requires 4.0 - torvalds/linux@e36cb0b IS_REG is still there on 6.15 so I do NOT see any issues forcing it for all. strscpy requires 4.3 strscpy on this usage can be replaced with strncpy + null term. kernel gives us an option though. strlcpy is fast af, hotrod fast. It’s just memcpy + null term, so lets go with that. it got dropped in 6.8 due to risk concerns, so for those, lets use og strscpy. ref: openwrt/packages #26453 cred->session_keyring -> cred->tgcred->session_keyring ref: https://elixir.bootlin.com/linux/v3.8/source/include/linux/cred.h https://elixir.bootlin.com/linux/v3.7/source/include/linux/cred.h Makefile: remove overlayfs dependency - not needed with magic mount Signed-off-by: backslashxx <[email protected]>
1 parent 8e5cfdb commit 6ea6ed8

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

kernel/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ menu "KernelSU"
22

33
config KSU
44
bool "KernelSU function support"
5-
depends on OVERLAY_FS
65
default y
76
help
87
Enable kernel-level root privileges on Android System.

kernel/core_hook.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,11 @@ LSM_HANDLER_TYPE ksu_key_permission(key_ref_t key_ref, const struct cred *cred,
703703
// we are only interested in `init` process
704704
return 0;
705705
}
706+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)
706707
init_session_keyring = cred->session_keyring;
708+
#else
709+
init_session_keyring = cred->tgcred->session_keyring;
710+
#endif
707711
pr_info("kernel_compat: got init_session_keyring\n");
708712
return 0;
709713
}

kernel/kernel_compat.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ void ksu_android_ns_fs_check()
7979
struct file *ksu_filp_open_compat(const char *filename, int flags, umode_t mode)
8080
{
8181
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
82-
if (init_session_keyring != NULL && !current_cred()->session_keyring &&
82+
if (init_session_keyring != NULL &&
83+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)
84+
!current_cred()->session_keyring &&
85+
#else
86+
!current_cred()->tgcred->session_keyring &&
87+
#endif
8388
(current->flags & PF_WQ_WORKER)) {
8489
pr_info("installing init session keyring for older kernel\n");
8590
install_session_keyring(init_session_keyring);

kernel/ksud.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr,
352352
return 0;
353353
}
354354

355-
if (!d_is_reg(file->f_path.dentry)) {
355+
if (!S_ISREG(file->f_path.dentry->d_inode->i_mode)) {
356356
return 0;
357357
}
358358

kernel/throne_tracker.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ FILLDIR_RETURN_TYPE my_actor(struct dir_context *ctx, const char *name,
174174
return FILLDIR_ACTOR_CONTINUE;
175175
}
176176

177+
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 8, 0)
178+
strlcpy(data->dirpath, dirpath, DATA_PATH_LEN);
179+
#else
177180
strscpy(data->dirpath, dirpath, DATA_PATH_LEN);
181+
#endif
178182
data->depth = my_ctx->depth - 1;
179183
list_add_tail(&data->list, my_ctx->data_path_list);
180184
} else {
@@ -230,7 +234,11 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
230234

231235
// First depth
232236
struct data_path data;
237+
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 8, 0)
238+
strlcpy(data.dirpath, path, DATA_PATH_LEN);
239+
#else
233240
strscpy(data.dirpath, path, DATA_PATH_LEN);
241+
#endif
234242
data.depth = depth;
235243
list_add_tail(&data.list, &data_path_list);
236244

0 commit comments

Comments
 (0)