Skip to content

Commit

Permalink
selinux: add ksu allowance
Browse files Browse the repository at this point in the history
  • Loading branch information
naups committed Jul 5, 2024
1 parent 3838d05 commit edc1575
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
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 @@ -2318,16 +2318,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 = !mnt_may_suid(bprm->file->f_path.mnt);
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 edc1575

Please sign in to comment.