[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241105181905.work.462-kees@kernel.org>
Date: Tue, 5 Nov 2024 10:19:11 -0800
From: Kees Cook <kees@...nel.org>
To: Al Viro <viro@...iv.linux.org.uk>
Cc: Kees Cook <kees@...nel.org>,
syzbot+03e1af5c332f7e0eb84b@...kaller.appspotmail.com,
Christian Brauner <brauner@...nel.org>,
Jan Kara <jack@...e.cz>,
Eric Biederman <ebiederm@...ssion.com>,
linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org,
Tycho Andersen <tandersen@...flix.com>,
Zbigniew Jędrzejewski-Szmek <zbyszek@...waw.pl>,
linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: [PATCH] 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: syzbot+03e1af5c332f7e0eb84b@...kaller.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@...nel.org>
---
Cc: Alexander Viro <viro@...iv.linux.org.uk>
Cc: Christian Brauner <brauner@...nel.org>
Cc: Jan Kara <jack@...e.cz>
Cc: Eric Biederman <ebiederm@...ssion.com>
Cc: linux-fsdevel@...r.kernel.org
Cc: linux-mm@...ck.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
Powered by blists - more mailing lists