Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5690190pxb; Wed, 26 Jan 2022 18:57:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzw81/NOMd7NqVS6gNc6SEYlFERXo1uVNpSc3noGeIRCmx6RoyluKtH3U+rru80QmkWFJuu X-Received: by 2002:a17:907:3e0c:: with SMTP id hp12mr1306398ejc.685.1643252269667; Wed, 26 Jan 2022 18:57:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643252269; cv=none; d=google.com; s=arc-20160816; b=RC2RMJOYPM204jf3e6p1YiTT+/TSU0Ihitks+bA+oSkIV2+ek7ISlOu0bHDNN0pNYs RhewgXBGsS1gKgbSXZeuWdHh7S3pacWLkz/2laIQ3d5Db4PtGQIUDBIpBd3xfjtGUGRn SKzyDu5xEqFb+dCnmq1zeBnotKbJwTet03rYaI/1SINvj6/mPOEFBqBiQ4ek6It9q1ZY d5plj3Ez/CxWn7XuUvZOB/5JrSt0NhuvBiy2QgkCrPt5pG7qc4WSbnqnlC5w30mJ6aX8 3Ve3mxSYxEGYX+lkK+Y4J5TzxC1uM58sbL0XUepFpoOdTcajs32Fa/2nr6mDEOiJj/V8 rj8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=Lw96g1yZaEdwr2m6O0x5UWFP2I+wjfm/wup46yFlBkI=; b=qW6w3f70bYvFvQRM58FHcUidMyUHCueBWSRsAlptaIZ//nNKFlo4ZnJb9qhGF3SR7F wVbcPOlSbScqGRcpDh0yV+AA35AehvvVoUzzHCiw6MiASPi46lh8lZkWcAFbFyFR4cxr iNC7Yis2S4lO8I61NkP5HsdmASX86JBto5aW8wyg0zdiH4zmOjZ1gXIDhyN/u+4QEIov Tv7tuo8cXZAUSFhcAzf1wbDA6mkZjDs6ADAsFdL/3I+GUCKfD4dQ2tDdvA04qAGjKj4p ylqRo14RSSCp1u5TXTMIJZFbloUoA4S4ljMdgEYNi5giwiRxuPqFAGbpVfxLl8k5WS/M 68/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dereferenced.org header.s=mailbun header.b=QSPTUoom; 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=dereferenced.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si623224ejo.223.2022.01.26.18.57.25; Wed, 26 Jan 2022 18:57:49 -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=@dereferenced.org header.s=mailbun header.b=QSPTUoom; 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=dereferenced.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231352AbiAZXHx (ORCPT + 99 others); Wed, 26 Jan 2022 18:07:53 -0500 Received: from mx1.mailbun.net ([170.39.20.100]:42888 "EHLO mx1.mailbun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229852AbiAZXHw (ORCPT ); Wed, 26 Jan 2022 18:07:52 -0500 Received: from [2607:fb90:d98b:8818:f877:8b4d:b8e:5ef5] (unknown [172.58.109.194]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ariadne@dereferenced.org) by mx1.mailbun.net (Postfix) with ESMTPSA id 4098911A817; Wed, 26 Jan 2022 23:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dereferenced.org; s=mailbun; t=1643238472; bh=4jbgQdEYB/Ogcs9D1+o31MmOrg2MwhNco7JGwQ6xy9w=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=QSPTUoomDAqer1KGHVfncm5b4qTeKVefbWYv/t88Dl6BoD1i4XrQJXAAKRv2WlBgw kmAz63xLLfDyC3lz1qW9caCHtb42xZkZ/OEErIZJuHNOhCpY68SWBeGqQpbl/kb+Ir 0QG3VKzwSFeFoqgX4vr/ikJvc3Qw49mkbhOAKuGWbRRhDL/4df3sUuYP5uNME52Cbt AhoFbMlCyyODAbcFbautiRTFpGKMyFo9Eb0zspWUDh4N1pFkjddkiSaEZfIRzwQNhV WLzGsIGgC/aDYJ3Gx9I7utgNfzAQod5iL3eZIbDAZHnCf26yAzIKScsewXua4HzFuz gD40nnVtDEbLg== Date: Wed, 26 Jan 2022 17:07:45 -0600 (CST) From: Ariadne Conill To: Kees Cook cc: Ariadne Conill , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Eric Biederman , Alexander Viro Subject: Re: [PATCH v2] fs/exec: require argv[0] presence in do_execveat_common() In-Reply-To: <202201261440.0C13601104@keescook> Message-ID: <85834b6e-a0e-eefc-7cf6-2ca37798cdf@dereferenced.org> References: <20220126114447.25776-1-ariadne@dereferenced.org> <202201261202.EC027EB@keescook> <202201261239.CB5D7C991A@keescook> <5e963fab-88d4-2039-1cf4-6661e9bd16b@dereferenced.org> <202201261323.9499FA51@keescook> <64e91dc2-7f5c-6e8-308e-414c82a8ae6b@dereferenced.org> <202201261440.0C13601104@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Wed, 26 Jan 2022, Kees Cook wrote: > On Wed, Jan 26, 2022 at 03:30:13PM -0600, Ariadne Conill wrote: >> Hi, >> >> On Wed, 26 Jan 2022, Kees Cook wrote: >> >>> On Wed, Jan 26, 2022 at 03:13:10PM -0600, Ariadne Conill wrote: >>>> Looks good to me, but I wonder if we shouldn't set an argv of >>>> {bprm->filename, NULL} instead of {"", NULL}. Discussion in IRC led to the >>>> realization that multicall programs will try to use argv[0] and might crash >>>> in this scenario. If we're going to fake an argv, I guess we should try to >>>> do it right. >>> >>> They're crashing currently, though, yes? I think the goal is to move >>> toward making execve(..., NULL, NULL) just not work at all. Using the >>> {"", NULL} injection just gets us closer to protecting a bad userspace >>> program. I think things _should_ crash if they try to start depending >>> on this work-around. >> >> Is there a reason to spawn a program, just to have it crash, rather than >> just denying it to begin with, though? > > I think the correct behavior here is to unconditionally reject a NULL > argv -- and I wish this had gotten fixed in 2008. :P Given the code we've > found that depends on NULL argv, I think we likely can't make the change > outright, so we're down this weird rabbit hole of trying to reject what we > can and create work-around behaviors for the cases that currently exist. > I think new users of the new work-around shouldn't be considered. We'd > prefer they get a rejection, etc. > >> I mean, it all seems fine enough, and perhaps I'm just a bit picky on the >> colors and flavors of my bikesheds, so if you want to go with this patch, >> I'll be glad to carry it in the Alpine security update I am doing to make >> sure the *other* GLib-using SUID programs people find don't get exploited in >> the same way. > > They "don't break userspace" guideline is really "don't break userspace > if someone notices". :P Since this is a mitigation (not strictly a > security flaw fix), changes to userspace behavior tend to be very > conservatively viewed by Linus. ;) > > My preference is the earlier very simple version to fix this: > > diff --git a/fs/exec.c b/fs/exec.c > index 79f2c9483302..aabadcf4a525 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1897,6 +1897,8 @@ static int do_execveat_common(int fd, struct filename *filename, > } > > retval = count(argv, MAX_ARG_STRINGS); > + if (reval == 0) > + retval = -EINVAL; > if (retval < 0) > goto out_free; > bprm->argc = retval; > > So, I guess we should start there and send a patch to valgrind? Yes, seems reasonable, though without the typo :) Since you've already written the patch, do you want to proceed with it? If so, I can work on the Valgrind tests. Ariadne