exec: clarify reasoning for euid/egid reset
authorKees Cook <keescook@chromium.org>
Tue, 17 May 2016 19:14:39 +0000 (12:14 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 17 May 2016 20:56:53 +0000 (13:56 -0700)
This section of code initially looks redundant, but is required. This
improves the comment to explain more clearly why the reset is needed.

Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/exec.c

index c4010b8207a144303ba498269427e42de1c72336..a98b21d473855869fac9d9214dc14bf08218a33d 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1387,7 +1387,12 @@ static void bprm_fill_uid(struct linux_binprm *bprm)
        kuid_t uid;
        kgid_t gid;
 
-       /* clear any previous set[ug]id data from a previous binary */
+       /*
+        * Since this can be called multiple times (via prepare_binprm),
+        * we must clear any previous work done when setting set[ug]id
+        * bits from any earlier bprm->file uses (for example when run
+        * first for a setuid script then again for its interpreter).
+        */
        bprm->cred->euid = current_euid();
        bprm->cred->egid = current_egid();