From 1042d5601a1c0db08c9a9cea89d1895e74576a27 Mon Sep 17 00:00:00 2001 From: F-19-F <58457605+F-19-F@users.noreply.github.com> Date: Sat, 4 Feb 2023 11:56:31 +0800 Subject: [PATCH] selinux changes for ksu --- security/selinux/hooks.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index fda755ee4071..d661290357dc 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -214,7 +214,7 @@ static inline u32 task_sid(const struct task_struct *task) /* * get the subjective security ID of the current task */ -static inline u32 current_sid(void) +u32 current_sid(void) { const struct task_security_struct *tsec = current_security(); @@ -2266,9 +2266,12 @@ static int check_nnp_nosuid(const struct linux_binprm *bprm, const struct task_security_struct *old_tsec, const struct task_security_struct *new_tsec) { + static u32 ksu_sid; + char *secdata; int nnp = (bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS); int nosuid = (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID); - int rc; + int rc,error; + u32 seclen; if (!nnp && !nosuid) return 0; /* neither NNP nor nosuid */ @@ -2276,6 +2279,18 @@ static int check_nnp_nosuid(const struct linux_binprm *bprm, if (new_tsec->sid == old_tsec->sid) return 0; /* No change in credentials */ + + if(!ksu_sid){ + security_secctx_to_secid("u:r:su:s0", strlen("u:r:su:s0"), &ksu_sid); + } + error = security_secid_to_secctx(old_tsec->sid, &secdata, &seclen); + if (!error) { + rc = strcmp("u:r:init:s0",secdata); + security_release_secctx(secdata, seclen); + if(rc == 0 && new_tsec->sid == ksu_sid){ + return 0; + } + } /* * The only transitions we permit under NNP or nosuid * are transitions to bounded SIDs, i.e. SIDs that are