From nobody Wed Jan 26 20:02:03 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id B1FF319850FB; Wed, 26 Jan 2022 20:02:07 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from omta002.cacentral1.a.cloudfilter.net (omta002.cacentral1.a.cloudfilter.net [3.97.99.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JkZPV5mllz4rQH; Wed, 26 Jan 2022 20:02:06 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from shw-obgw-4004a.ext.cloudfilter.net ([10.228.9.227]) by cmsmtp with ESMTP id Ci12n0bM6yr5HCoUYnHOXW; Wed, 26 Jan 2022 20:02:06 +0000 Received: from spqr.komquats.com ([70.66.148.124]) by cmsmtp with ESMTPA id CoUWnBuhlviGhCoUXn1hSD; Wed, 26 Jan 2022 20:02:06 +0000 X-Authority-Analysis: v=2.4 cv=IaOU5Ema c=1 sm=1 tr=0 ts=61f1a8be a=Cwc3rblV8FOMdVN/wOAqyQ==:117 a=Cwc3rblV8FOMdVN/wOAqyQ==:17 a=kj9zAlcOel0A:10 a=DghFqjY3_ZEA:10 a=6I5d2MoRAAAA:8 a=YxBL1-UpAAAA:8 a=EkcXrb_YAAAA:8 a=aSK87Oe7N9jouBhdMrAA:9 a=CjuIK1q_8ugA:10 a=IjZwj45LgO3ly-622nXo:22 a=Ia-lj3WSrqcvXOmTRaiG:22 a=LK5xJRSDVpKd5WXXoEvA:22 Received: from slippy.cwsent.com (slippy [10.1.1.91]) by spqr.komquats.com (Postfix) with ESMTPS id 4CF8B3F3; Wed, 26 Jan 2022 12:02:03 -0800 (PST) Received: from slippy (localhost [127.0.0.1]) by slippy.cwsent.com (8.16.1/8.16.1) with ESMTP id 20QK23GH087609; Wed, 26 Jan 2022 12:02:03 -0800 (PST) (envelope-from Cy.Schubert@cschubert.com) Message-Id: <202201262002.20QK23GH087609@slippy.cwsent.com> X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.7.1 Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: Kyle Evans cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: 773fa8cd136a - main - execve: disallow argc == 0 In-reply-to: <202201261941.20QJfYf6038425@gitrepo.freebsd.org> References: <202201261941.20QJfYf6038425@gitrepo.freebsd.org> Comments: In-reply-to Kyle Evans message dated "Wed, 26 Jan 2022 19:41:34 +0000." List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 26 Jan 2022 12:02:03 -0800 X-CMAE-Envelope: MS4xfPsWX1ph17YI3T+wAdoxZ1gYLIX9N+yDmWY88dsRVwfw3RcsBBvfnaBTahJwKlXxwwx1d37T3lQy6a4uEoGM2ptqmnC4EqWWdTL+OwOlzNNFD6LMR7UQ 6ZMeDPMtVdrYXmg9tvj4gM4o9S3ObQoWKXNo5R4v1jvOmhGOTHxYpFIwkXEw00ukDa5njriul48KD/B6cLjC9onxqVwYshtC5xWTFaBq+1QE3CWadU4h5APD z4hPTZd+Z1Cdw4MvtfvWMEsVNDFXhXgVxDKkCShZDl0oXdIRRcDDBo7ROID/nwAVCXxAEQJ147E/1CtRmhUzEwV60Mdh0FMW6aMgNf2io28= X-Rspamd-Queue-Id: 4JkZPV5mllz4rQH X-Spamd-Bar: ++ Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of cy.schubert@cschubert.com has no SPF policy when checking 3.97.99.33) smtp.mailfrom=cy.schubert@cschubert.com X-Spamd-Result: default: False [2.78 / 15.00]; HAS_REPLYTO(0.00)[Cy.Schubert@cschubert.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_FIVE(0.00)[5]; REPLYTO_EQ_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; MV_CASE(0.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[cschubert.com: no valid DMARC record]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_SPAM_MEDIUM(1.00)[1.000]; AUTH_NA(1.00)[]; RCVD_IN_DNSWL_MED(-0.20)[3.97.99.33:from]; NEURAL_SPAM_LONG(1.00)[1.000]; NEURAL_HAM_SHORT(-0.42)[-0.418]; MLMMJ_DEST(0.00)[dev-commits-src-main,dev-commits-src-all]; R_SPF_NA(0.00)[no SPF record]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:16509, ipnet:3.96.0.0/15, country:US]; RCVD_TLS_LAST(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[70.66.148.124:received] X-ThisMailContainsUnwantedMimeParts: N In message <202201261941.20QJfYf6038425@gitrepo.freebsd.org>, Kyle Evans writes : > The branch main has been updated by kevans: > > URL: https://cgit.FreeBSD.org/src/commit/?id=773fa8cd136a5775241c3e3a70f19976 > 33ebeedf > > commit 773fa8cd136a5775241c3e3a70f1997633ebeedf > Author: Kyle Evans > AuthorDate: 2022-01-25 22:47:23 +0000 > Commit: Kyle Evans > CommitDate: 2022-01-26 19:40:27 +0000 > > execve: disallow argc == 0 > > The manpage has contained the following verbiage on the matter for just > under 31 years: > > "At least one argument must be present in the array" > > Previous to this version, it had been prefaced with the weakening phrase > "By convention." > > Carry through and document it the rest of the way. Allowing argc == 0 > has been a source of security issues in the past, and it's hard to > imagine a valid use-case for allowing it. Toss back EINVAL if we ended > up not copying in any args for *execve(). > > The manpage change can be considered "Obtained from: OpenBSD" > > Reviewed by: emaste, kib, markj (all previous version) > Differential Revision: https://reviews.freebsd.org/D34045 > --- > lib/libc/sys/execve.2 | 5 ++++- > sys/kern/kern_exec.c | 6 ++++++ > 2 files changed, 10 insertions(+), 1 deletion(-) > > diff --git a/lib/libc/sys/execve.2 b/lib/libc/sys/execve.2 > index a8f5aa14854b..1abadba13d91 100644 > --- a/lib/libc/sys/execve.2 > +++ b/lib/libc/sys/execve.2 > @@ -28,7 +28,7 @@ > .\" @(#)execve.2 8.5 (Berkeley) 6/1/94 > .\" $FreeBSD$ > .\" > -.Dd March 30, 2020 > +.Dd January 26, 2022 > .Dt EXECVE 2 > .Os > .Sh NAME > @@ -273,6 +273,9 @@ Search permission is denied for a component of the path p > refix. > The new process file is not an ordinary file. > .It Bq Er EACCES > The new process file mode denies execute permission. > +.It Bq Er EINVAL > +.Fa argv > +did not contain at least one element. > .It Bq Er ENOEXEC > The new process file has the appropriate access > permission, but has an invalid magic number in its header. > diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c > index 0494b73fc405..303c145689ae 100644 > --- a/sys/kern/kern_exec.c > +++ b/sys/kern/kern_exec.c > @@ -356,6 +356,12 @@ kern_execve(struct thread *td, struct image_args *args, > struct mac *mac_p, > exec_args_get_begin_envv(args) - args->begin_argv); > AUDIT_ARG_ENVV(exec_args_get_begin_envv(args), args->envc, > args->endp - exec_args_get_begin_envv(args)); > + > + /* Must have at least one argument. */ > + if (args->argc == 0) { > + exec_free_args(args); > + return (EINVAL); > + } > return (do_execve(td, args, mac_p, oldvmspace)); > } > > Thank you. I think this might help me track down a bug in a port. Can we MFC this at some point? -- Cheers, Cy Schubert FreeBSD UNIX: Web: https://FreeBSD.org NTP: Web: https://nwtime.org The need of the many outweighs the greed of the few.