Add a flag preserve_creds that binfmt_misc can set to prevent credentials from being updated. This allows binfmt_misc to always call prepare_binprm. Allowing the credential computation logic to be consolidated. Not replacing the credentials with the interpreters credentials is safe because because an open file descriptor to the executable is passed to the interpreter. As the interpreter does not need to reopen the executable it is guaranteed to see the same file that exec sees.
Showing the changes to include/linux (1 of 3 files). Show all
Unified · Split
| @@ -26,6 +26,8 @@ struct linux_binprm { · 25 unmodified lines | ||
| 26 | 26 | unsigned long p; /* current top of mem */ |
| 27 | 27 | unsigned long argmin; /* rlimit marker for copy_strings() */ |
| 28 | 28 | unsigned int |
| 29 | + /* It is safe to use the creds of a script (see binfmt_misc) */ | |
| 30 | + preserve_creds:1, | |
| 29 | 31 | /* |
| 30 | 32 | * True if most recent call to security_bprm_set_creds |
| 31 | 33 | * resulted in elevated privileges. |