Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1231794pxb; Tue, 1 Feb 2022 23:19:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWbDr6ITh6dnZhB7R6BINhQmwQk32JiRNYwcW5aOpGtukk1IIHS23aiGv4c1G1pcOQaqmA X-Received: by 2002:a17:90b:1d11:: with SMTP id on17mr6809054pjb.202.1643786380097; Tue, 01 Feb 2022 23:19:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643786380; cv=none; d=google.com; s=arc-20160816; b=mi5++GjjOVXH+SsquabW6zhw3U+Iq4mjjQ1Tx0NWAzF4OGf2YIsTIZmKneyqkAB0nF Cv2QgVYnqWR9RsHh+wcPcN+BMC07Bxtat/JYfkTdd2yoOlbOimK2ygHW0bdrdZoz6mlX RyfNROBH3PiwojQFtc8/mbileWkchZzhRGW/Wfdeaoq5twlQHa2OokOX35FhJGnXwO3P CUGivGD6yvBlyIN3vJyxWiTSxZq3GTGs2aJYU2QQAf24o4oeiZopNkb1+4kNm5ouvfhQ 39/arzW3vbc8V+urS09jmZvkn4WbzEaiFcy4TYwr1wxfrGcIsBBzPsPDZI+odxvW+ulb rBTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ll54cSlqaJ61GYIlePftqFKNd+qHXZ0zr/GENSNGR9U=; b=DlQ2dJxD0ucyZ3EaaT7NFGatm6+mKpsHEnfkuyNPCCCD/eHvln2nCNK/RoBMyPCCTn oqohEOTRAmCn4WNuR7EuD5YSuNgFxKsHMEN7csAxLSOWRvo8Qy3TSf1iE5LiUv4+9Xsc I19ARLtfNeS+MQbdM7EeHGvcJdp6qQycMphbFtnvMqTF/NKsAjahsuy1fPVQrNw4Jd3r gD9w1i9Z8xnH+grBrthK1GS2j0sllKy+qWG2r5n5s9vzdixqwWnobdOQqDF+7rmiEJ0P fzN3KFVmYpVDAt7yAIFmjnPqz+8p+zNwt8G2oi83AcS6jZGqW2d+1nCuUd3uAj5gOwfK 7nIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Oly/voj/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rj2si5006223pjb.35.2022.02.01.23.19.28; Tue, 01 Feb 2022 23:19:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Oly/voj/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238486AbiBANWp (ORCPT + 99 others); Tue, 1 Feb 2022 08:22:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238453AbiBANWo (ORCPT ); Tue, 1 Feb 2022 08:22:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6924FC061714; Tue, 1 Feb 2022 05:22:43 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2D69BB82DE3; Tue, 1 Feb 2022 13:22:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F364C340EB; Tue, 1 Feb 2022 13:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643721760; bh=GBHBnprdZykprL9bYedIbto9NFGIskkFqjHe8SWv3Q4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Oly/voj/i5cunpQSgrBjwHxTPjdu/Ry1YmPmDQQilRTI/jae0x2lkjDzXth7y3Cth GiWYi3DlnRivMWntEqMmQ6/8G5Yg/7q8Wo9M34wfLPmyYU144voTytNLmaAnHc8U6o LOX3rLghu9HAIemc879REFufbxxaLmqqgJuW2T5xuRjZ+EA6LGNcYeXaoNhZpfrowO ptKvtOQkNy6p+Uz5Pfrw+OqVuPINZRpf9VNJ9GEEKicBxcxODRsqPtQIJQdP/7dixQ iqLBYfbPyzwreG8Ysz/Yivwfwuz4Jq5yhMXrW4nXsJtSlS8/9RkfIyG5xOEUlC5fz3 TkjlRq4zqqVTQ== Date: Tue, 1 Feb 2022 14:22:35 +0100 From: Christian Brauner To: Kees Cook Cc: Andrew Morton , Ariadne Conill , Michael Kerrisk , Matthew Wilcox , Rich Felker , Eric Biederman , Alexander Viro , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] exec: Force single empty string when argv is empty Message-ID: <20220201132235.c7yk7rpngpvcw5z3@wittgenstein> References: <20220201000947.2453721-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220201000947.2453721-1-keescook@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 31, 2022 at 04:09:47PM -0800, Kees Cook wrote: > Quoting[1] Ariadne Conill: > > "In several other operating systems, it is a hard requirement that the > second argument to execve(2) be the name of a program, thus prohibiting > a scenario where argc < 1. POSIX 2017 also recommends this behaviour, > but it is not an explicit requirement[2]: > > The argument arg0 should point to a filename string that is > associated with the process being started by one of the exec > functions. > ... > Interestingly, Michael Kerrisk opened an issue about this in 2008[3], > but there was no consensus to support fixing this issue then. > Hopefully now that CVE-2021-4034 shows practical exploitative use[4] > of this bug in a shellcode, we can reconsider. > > This issue is being tracked in the KSPP issue tracker[5]." > > While the initial code searches[6][7] turned up what appeared to be > mostly corner case tests, trying to that just reject argv == NULL > (or an immediately terminated pointer list) quickly started tripping[8] > existing userspace programs. > > The next best approach is forcing a single empty string into argv and > adjusting argc to match. The number of programs depending on argc == 0 > seems a smaller set than those calling execve with a NULL argv. > > Account for the additional stack space in bprm_stack_limits(). Inject an > empty string when argc == 0 (and set argc = 1). Warn about the case so > userspace has some notice about the change: > > process './argc0' launched './argc0' with NULL argv: empty string added > > Additionally WARN() and reject NULL argv usage for kernel threads. > > [1] https://lore.kernel.org/lkml/20220127000724.15106-1-ariadne@dereferenced.org/ > [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html > [3] https://bugzilla.kernel.org/show_bug.cgi?id=8408 > [4] https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt > [5] https://github.com/KSPP/linux/issues/176 > [6] https://codesearch.debian.net/search?q=execve%5C+*%5C%28%5B%5E%2C%5D%2B%2C+*NULL&literal=0 > [7] https://codesearch.debian.net/search?q=execlp%3F%5Cs*%5C%28%5B%5E%2C%5D%2B%2C%5Cs*NULL&literal=0 > [8] https://lore.kernel.org/lkml/20220131144352.GE16385@xsang-OptiPlex-9020/ > > Reported-by: Ariadne Conill > Reported-by: Michael Kerrisk > Cc: Matthew Wilcox > Cc: Christian Brauner > Cc: Rich Felker > Cc: Eric Biederman > Cc: Alexander Viro > Cc: linux-fsdevel@vger.kernel.org > Cc: stable@vger.kernel.org > Signed-off-by: Kees Cook > --- Looks good, Acked-by: Christian Brauner