Skip to contentSkip to conversation

exec: clarify reasoning for euid/egid reset

PATCH Superseded Kees Cook 3 participants 3 messages Apr 12, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 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.

---
 fs/exec.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/exec.c +6 -1
index c4010b8207a1..889221bbfdb3 100644
@@ -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 script then for its interpreter).
+	 */
 	bprm->cred->euid = current_euid();
 	bprm->cred->egid = current_egid();
 
Signature · 6 lines
2.6.3


-- 
Kees Cook
Chrome OS & Brillo Security
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Kees Cook

This section of code initially looks redundant, but is required. This improves the comment to explain more clearly why the reset is needed.

Thanks, Kees.

Quoted 29 lines
---
 fs/exec.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/exec.c +6 -1
index c4010b8207a1..889221bbfdb3 100644
@@ -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 script then for its interpreter).
+	 */
 	bprm->cred->euid = current_euid();
 	bprm->cred->egid = current_egid();
 
Signature · 6 lines
2.6.3


-- 
Kees Cook
Chrome OS & Brillo Security
#2 lore raw
In reply to Kees Cook

fs/exec.c static void bprm_fill_uid(struct linux_binprm *bprm) · line 1397

Quoted 9 lines · Kees Cook
fs/exec.c +6 -1
-	/* 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 script then for its interpreter).
+	 */
 	bprm->cred->euid = current_euid();
 	bprm->cred->egid = current_egid();

I would further add that this is where we deal with setuid scripts.

David