Skip to content

Commit 9057f95

Browse files
rhjdvsgsgksExtremeXT
authored andcommitted
kernel: expose allowlist workaround as Kconfig option
Useful for situations where the SU allowlist is not kept after a reboot. As per upstream this is only used for < 4.10 and Huawei HiSilicon devices. but theres user reports having issues even on 4.14/4.19 samsung kernels. Expose this option so users affected can opt-in. This supercedes ` kernel:Add Huawei hisi check (tiann#1545) ` References: tiann@f57d351 tiann@b61cb30 Reviewed-by: Alex <[email protected]> Signed-off-by: backslashxx <[email protected]> Co-Authored-By: ExtremeXT <[email protected]>
1 parent 7b4a041 commit 9057f95

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

kernel/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ config KSU_DEBUG
1414
help
1515
Enable KernelSU debug mode.
1616

17+
config KSU_ALLOWLIST_WORKAROUND
18+
bool "KernelSU Session Keyring Init workaround"
19+
depends on KSU
20+
default n
21+
help
22+
Enable session keyring init workaround for problematic devices.
23+
Useful for situations where the SU allowlist is not kept after a reboot.
24+
1725
endmenu

kernel/core_hook.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ static int ksu_task_prctl(int option, unsigned long arg2, unsigned long arg3,
610610
return -ENOSYS;
611611
}
612612
// kernel 4.4 and 4.9
613-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
613+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
614614
static int ksu_key_permission(key_ref_t key_ref, const struct cred *cred,
615615
unsigned perm)
616616
{
@@ -642,7 +642,7 @@ static struct security_hook_list ksu_hooks[] = {
642642
LSM_HOOK_INIT(task_prctl, ksu_task_prctl),
643643
LSM_HOOK_INIT(inode_rename, ksu_inode_rename),
644644
LSM_HOOK_INIT(task_fix_setuid, ksu_task_fix_setuid),
645-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
645+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
646646
LSM_HOOK_INIT(key_permission, ksu_key_permission)
647647
#endif
648648
};

kernel/kernel_compat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <linux/uaccess.h>
1010
#include "klog.h" // IWYU pragma: keep
1111

12-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
12+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
1313
#include "linux/key.h"
1414
#include "linux/errno.h"
1515
#include "linux/cred.h"
@@ -78,7 +78,7 @@ void ksu_android_ns_fs_check()
7878

7979
struct file *ksu_filp_open_compat(const char *filename, int flags, umode_t mode)
8080
{
81-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
81+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
8282
if (init_session_keyring != NULL && !current_cred()->session_keyring &&
8383
(current->flags & PF_WQ_WORKER)) {
8484
pr_info("installing init session keyring for older kernel\n");

kernel/kernel_compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern long ksu_strncpy_from_user_nofault(char *dst,
1010
const void __user *unsafe_addr,
1111
long count);
1212

13-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
13+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
1414
extern struct key *init_session_keyring;
1515
#endif
1616

0 commit comments

Comments
 (0)