Skip to content

Commit 3bbeeb3

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. Discussion: tiann#1249 tiann#1346 References: tiann@f57d351 tiann@b61cb30 Credits to respective authors: rhjdvsgsgks ExtremeXT Reviewed-by: Alex <[email protected]> Co-Authored-By: ExtremeXT <[email protected]> Signed-off-by: backslashxx <[email protected]>
1 parent 622706e commit 3bbeeb3

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
@@ -16,4 +16,12 @@ config KSU_DEBUG
1616
help
1717
Enable KernelSU debug mode.
1818

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

kernel/core_hook.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ static int ksu_task_prctl(int option, unsigned long arg2, unsigned long arg3,
648648
return -ENOSYS;
649649
}
650650
// kernel 4.4 and 4.9
651-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
651+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
652652
static int ksu_key_permission(key_ref_t key_ref, const struct cred *cred,
653653
unsigned perm)
654654
{
@@ -681,7 +681,7 @@ static struct security_hook_list ksu_hooks[] = {
681681
LSM_HOOK_INIT(task_prctl, ksu_task_prctl),
682682
LSM_HOOK_INIT(inode_rename, ksu_inode_rename),
683683
LSM_HOOK_INIT(task_fix_setuid, ksu_task_fix_setuid),
684-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
684+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
685685
LSM_HOOK_INIT(key_permission, ksu_key_permission)
686686
#endif
687687
};

kernel/kernel_compat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "klog.h" // IWYU pragma: keep
1111
#include "kernel_compat.h" // Add check Huawei Device
1212

13-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
13+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
1414
#include <linux/key.h>
1515
#include <linux/errno.h>
1616
#include <linux/cred.h>
@@ -79,7 +79,7 @@ void ksu_android_ns_fs_check()
7979

8080
struct file *ksu_filp_open_compat(const char *filename, int flags, umode_t mode)
8181
{
82-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
82+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
8383
if (init_session_keyring != NULL && !current_cred()->session_keyring &&
8484
(current->flags & PF_WQ_WORKER)) {
8585
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
@@ -24,7 +24,7 @@ extern long ksu_strncpy_from_user_nofault(char *dst,
2424
const void __user *unsafe_addr,
2525
long count);
2626

27-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI)
27+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_IS_HW_HISI) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
2828
extern struct key *init_session_keyring;
2929
#endif
3030

0 commit comments

Comments
 (0)