Skip to content

Commit 498b580

Browse files
F-19-Fbackslashxx
authored andcommitted
kernel: ksud: provide is_ksu_transition check v2
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. 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) 250611-edit: - remove ksu_execveat_hook entry check - turns out some devices needs the transition for multiple times Reported-by: edenadversary <[email protected]> Signed-off-by: backslashxx <[email protected]>
1 parent d4bb5f7 commit 498b580

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

kernel/ksud.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,29 @@ bool ksu_is_safe_mode()
432432
return false;
433433
}
434434

435+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
436+
#include "objsec.h" // task_security_struct
437+
bool is_ksu_transition(const struct task_security_struct *old_tsec,
438+
const struct task_security_struct *new_tsec)
439+
{
440+
static u32 ksu_sid;
441+
char *secdata;
442+
u32 seclen;
443+
bool allowed = false;
444+
445+
if (!ksu_sid)
446+
security_secctx_to_secid("u:r:su:s0", strlen("u:r:su:s0"), &ksu_sid);
447+
448+
if (security_secid_to_secctx(old_tsec->sid, &secdata, &seclen))
449+
return false;
450+
451+
allowed = (!strcmp("u:r:init:s0", secdata) && new_tsec->sid == ksu_sid);
452+
security_release_secctx(secdata, seclen);
453+
454+
return allowed;
455+
}
456+
#endif
457+
435458
static void stop_vfs_read_hook()
436459
{
437460
ksu_vfs_read_hook = false;

0 commit comments

Comments
 (0)