From: Bernd Edlinger Date: Mon, 22 Jan 2024 18:34:21 +0000 (+0100) Subject: exec: Fix error handling in begin_new_exec() X-Git-Tag: v6.7.3~117 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=69a6f8ee9da574166a907997c8524dd8b000aafb;p=thirdparty%2Fkernel%2Fstable.git exec: Fix error handling in begin_new_exec() commit 84c39ec57d409e803a9bb6e4e85daf1243e0e80b upstream. If get_unused_fd_flags() fails, the error handling is incomplete because bprm->cred is already set to NULL, and therefore free_bprm will not unlock the cred_guard_mutex. Note there are two error conditions which end up here, one before and one after bprm->cred is cleared. Fixes: b8a61c9e7b4a ("exec: Generic execfd support") Signed-off-by: Bernd Edlinger Acked-by: Eric W. Biederman Link: https://lore.kernel.org/r/AS8P193MB128517ADB5EFF29E04389EDAE4752@AS8P193MB1285.EURP193.PROD.OUTLOOK.COM Cc: stable@vger.kernel.org Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/exec.c b/fs/exec.c index 4aa19b24f2810..6d9ed2d765efe 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1408,6 +1408,9 @@ int begin_new_exec(struct linux_binprm * bprm) out_unlock: up_write(&me->signal->exec_update_lock); + if (!bprm->cred) + mutex_unlock(&me->signal->cred_guard_mutex); + out: return retval; }