Skip to content

Commit

Permalink
exec: Teach prepare_exec_creds how exec treats uids & gids
Browse files Browse the repository at this point in the history
It is almost possible to use the result of prepare_exec_creds with no
modifications during exec.  Update prepare_exec_creds to initialize
the suid and the fsuid to the euid, and the sgid and the fsgid to the
egid.  This is all that is needed to handle the common case of exec
when nothing special like a setuid exec is happening.

That this preserves the existing behavior of exec can be verified
by examing bprm_fill_uid and cap_bprm_set_creds.

This change makes it clear that the later parts of exec that
update bprm->cred are just need to handle special cases such
as setuid exec and change of domains.

Link: https://lkml.kernel.org/r/[email protected]
Acked-by: Linus Torvalds <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed May 20, 2020
1 parent b127c16 commit 87b047d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kernel/cred.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ struct cred *prepare_exec_creds(void)
new->process_keyring = NULL;
#endif

new->suid = new->fsuid = new->euid;
new->sgid = new->fsgid = new->egid;

return new;
}

Expand Down

0 comments on commit 87b047d

Please sign in to comment.