Skip to content

Commit 846624a

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 418b5d8 commit 846624a

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
@@ -678,6 +678,19 @@ LSM_HANDLER_TYPE ksu_sb_mount(const char *dev_name, const struct path *path,
678678
}
679679
}
680680

681+
extern int ksu_handle_devpts(struct inode *inode); // sucompat.c
682+
683+
LSM_HANDLER_TYPE ksu_inode_permission(struct inode *inode, int mask)
684+
{
685+
if (inode && inode->i_sb && unlikely(inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC)) {
686+
#ifdef CONFIG_KSU_DEBUG
687+
pr_info("%s: handling devpts for: %s \n", __func__, current->comm);
688+
#endif
689+
ksu_handle_devpts(inode);
690+
}
691+
return 0;
692+
}
693+
681694
// kernel 4.9 and older
682695
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
683696
LSM_HANDLER_TYPE ksu_key_permission(key_ref_t key_ref, const struct cred *cred,
@@ -721,6 +734,7 @@ static struct security_hook_list ksu_hooks[] = {
721734
LSM_HOOK_INIT(inode_rename, ksu_inode_rename),
722735
LSM_HOOK_INIT(task_fix_setuid, ksu_task_fix_setuid),
723736
LSM_HOOK_INIT(sb_mount, ksu_sb_mount),
737+
LSM_HOOK_INIT(inode_permission, ksu_inode_permission),
724738
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || defined(CONFIG_KSU_ALLOWLIST_WORKAROUND)
725739
LSM_HOOK_INIT(key_permission, ksu_key_permission)
726740
#endif

0 commit comments

Comments
 (0)