Skip to content

Commit 8e5cfdb

Browse files
F-19-Fbackslashxx
authored andcommitted
kernel: ksud: provide is_ksu_transition check
context: this is known by many as `selinux hook`, `4.9 hook` add is_ksu_transition check which allows ksud execution under nosuid. it also eases up integration on 3.X kernels that does not have check_nnp_nosuid. this also adds a `ksu_execveat_hook` check since this transition is NOT needed anymore once ksud ran. Usage: if (is_ksu_transition(old_tsec, new_tsec)) return 0; on either check_nnp_nosuid or selinux_bprm_set_creds (after execve sid reset) reference: https://github.com/backslashxx/msm8953-kernel/commits/dfe003c9fdfa394a2bffe74668987a19a0d2f546 taken from: `allow init exec ksud under nosuid` - LineageOS/android_kernel_oneplus_msm8998@3df9df4 - tiann#166 (comment) Signed-off-by: backslashxx <[email protected]>
1 parent 846624a commit 8e5cfdb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

kernel/ksud.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,32 @@ int ksu_handle_compat_execve_ksud(const char __user *filename_user,
531531
}
532532
#endif
533533

534+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
535+
#include "objsec.h" // task_security_struct
536+
bool is_ksu_transition(const struct task_security_struct *old_tsec,
537+
const struct task_security_struct *new_tsec)
538+
{
539+
static u32 ksu_sid;
540+
char *secdata;
541+
u32 seclen;
542+
bool allowed = false;
543+
544+
if (!ksu_execveat_hook) // not needed anymore once ksud ran
545+
return false;
546+
547+
if (!ksu_sid)
548+
security_secctx_to_secid("u:r:su:s0", strlen("u:r:su:s0"), &ksu_sid);
549+
550+
if (security_secid_to_secctx(old_tsec->sid, &secdata, &seclen))
551+
return false;
552+
553+
allowed = (!strcmp("u:r:init:s0", secdata) && new_tsec->sid == ksu_sid);
554+
security_release_secctx(secdata, seclen);
555+
556+
return allowed;
557+
}
558+
#endif
559+
534560
static void stop_vfs_read_hook()
535561
{
536562
ksu_vfs_read_hook = false;

0 commit comments

Comments
 (0)