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=Bs0suKii; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 5F3FA5A0262 for ; Thu, 21 May 2026 04:31:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779330706; bh=mKR2/0mSVzOyUf0ynDT7JTFF7S9KgkecimP/fEbdq8s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Bs0suKiitK7/oYJtHFWHnYY5ucqdWL0C0TMiv74s5alV98IfKuQZXXua9i0kqR8EQ oNdm2vvfWtkeVZU07OWyNu1IYY1jsHZU/0Y+deURdPeJGjM4BK1i+g8vfcEixSA5+1 YXrAYhVLAfxsTzCd+UKGTY4Khd6n2zTZYsRLU2EUG2pptpS27/h0oIKjOCE/pFyW+2 T6I3FyBBlF+1woRgO1yujdqC3yyubvPOTGap5CDvLG9JygDPTaTq6L6WUw3itntS0Q 5Y0Xtcnu2CYwvWemzwKEToxnsrx3e4GbzcWRAuUuswI2DaRbJH97/96/9gMQoSzhjn Q3/pr/bMAhfSg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gLXVB6ZS6z4wL2; Thu, 21 May 2026 12:31:46 +1000 (AEST) Date: Thu, 21 May 2026 12:31:38 +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> <20260520162209.344f7232@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ToUUOjNv4k8biHc3" Content-Disposition: inline In-Reply-To: <20260520162209.344f7232@elisabeth> Message-ID-Hash: 7F2FLU3EP6YDMLN7MYG4BIYVJUBTM2RT X-Message-ID-Hash: 7F2FLU3EP6YDMLN7MYG4BIYVJUBTM2RT 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: --ToUUOjNv4k8biHc3 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 20, 2026 at 04:22:10PM +0200, Stefano Brivio wrote: > On Wed, 20 May 2026 22:52:47 +1000 > David Gibson wrote: >=20 > > 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: =20 > > > > > 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 c= reate. This > > > > > > > > seems to be generally accepted security best practice these= days, and we > > > > > > > > never fork(), so certainly have no need to pass fds to chil= dren. =20 > > > > > > >=20 > > > > > > > But we do clone() with CLONE_FILES (even though when we clone= () to 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 sho= uldn'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 sho= rt > > > > > > version rather than saying clone() with CLONE_FILES doesn't cou= nt. > > > > > >=20 > > > > > > Now, I realised that we've both fallen for the trap again, forg= etting > > > > > > that this has nothing to do with fork() or clone() and is, as i= t says > > > > > > 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 wo= uld 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 > > >=20 > > > Well, grep would beg to differ, as we don't call execve() at all, but= : =20 > >=20 > > I meant the system call execve(2), which execv() and execvp() are > > library wrappers around. >=20 > Oops, I missed the (2). >=20 > > > $ grep execv *.c | grep -v qrap > > > arch.c: execv(new_path, argv); > > > pasta.c: execvp(a->exe, a->argv); =20 > >=20 > > 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. > >=20 > > > 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 > > >=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. = =20 > >=20 > > 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(). > >=20 > > From execve(2): > > > =E2=80=A2 The file descriptor table is unshared, undoing the = effect of the CLONE_FILES flag of clone(2). =20 > >=20 > > .. then the now copied files do or don't survive depending on > > O_CLOEXEC. Either way, O_CLOEXEC has the same final effect. >=20 > Ah, right, I forgot about this part. But anyway, O_CLOEXEC is always > relevant, as long as we call execvp() not right after start, regardless > of having called clone() before. >=20 > And in this case (pasta_spawn_cmd()) we call it rather "late", so the > fact we don't call fork() is not really relevant for this purpose. Right. I already removed the reference to fork() in the next vesion. --=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 --ToUUOjNv4k8biHc3 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoObokACgkQzQJF27ox 2GcP+g//fRi9Zx7cEF+U4iP30+ISbnW/WK7sgijyxWv6QsNIi14rKALnUyJVGe/k W7Z6UW3rWZULX94nwokTbK22+tK8EcycgKjQNs6gXF7j6Wvvg1F5LO6srxruiNza EWr4nGUKGrHbLzPefLx/ZwxwGZqkU5+HX8W2/c1GyCcVSkpqN4Ct+Pc2Dn+DvzaU +em6OPSxMEXjmlwy+vG8lruO9p6ENsOPEvTmd4CcUutR2St3J10zwMBJJ3goT86E OuX3vhXfgeM5UR5vsRAWBURUFjfMtFs5MQMc2xkXao5sKthrsV384UoX1ECgDOHp vzzzjHMe567NJ4GZUNz92AO9VarqmhkCBOtFzNp7Et9jGO3cC9Qw/LWNf27iJCUZ trYQ/JIaD1TDeMF6BR7Mv9mztb4YactVlSrk7JWNhzqAgbM9Q930vbM296dp3HcO kJKVZEdYMrLlbsVk1N+xTRSfkmWQTllGArglDl1xRtd3KwpbLd0pY/jcPV+ORnYW 9UQ24LOZi7yUcSI3iwO+wAkAj26//XTiRmglWz9k/26g/3Bzoy87hM2Oj7jl5cB2 puMmV47ZCwFkniBaPvuTjOmmts7Izb/fZspt10XOZJgctuqRboYSsYOgBv8t4Z82 wrHu+SiZ5nGnQgAQZESfI+jMI6XYb67IujTO7UHLqaRXkIEsNEM= =W0Ya -----END PGP SIGNATURE----- --ToUUOjNv4k8biHc3--