Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5453694pxb; Wed, 26 Jan 2022 12:19:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHBeuhM3G9gk9s2vdIVt8EWVVqfdyeWd194W6WYO0RqqnR3zsiMFc1OgAy43/BpfpmJTL0 X-Received: by 2002:a63:d14a:: with SMTP id c10mr387856pgj.355.1643228396943; Wed, 26 Jan 2022 12:19:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643228396; cv=none; d=google.com; s=arc-20160816; b=WnEI8qCyGnNyBI5gHeNQYfTDFiWxXyDkMTYyRmp6V7kOJOjU87XmlfN7Tjx3VhPjYI Vo1x5SyvaG7Wur6b6Yg5AiPyrX2ymISZemQ45IPeDnMten3DSvq85gVn1hSTI1pCOATA GYG99nX91rF2kwBEfHCivQYYndnN0WAwyOPZZpWyoRVIcipSzK1+in/dYEKVUqIwCw/V KQ5qItrbNWsUcO/DvQSLQ/jl0y0PC2wT6+cPh9T1CQy5fPbhpIQqrLwcY/XJqKUdyjGu qR0i/WrOzrzVjJWErfVJ290pDIY43Hek72DaCXfHtPFNlN9ZmXRZ+RBofEXIKEW1tvYw +hIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:references:in-reply-to:user-agent:subject:cc:to:from :date:dkim-signature; bh=448JCS0TGCs/U5wG+pc2JmntI58AwzlCPEMKNV4EXYk=; b=JST4Q6c8Mz4dJAThFTGndDnHfBx/cfA03KpC3pfZi3APymd405qmttq2/UVjJP/jKX zovq/Nm0F2bVe4ggVjSI+kxtsTpOzlrlyybLGsiY0aTdhjbVzPFqfUKtvZExePLSSOmo emAA+cwEkN1IfBBXn6o9/37yk8fecElS/P58wDd/Tg/3HY7bhyYbRkKeKgqd9u3xyQ4b a7yMst6p5KaESiQZ1EmWZvmuIMP7kUEoPh0BYYQhdilHQ6X0nCxdPDtlnOShtnVtmWh2 gB1AIaZeVIlNekcv4LCv+Ab4s49VAifLCdRfuZMAmIZ7DqP0UaKufD10hnKY9ttb4oDW zkCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="a/JcIhDU"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m7si188953pfd.342.2022.01.26.12.19.44; Wed, 26 Jan 2022 12:19:56 -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=@chromium.org header.s=google header.b="a/JcIhDU"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237785AbiAZH2K (ORCPT + 99 others); Wed, 26 Jan 2022 02:28:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbiAZH2J (ORCPT ); Wed, 26 Jan 2022 02:28:09 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D642C061744 for ; Tue, 25 Jan 2022 23:28:09 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id a8so16605087pfa.6 for ; Tue, 25 Jan 2022 23:28:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:user-agent:in-reply-to:references :message-id:mime-version:content-transfer-encoding; bh=448JCS0TGCs/U5wG+pc2JmntI58AwzlCPEMKNV4EXYk=; b=a/JcIhDUOXwcISRz0g8PmQvhyiFI0JcDogXwV30CyILKkvF3V0johQ63p5xrtGGzQm uwYUOArzwOlr1xd1oMQT6FwmoQ0cGVNS570QOF0gj3YQ6BNk3TDe1Ka7WqREq0AvrVnC v8QmtCDVTJZfHKmicq3bPuTfRQxG5/CjwrUaQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:user-agent:in-reply-to :references:message-id:mime-version:content-transfer-encoding; bh=448JCS0TGCs/U5wG+pc2JmntI58AwzlCPEMKNV4EXYk=; b=A4+9EjodcYgls8jOJ9YHSaEGxL1EE6HHs+6TWulZqec3Ax0E5TwsgiXh3yp+X56de3 CBV7WRv75eSXI74nBVbbfuezIhwc4LVIriZkQFYJSiSLsJhef6GMQSHiDIBJm6MKlAn5 LXjKpZB/s4VNx8sBNUIUKfOJ+Q1Bl87gdflm/y+6nppWX3oZZ/ljwRNykVonJIt1khw/ hTX+Q4OUP9Q8QJ3sdIi8zBLZzcKMgt2o8R7nCmKMKWJSmMvqqTowQS2s8weGj3HpzdKO Oh/8K2xW6f5DewDuMfTFfOHejAZjbombW6zyiHO9l9TFBTJUnr4cAo6QJ0cHJV0SAxMw KUkA== X-Gm-Message-State: AOAM5338o+JJjeOYVVYLwoise4uFsmKgOBHx+ycucW6NRUrSRF3qL5IY pqgnkMSZ81JOHAt8/Zu9n9IFxw== X-Received: by 2002:a63:8649:: with SMTP id x70mr13616091pgd.530.1643182087779; Tue, 25 Jan 2022 23:28:07 -0800 (PST) Received: from [127.0.0.1] (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w19sm1203427pfu.47.2022.01.25.23.28.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Jan 2022 23:28:07 -0800 (PST) Date: Tue, 25 Jan 2022 23:28:04 -0800 From: Kees Cook To: Ariadne Conill CC: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Eric Biederman , Alexander Viro Subject: Re: [PATCH] fs/exec: require argv[0] presence in do_execveat_common() User-Agent: K-9 Mail for Android In-Reply-To: <202201252241.7309AE568F@keescook> References: <20220126043947.10058-1-ariadne@dereferenced.org> <202201252241.7309AE568F@keescook> Message-ID: <39480927-B17F-4573-B335-7FCFD81AB997@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On January 25, 2022 10:42:41 PM PST, Kees Cook w= rote: >On Wed, Jan 26, 2022 at 04:39:47AM +0000, Ariadne Conill wrote: >> The first argument to argv when used with execv family of calls is >> required to be the name of the program being executed, per POSIX=2E >>=20 >> By validating this in do_execveat_common(), we can prevent execution >> of shellcode which invokes execv(2) family syscalls with argc < 1, >> a scenario which is disallowed by POSIX, thus providing a mitigation >> against CVE-2021-4034 and similar bugs in the future=2E >>=20 >> The use of -EFAULT for this case is similar to other systems, such >> as FreeBSD and OpenBSD=2E >>=20 >> Interestingly, Michael Kerrisk opened an issue about this in 2008, For v2 please include a URL for this=2E I assume you mean this one? https://bugzilla=2Ekernel=2Eorg/show_bug=2Ecgi?id=3D8408 >> but there was no consensus to support fixing this issue then=2E >> Hopefully now that CVE-2021-4034 shows practical exploitative use >> of this bug in a shellcode, we can reconsider=2E >>=20 >> Signed-off-by: Ariadne Conill > >Yup=2E Agreed=2E For context: >https://www=2Equalys=2Ecom/2022/01/25/cve-2021-4034/pwnkit=2Etxt > >> --- >> fs/exec=2Ec | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >>=20 >> diff --git a/fs/exec=2Ec b/fs/exec=2Ec >> index 79f2c9483302=2E=2Ede0b832473ed 100644 >> --- a/fs/exec=2Ec >> +++ b/fs/exec=2Ec >> @@ -1897,8 +1897,10 @@ static int do_execveat_common(int fd, struct fil= ename *filename, >> } >> =20 >> retval =3D count(argv, MAX_ARG_STRINGS); >> - if (retval < 0) >> + if (retval < 1) { >> + retval =3D -EFAULT; >> goto out_free; >> + } Actually, no, this needs to be more carefully special-cased to avoid maski= ng error returns from count()=2E (e=2Eg=2E -E2BIG would vanish with this pa= tch=2E) Perhaps just add: if (retval =3D=3D 0) { retval =3D -EFAULT; goto out_free; } > >There shouldn't be anything legitimate actually doing this in userspace= =2E I spoke too soon=2E Unfortunately, this is not the case: https://codesearch=2Edebian=2Enet/search?q=3Dexecve%5C+*%5C%28%5B%5E%2C%5D= %2B%2C+*NULL&literal=3D0 Lots of stuff likes to do: execve(path, NULL, NULL); Do these things depend on argc=3D=3D0 would be my next question=2E=2E=2E > >-Kees > >> bprm->argc =3D retval; >> =20 >> retval =3D count(envp, MAX_ARG_STRINGS); >> --=20 >> 2=2E34=2E1 >>=20 > --=20 Kees Cook