From: Kees Cook Date: Tue, 17 May 2016 19:14:39 +0000 (-0700) Subject: exec: clarify reasoning for euid/egid reset X-Git-Tag: v4.9.8~2121 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb6fd68fdd4a94880a99ad8515844c7a25e50d3e;p=platform%2Fkernel%2Flinux-rpi3.git exec: clarify reasoning for euid/egid reset 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 Acked-by: Serge E. Hallyn Signed-off-by: Linus Torvalds --- diff --git a/fs/exec.c b/fs/exec.c index c4010b8..a98b21d4 100644 --- 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();