Skip to contentSkip to conversation

exec: NULL out bprm->argv0 when it is an ERR_PTR

PATCH In review Kees Cook 4 participants 4 messages Nov 5, 2024 – Nov 6, 2024

Subsystems (3)
lore
Share & tools
lore

Kees Cook

author maintainer
#0 lore raw

PATCH 1/1 exec: NULL out bprm->argv0 when it is an ERR_PTR

Attempting to free an ERR_PTR will not work. ;)

process 'syz-executor210' launched '/dev/fd/3' with NULL argv: empty string added kernel BUG at arch/x86/mm/physaddr.c:23!

Set bprm->argv0 to NULL if it fails to get a string from userspace so that bprm_free() will not try to free an invalid pointer when cleaning up.

Reported-by [email protected]
Fixes 7bdc6fc85c9a ("exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case")

---
Cc: Alexander Viro <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 fs/exec.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/exec.c +6 -2
index 79045c1d1608..65448ea609a2 100644
@@ -1522,8 +1522,12 @@ static int bprm_add_fixup_comm(struct linux_binprm *bprm,
 		return 0;
 
 	bprm->argv0 = strndup_user(p, MAX_ARG_STRLEN);
-	if (IS_ERR(bprm->argv0))
-		return PTR_ERR(bprm->argv0);
+	if (IS_ERR(bprm->argv0)) {
+		int rc = PTR_ERR(bprm->argv0);
+
+		bprm->argv0 = NULL;
+		return rc;
+	}
 
 	return 0;
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Kees Cook

Attempting to free an ERR_PTR will not work. ;)

process 'syz-executor210' launched '/dev/fd/3' with NULL argv: empty string added kernel BUG at arch/x86/mm/physaddr.c:23!

Quoted 7 lines

Set bprm->argv0 to NULL if it fails to get a string from userspace so that bprm_free() will not try to free an invalid pointer when cleaning up.

Reported-by [email protected]
Fixes 7bdc6fc85c9a ("exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case")

Thanks.

Acked-by on v1 1/1
#2 lore raw
In reply to Kees Cook
Quoted 12 lines · Kees Cook

Attempting to free an ERR_PTR will not work. ;)

process 'syz-executor210' launched '/dev/fd/3' with NULL argv: empty string added kernel BUG at arch/x86/mm/physaddr.c:23!

Set bprm->argv0 to NULL if it fails to get a string from userspace so that bprm_free() will not try to free an invalid pointer when cleaning up.

Reported-by [email protected]
Fixes 7bdc6fc85c9a ("exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case")
Quoted 7 lines

---
Cc: Alexander Viro <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: [email protected]
Cc: [email protected]

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Kees Cook
Quoted 5 lines · Kees Cook

Attempting to free an ERR_PTR will not work. ;)

process 'syz-executor210' launched '/dev/fd/3' with NULL argv: empty string added kernel BUG at arch/x86/mm/physaddr.c:23!

Quoted 8 lines

Set bprm->argv0 to NULL if it fails to get a string from userspace so that bprm_free() will not try to free an invalid pointer when cleaning up.

Reported-by [email protected]
Fixes 7bdc6fc85c9a ("exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case")

---