Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5504640pxb; Wed, 26 Jan 2022 13:37:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzr1OFHzV2S1HuCQBefP/4KYGB8uPaMRrgoYLldtk0wApT6OwppaYy0WBFlJeQRiZWe7Cuf X-Received: by 2002:a63:db03:: with SMTP id e3mr551275pgg.613.1643233037283; Wed, 26 Jan 2022 13:37:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643233037; cv=none; d=google.com; s=arc-20160816; b=rEsU+yUM+XOLfkuk6mhIhFMgCIz4mKq3OhsYrCpZShyUzx9W1EW99HnFi9QaWH3Wkc nwo5PMR+l03QFJiPmgn+Hq9oZsenhWCgD2DrjTZZR+l98UJCv+Mr0eMu80t7oZDTyvlI /ydNd9pbqoyzl21LyN18VcVUJ4lqQYORsNn4/SHeJt1iW6nZr71Z5bdzzb2himFi3Gwk ZiwyFP0L4bu++Q5Xppy9q63W5nxgj2HAw1JEvQcxJf70hcWe4+Ll6oDntXT+uC4aNt/1 rxe3ezXPs9IBc6lqhjKamg5cu8ka3gAQfmqznhh8hwV4MuiAGoPX/b+pjR0U6W3ywhew v1mg== 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=CFtOi7chIbKkPpzpTyQNMjLSqIWvdOnoFw9tu2h2FwM=; b=USw+nWZ3bqesvLUKLf7niuIC5xDTj5h91F7oXK2FCw6SG82IHNEz082Ujds/B01721 lagZ8n9xUeOV9pKcBmnu0mhMlkm/vXnl5YARxozhnzY3IHWvdfVnaFED8FkTHWNmuab8 friHkQwud1o15bO3CQJLsRk4FNornqFlKx1zAY9zilzh3HHOXUJsC6s7iC88VNiTqscp QVO3aU9jWWRaofe/hEAgb2i6qrpKaUAtjVXwT0gqDB6Svwf36nbcppOshenRGEaqcaPu 1YC7cKWueR+NGZaZvFwZevA90J5eLCuH+s+70x5KbseeJ+KnL/w5nA4WeBnERWt7JDtn qSEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=FJayuleE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kk2si4454898pjb.66.2022.01.26.13.37.04; Wed, 26 Jan 2022 13:37:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=FJayuleE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242267AbiAZOlD (ORCPT + 99 others); Wed, 26 Jan 2022 09:41:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242259AbiAZOk4 (ORCPT ); Wed, 26 Jan 2022 09:40:56 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3B92C06161C; Wed, 26 Jan 2022 06:40:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=CFtOi7chIbKkPpzpTyQNMjLSqIWvdOnoFw9tu2h2FwM=; b=FJayuleENqPAYh6qPPQIDr12gd cnkhWyeLZQtLieqUfbB0oOTkM9ItxqVnFWRKeAAmJ86m3rK1xuPSjVcDYYzwYXLHjyv0am6KS+uiW Tl3/zFHo6Pke/Qd4QOtPr+TywIwtBduBdT+cuRsbO7UTWQKyM0Txn7RrDuVCSpmS5MaGeQGZz0El2 MJkWdw83v2Bpq48HZLzWUGvD56h8J0q6HLpTO0yR1mKwPc/NN5F/DY9nRNWqJoXi24d+kklNQ0WMN at4eoZCpUgRELl+xwehk18Aco/VHy9RgZoaB0bWzjBTR+5eo0rlrxzx2pLHAJD2SoOAJacm85O4a5 wuGexQSA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nCjTh-00486l-HZ; Wed, 26 Jan 2022 14:40:53 +0000 Date: Wed, 26 Jan 2022 14:40:53 +0000 From: Matthew Wilcox To: Ariadne Conill Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Eric Biederman , Kees Cook , Alexander Viro Subject: Re: [PATCH v2] fs/exec: require argv[0] presence in do_execveat_common() Message-ID: References: <20220126114447.25776-1-ariadne@dereferenced.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220126114447.25776-1-ariadne@dereferenced.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 26, 2022 at 11:44:47AM +0000, Ariadne Conill wrote: > In several other operating systems, it is a hard requirement that the > first 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[0]: > > The argument arg0 should point to a filename string that is > associated with the process being started by one of the exec > functions. > > To ensure that execve(2) with argc < 1 is not a useful gadget for > shellcode to use, we can validate this in do_execveat_common() and > fail for this scenario, effectively blocking successful exploitation > of CVE-2021-4034 and similar bugs which depend on this gadget. > > The use of -EFAULT for this case is similar to other systems, such > as FreeBSD, OpenBSD and Solaris. QNX uses -EINVAL for this case. > > Interestingly, Michael Kerrisk opened an issue about this in 2008[1], > but there was no consensus to support fixing this issue then. > Hopefully now that CVE-2021-4034 shows practical exploitative use > of this bug in a shellcode, we can reconsider. > > [0]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html > [1]: https://bugzilla.kernel.org/show_bug.cgi?id=8408 > > Changes from v1: > - Rework commit message significantly. > - Make the argv[0] check explicit rather than hijacking the error-check > for count(). > > Signed-off-by: Ariadne Conill > --- > fs/exec.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/fs/exec.c b/fs/exec.c > index 79f2c9483302..e52c41991aab 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1899,6 +1899,10 @@ static int do_execveat_common(int fd, struct filename *filename, > retval = count(argv, MAX_ARG_STRINGS); > if (retval < 0) > goto out_free; > + if (retval == 0) { > + retval = -EFAULT; > + goto out_free; > + } I don't object to the concept, but it's a more common pattern in Linux to do this: retval = count(argv, MAX_ARG_STRINGS); + if (retval == 0) + retval = -EFAULT; if (retval < 0) goto out_free; (aka I like my bikesheds painted in Toasty Eggshell)