From patchwork Tue Nov 5 18:19:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13863337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D46BD3177E for ; Tue, 5 Nov 2024 18:19:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C87C56B0085; Tue, 5 Nov 2024 13:19:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C36556B0089; Tue, 5 Nov 2024 13:19:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFE1C6B008A; Tue, 5 Nov 2024 13:19:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 90AC36B0085 for ; Tue, 5 Nov 2024 13:19:23 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3397F816E0 for ; Tue, 5 Nov 2024 18:19:23 +0000 (UTC) X-FDA: 82752852840.12.A14E4B2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 432AC140024 for ; Tue, 5 Nov 2024 18:18:56 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Wzta4frQ; spf=pass (imf26.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730830539; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=s2F9MMdFWO2HBMROgur2M56bEU4aN7EKyDY6YVDlLCc=; b=bEbTbsZ6OeclwYxPlLmEDT7f3kwtVLlV/MDyAK0u7EKeljy2N6wancS9H2jTsfPphwU2Bu KJT/cB1widHD65lWHdIBJEkhy71UMZm0zzyEq5St2ROyOcLluuObndYFqBfjhiZqIV9krv RjT1YEF3s85Ff8EfEjqICz+VRUINbmM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Wzta4frQ; spf=pass (imf26.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730830539; a=rsa-sha256; cv=none; b=YWkgV0JfxUVUN+3u4JtF30w4OZK6Lu6f3nmuJ6mPGiO6U5l71HWhMIWkzq7PRjo8g2DBa1 nJRkDKtOe/NgM0rQB0PT+vA62ako53E3wcLrueSD3Mv2O3kVS/XYdz6a4ZXXxYlDvt3iD8 zgwVjKqOvRvmntCGq8Z5Tfi3Wn9EtGM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CAF605C4BE6; Tue, 5 Nov 2024 18:18:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32F80C4CECF; Tue, 5 Nov 2024 18:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730830760; bh=KLo/rEHIE6am70Vo9zl892I6Woc0BURA4LAhcckibeU=; h=From:To:Cc:Subject:Date:From; b=Wzta4frQAfI+4x29xiW8d95oYiYMxDwzeUtVWVyxDS1oUTnFvakcknjMNjmV59u8x s6w5C7WqSSq5pm152rGl/d+Ns/2NXaRTkrTeFe4kMlW3/ugHTz/Iw9//DMH0TL043G WGWXmMW6T/oRX9lkWkk5VWWNEpssvtmrDa18Re9xeN/uOFm4VPEnrgIhkW2NCuSSTY sWg1NgdhxcjETb4r1O47SzSPTEFSihoziq/5Y5RVOuIjXFN5mHxzZ2Ik/lpoNU3T16 ThWrqxS5f8u/XdkUPaRQZHRJsv/njGi9uL6/eE8elHb4k0J3eIRjmO22YfB29R3Qco tf6VjvAeNvy5g== From: Kees Cook To: Al Viro Cc: Kees Cook , syzbot+03e1af5c332f7e0eb84b@syzkaller.appspotmail.com, Christian Brauner , Jan Kara , Eric Biederman , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Tycho Andersen , =?utf-8?q?Zbign?= =?utf-8?q?iew_J=C4=99drzejewski-Szmek?= , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] exec: NULL out bprm->argv0 when it is an ERR_PTR Date: Tue, 5 Nov 2024 10:19:11 -0800 Message-Id: <20241105181905.work.462-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1391; i=kees@kernel.org; h=from:subject:message-id; bh=KLo/rEHIE6am70Vo9zl892I6Woc0BURA4LAhcckibeU=; b=owGbwMvMwCVmps19z/KJym7G02pJDOlaifPnGyS82b/muRhXf1nrDL+nbivKFV8oKxtG8T/fs vIHt6hCRykLgxgXg6yYIkuQnXuci8fb9nD3uYowc1iZQIYwcHEKwES4rjL8lV0nvoYlzPJdBW/x 9vUhHHsKS4qPP2dLPv+y+69b4t/7mYwML71dr6nqdhzI+PWgVKKNuSjg68a+13YiemdmpygVVd7 mBAA= X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 432AC140024 X-Stat-Signature: w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gcI4xDJ9VEG1EKLEAr9uT0oipzpw4h74F3jial8KNI+dl7dJXzHreLwci0gGOH3XlqNTZoNUKJ8QDF8WZH5GXx1RQqYMMD8SAVVb3kQiT0S7KfWZkkP4qok1RD0qlOypbEol9T4qQz4O4GaD55Z9telPXX+SqkInPTZtszFvS2m2CYfPpiYy4dvSxffke7/w9wW0dJP9fM5TulfDXyIWEGJuRsRAjKifHhobXKdZTnBkTsNW23JNMX0oaOUz8FnnHCe32drTfgzT0KXyx+3jW+M47SxVeWYsq3w36p+3XPVGgsbMp8Jr1myAyywpOXLTkTbhhxNPjqWiFZ/VIC1ajxYke9ZmQkiccqZnZ2HCCpAoZGaA9bNA8lZRS8SofwLm7KrZ86pAQZ9NAxYAp72CqWqVNDVgd2QzzKViCiw1jf4Bh6VD3SIgsBPjSbvATRMFAnLpCBH47xoc7WyjP2mWM/az1o5eZyFb4Kc6EJymeSA6kid8+p/qCFlHPpxfU4eSkokBmnmb+Zol9EEqIabbWAR2VyPAGy1VMJZDI7+aqu3B3log46+t95eLzXkfFaApw10dVFxYw4bTO4eE2FDBAS8pQxexSyI+bOenE+pdkHjcaC9koiKfSpKwOQjoBWg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Reviewed-by: Tycho Andersen Reviewed-by: Christian Brauner --- Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman 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; }