Skip to content

Commit eae4393

Browse files
committed
kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
disabling this removes the need for LSM_HOOK_INIT, security_add_hooks and such, furthermore, this will also allow easier integration on pre-4.1 kernels, this change just exposes this and makes it a configurable option. Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
1 parent 4f80d32 commit eae4393

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

kernel/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ config KSU_ALLOWLIST_WORKAROUND
2222
Enable session keyring init workaround for problematic devices.
2323
Useful for situations where the SU allowlist is not kept after a reboot.
2424

25+
config KSU_LSM_SECURITY_HOOKS
26+
bool "use lsm security hooks"
27+
depends on KSU
28+
default y
29+
help
30+
Disabling this is mostly only useful for kernel 4.1 and older.
31+
Make sure to implement manual hooks on security/security.c.
32+
2533
endmenu

kernel/core_hook.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include <linux/init.h>
66
#include <linux/init_task.h>
77
#include <linux/kernel.h>
8+
9+
#ifdef CONFIG_KSU_LSM_SECURITY_HOOKS
810
#include <linux/lsm_hooks.h>
11+
#endif
12+
913
#include <linux/nsproxy.h>
1014
#include <linux/path.h>
1115
#include <linux/printk.h>
@@ -607,15 +611,9 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
607611
return 0;
608612
}
609613

610-
static int ksu_task_prctl(int option, unsigned long arg2, unsigned long arg3,
611-
unsigned long arg4, unsigned long arg5)
612-
{
613-
ksu_handle_prctl(option, arg2, arg3, arg4, arg5);
614-
return -ENOSYS;
615-
}
616-
// kernel 4.4 and 4.9
614+
// kernel 4.9 and older
617615
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
618-
static int ksu_key_permission(key_ref_t key_ref, const struct cred *cred,
616+
int ksu_key_permission(key_ref_t key_ref, const struct cred *cred,
619617
unsigned perm)
620618
{
621619
if (init_session_keyring != NULL) {
@@ -630,6 +628,15 @@ static int ksu_key_permission(key_ref_t key_ref, const struct cred *cred,
630628
return 0;
631629
}
632630
#endif
631+
632+
#ifdef CONFIG_KSU_LSM_SECURITY_HOOKS
633+
static int ksu_task_prctl(int option, unsigned long arg2, unsigned long arg3,
634+
unsigned long arg4, unsigned long arg5)
635+
{
636+
ksu_handle_prctl(option, arg2, arg3, arg4, arg5);
637+
return -ENOSYS;
638+
}
639+
633640
static int ksu_inode_rename(struct inode *old_inode, struct dentry *old_dentry,
634641
struct inode *new_inode, struct dentry *new_dentry)
635642
{
@@ -665,3 +672,9 @@ void __init ksu_core_init(void)
665672
{
666673
ksu_lsm_hook_init();
667674
}
675+
#else
676+
void __init ksu_core_init(void)
677+
{
678+
pr_info("ksu_core_init: LSM hooks not in use.\n");
679+
}
680+
#endif //CONFIG_KSU_LSM_SECURITY_HOOKS

0 commit comments

Comments
 (0)