Skip to content

Commit 5aa5a5a

Browse files
committed
kernel: core_hook: intercept devpts via security_inode_permission LSM
`ksu handles devpts with selinux lsm hook` - aviraxp - no, not yet, but yes we can, thats a good idea. This change tries to do that, so instead of hooking pts_unix98_lookup or devpts_get_priv, we just watch security_inode_permission, if its devpts, pass it along to the original handler. Tested-by: alternoegraha <[email protected]> Tested-by: AzyrRuthless <[email protected]> Signed-off-by: backslashxx <[email protected]>
1 parent ac4bbae commit 5aa5a5a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

kernel/core_hook.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,19 @@ LSM_HANDLER_TYPE ksu_sb_mount(const char *dev_name, const struct path *path,
684684
}
685685
}
686686

687+
extern int ksu_handle_devpts(struct inode *inode); // sucompat.c
688+
689+
LSM_HANDLER_TYPE ksu_inode_permission(struct inode *inode, int mask)
690+
{
691+
if (inode && inode->i_sb && unlikely(inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC)) {
692+
#ifdef CONFIG_KSU_DEBUG
693+
pr_info("%s: handling devpts for: %s \n", __func__, current->comm);
694+
#endif
695+
ksu_handle_devpts(inode);
696+
}
697+
return 0;
698+
}
699+
687700
// kernel 4.9 and older
688701
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
689702
LSM_HANDLER_TYPE ksu_key_permission(key_ref_t key_ref, const struct cred *cred,
@@ -727,6 +740,7 @@ static struct security_hook_list ksu_hooks[] = {
727740
LSM_HOOK_INIT(inode_rename, ksu_inode_rename),
728741
LSM_HOOK_INIT(task_fix_setuid, ksu_task_fix_setuid),
729742
LSM_HOOK_INIT(sb_mount, ksu_sb_mount),
743+
LSM_HOOK_INIT(inode_permission, ksu_inode_permission),
730744
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
731745
LSM_HOOK_INIT(key_permission, ksu_key_permission)
732746
#endif

0 commit comments

Comments
 (0)