Skip to content

Commit

Permalink
selinux changes for ksu
Browse files Browse the repository at this point in the history
  • Loading branch information
F-19-F committed Feb 4, 2023
1 parent 3d9c79c commit 1042d56
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions security/selinux/hooks.c
Expand Up @@ -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();

Expand Down Expand Up @@ -2266,16 +2266,31 @@ 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 */

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
Expand Down

0 comments on commit 1042d56

Please sign in to comment.