From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=BXfUXGn2; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 8C1BA5A0265 for ; Wed, 20 May 2026 14:52:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779281574; bh=obKwoXeV/Ic1lkrolaJy3FIR7Hq9YrkVqMXpnulHBOA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BXfUXGn2hVIM8jPpXNJvYbHIhzAEuwaPcRZdNKxETRqWpJ4faMDjA4tRLhe/8UFu6 O+/6GKB4YX9zup2Cha23Sz0bPP3sCr9lneQj7CDlPmnVCFYw0k7jQGYBJJnKUi9qjg xfShAqLOSuseXc68MIdGRqjQ6mOENcMahDbNcnTYUkag/ldStC7oZipH/Ixe8FqGHF VtAY4EIjHsg0UmaJMcUVq4quzJNSt6JsGOZOXU8rA7V2czqwei9dbx8kW8L9DDZg/O xCNW9HXDrfXuSa3QTSVaAhOMSF1C0shhN6Tlqrkt6DXNt8QJNJK5xsUERglcvfpdIk HyfVPOnifv1cQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gLBKL31BGz598Y; Wed, 20 May 2026 22:52:54 +1000 (AEST) Date: Wed, 20 May 2026 22:52:47 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 1/3] treewide: Add SOCK_CLOEXEC to accept() calls that are missing it Message-ID: References: <20260513041423.2446716-1-david@gibson.dropbear.id.au> <20260513041423.2446716-2-david@gibson.dropbear.id.au> <20260516174610.3ee899b5@elisabeth> <20260520023701.42418996@elisabeth> <20260520133647.29f92058@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="FEoKoe2EYHy/dbnC" Content-Disposition: inline In-Reply-To: <20260520133647.29f92058@elisabeth> Message-ID-Hash: 7ZKKIRQJAHRUIYV6WQEMR3NTSG5O4ZRW X-Message-ID-Hash: 7ZKKIRQJAHRUIYV6WQEMR3NTSG5O4ZRW X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --FEoKoe2EYHy/dbnC Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 20, 2026 at 01:36:48PM +0200, Stefano Brivio wrote: > On Wed, 20 May 2026 11:04:58 +1000 > David Gibson wrote: >=20 > > On Wed, May 20, 2026 at 02:37:02AM +0200, Stefano Brivio wrote: > > > On Mon, 18 May 2026 12:28:57 +1000 > > > David Gibson wrote: > > > =20 > > > > On Sat, May 16, 2026 at 05:46:11PM +0200, Stefano Brivio wrote: =20 > > > > > On Wed, 13 May 2026 14:14:21 +1000 > > > > > David Gibson wrote: > > > > > =20 > > > > > > Generally we try to set the O_CLOEXEC flag on every fd we creat= e. This > > > > > > seems to be generally accepted security best practice these day= s, and we > > > > > > never fork(), so certainly have no need to pass fds to children= =2E =20 > > > > >=20 > > > > > But we do clone() with CLONE_FILES (even though when we clone() t= o call > > > > > execvp() later, we don't set CLONE_FILES), so, even though I don'= t see > > > > > a reason to skip O_CLOEXEC for c->fd_tap, this conclusion shouldn= 't be > > > > > automatic from the fact we don't fork(). =20 > > > >=20 > > > > So, I did think about that when wrote it, but went for the short > > > > version rather than saying clone() with CLONE_FILES doesn't count. > > > >=20 > > > > Now, I realised that we've both fallen for the trap again, forgetti= ng > > > > that this has nothing to do with fork() or clone() and is, as it sa= ys > > > > right there in the name, about exec(). =20 > > >=20 > > > No, wait, I didn't fall for it, not this time. :) That's why I was > > > mentioning that when we call clone() and execvp() later (which would = be =20 > >=20 > > Uh...? I'm pretty sure the only execve(2) in the entire program is > > where we spawn passt.avx2. That's essentially the very first thing we > > do, long before this point. >=20 > Well, grep would beg to differ, as we don't call execve() at all, but: I meant the system call execve(2), which execv() and execvp() are library wrappers around. > $ grep execv *.c | grep -v qrap > arch.c: execv(new_path, argv); > pasta.c: execvp(a->exe, a->argv); Ah, I did miss the one in pasta_spawn_cmd(). Of course, we definitely don't want to leak our internal fds into the spawned command, so CLOEXEC is what we want. > O_CLOEXEC (or lack thereof) also matters on execvp(). >=20 > > > the only path that matters), we don't set CLONE_FILES anyway. =20 > >=20 > > CLONE_FILES is irrelevant, it's lost during execve(2). >=20 > Yes, but if you first clone(), which we actually do before calling > pasta_spawn_cmd(), and then execvp(), CLONE_FILES on clone() *would* > matter, because the cloned process would inherit the open files, and > the process started by execvp() would then get those files as well. No, it doesn't matter. If you clone() without CLONE_FILES, the new thread/process gets a copy of the handles, which do or don't survive exec() depending on O_CLOEXEC. If you clone with CLONE_FILES, the new process shares the fd table. The fd table is unshared again as part of the exec(). =46rom execve(2): > =E2=80=A2 The file descriptor table is unshared, undoing the effe= ct of the CLONE_FILES flag of clone(2). =2E. then the now copied files do or don't survive depending on O_CLOEXEC. Either way, O_CLOEXEC has the same final effect. > But as I was mentioning in that path we don't use CLONE_FILES anyway, > so that's not relevant. >=20 > --=20 > Stefano >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --FEoKoe2EYHy/dbnC Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoNro8ACgkQzQJF27ox 2Ge4dQ//UFZVk8rWb+afCYGpC7DxJ6DQJNI7CiyPlMMlL+QkuljW5VG+G1MeCl01 ZRdmHANhRkZ669PgD+mSu3BAsfks85yvgoHBUV5hTHvuQDWPyZ84phNBbUfe86/5 nfNFvBwjPq7C9mZMQpjET9AFLS9Dedlq3yyCeZ9hGEaSdwem9PylbxcWdR8Z0emt v8mjKEVwqhCLy1nfJ7AkZ420s5306HGfqjGHQpk1D40kTf8rqjxHNxqDpli+swIR iamiqGb9LukeLY/WNrdpPp1S91Bcx6uGTu7jR0pVTM75FTdAKq/LDv+AvOyzUGA9 ZOOMFOtvWMgK7RtNN4mTNSHk/27PzuGP/IYvhvxMuoAJFd8T/zGYSwPEksZBHtDB wt36iMpT0n2VZQXK0IbY/F0IQo4E6duuxWHn3pDCbhYh74cZlLVemi9aFmSeiBbb xUMTvYOZjSazioCGkndbIzLt56BUc264DOlRwFFWteYGaWgOOUdTPKzSyWylsrwg XBnlq2PGbdESW8+jg5dTIm93HQk6HbD3bo+xQOH60D0E379zFvt4s6jmH/Oujvl/ Xz4MVFHxAvx9dYqvygIo0z3jn20U6B0ylbZ1fYDBnBJ6KM2YEz4OyUaBDJ7KXkBz zblLrhL4whvIru3ePE7VZSTnYNCo7DmQTaT3kiZTFjIHqUaV+Oc= =KZ75 -----END PGP SIGNATURE----- --FEoKoe2EYHy/dbnC--