linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] exec: NULL out bprm->argv0 when it is an ERR_PTR
@ 2024-11-05 18:19 Kees Cook
  2024-11-05 19:07 ` Tycho Andersen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kees Cook @ 2024-11-05 18:19 UTC (permalink / raw)
  To: Al Viro
  Cc: Kees Cook, syzbot+03e1af5c332f7e0eb84b, Christian Brauner,
	Jan Kara, Eric Biederman, linux-fsdevel, linux-mm,
	Tycho Andersen, Zbigniew Jędrzejewski-Szmek, linux-kernel,
	linux-hardening

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: syzbot+03e1af5c332f7e0eb84b@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/6729d8d1.050a0220.701a.0017.GAE@google.com
Fixes: 7bdc6fc85c9a ("exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case")
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
---
 fs/exec.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 79045c1d1608..65448ea609a2 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -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;
 }
-- 
2.34.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] exec: NULL out bprm->argv0 when it is an ERR_PTR
  2024-11-05 18:19 [PATCH] exec: NULL out bprm->argv0 when it is an ERR_PTR Kees Cook
@ 2024-11-05 19:07 ` Tycho Andersen
  2024-11-06  8:22 ` Kirill A. Shutemov
  2024-11-06  9:39 ` Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Tycho Andersen @ 2024-11-05 19:07 UTC (permalink / raw)
  To: Kees Cook
  Cc: Al Viro, syzbot+03e1af5c332f7e0eb84b, Christian Brauner,
	Jan Kara, Eric Biederman, linux-fsdevel, linux-mm,
	Tycho Andersen, Zbigniew Jędrzejewski-Szmek, linux-kernel,
	linux-hardening

On Tue, Nov 05, 2024 at 10:19:11AM -0800, Kees Cook wrote:
> 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: syzbot+03e1af5c332f7e0eb84b@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/6729d8d1.050a0220.701a.0017.GAE@google.com
> Fixes: 7bdc6fc85c9a ("exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case")
> Signed-off-by: Kees Cook <kees@kernel.org>

Reviewed-by: Tycho Andersen <tycho@tycho.pizza.

Thanks.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] exec: NULL out bprm->argv0 when it is an ERR_PTR
  2024-11-05 18:19 [PATCH] exec: NULL out bprm->argv0 when it is an ERR_PTR Kees Cook
  2024-11-05 19:07 ` Tycho Andersen
@ 2024-11-06  8:22 ` Kirill A. Shutemov
  2024-11-06  9:39 ` Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Kirill A. Shutemov @ 2024-11-06  8:22 UTC (permalink / raw)
  To: Kees Cook
  Cc: Al Viro, syzbot+03e1af5c332f7e0eb84b, Christian Brauner,
	Jan Kara, Eric Biederman, linux-fsdevel, linux-mm,
	Tycho Andersen, Zbigniew Jędrzejewski-Szmek, linux-kernel,
	linux-hardening

On Tue, Nov 05, 2024 at 10:19:11AM -0800, Kees Cook wrote:
> 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: syzbot+03e1af5c332f7e0eb84b@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/6729d8d1.050a0220.701a.0017.GAE@google.com
> Fixes: 7bdc6fc85c9a ("exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case")
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Jan Kara <jack@suse.cz>
> Cc: Eric Biederman <ebiederm@xmission.com>
> Cc: linux-fsdevel@vger.kernel.org
> Cc: linux-mm@kvack.org

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
  Kiryl Shutsemau / Kirill A. Shutemov


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] exec: NULL out bprm->argv0 when it is an ERR_PTR
  2024-11-05 18:19 [PATCH] exec: NULL out bprm->argv0 when it is an ERR_PTR Kees Cook
  2024-11-05 19:07 ` Tycho Andersen
  2024-11-06  8:22 ` Kirill A. Shutemov
@ 2024-11-06  9:39 ` Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2024-11-06  9:39 UTC (permalink / raw)
  To: Kees Cook
  Cc: Al Viro, syzbot+03e1af5c332f7e0eb84b, Jan Kara, Eric Biederman,
	linux-fsdevel, linux-mm, Tycho Andersen,
	Zbigniew Jędrzejewski-Szmek, linux-kernel, linux-hardening

On Tue, Nov 05, 2024 at 10:19:11AM -0800, Kees Cook wrote:
> 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: syzbot+03e1af5c332f7e0eb84b@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/6729d8d1.050a0220.701a.0017.GAE@google.com
> Fixes: 7bdc6fc85c9a ("exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case")
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---

Reviewed-by: Christian Brauner <brauner@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-11-06  9:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-05 18:19 [PATCH] exec: NULL out bprm->argv0 when it is an ERR_PTR Kees Cook
2024-11-05 19:07 ` Tycho Andersen
2024-11-06  8:22 ` Kirill A. Shutemov
2024-11-06  9:39 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox