From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VvMy7ffv; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 1C7E15A0265 for ; Wed, 20 May 2026 16:22:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779286935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8UvbmORyf9ndNE6HTG6ZU/XeqMB6QqS5rlnueiMTutU=; b=VvMy7ffv+3tHhQWVQ4R+mdlFXFYw67L95Nvg87D7nkZMTyybxsT09UmW+n57nIkOizxx0v ajsBroyRzusYWh2GYH5EEyTlPerx6mCrRmmRUB0QnVOZHIUzAUDvehHB3K7dHIZMyNemGi SMLQjlSd1nqv8WgUr82I5s86EotqCNY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-nIIJxDYAOsWzaMFMww83kw-1; Wed, 20 May 2026 10:22:13 -0400 X-MC-Unique: nIIJxDYAOsWzaMFMww83kw-1 X-Mimecast-MFC-AGG-ID: nIIJxDYAOsWzaMFMww83kw_1779286932 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48e89faa62eso30210565e9.1 for ; Wed, 20 May 2026 07:22:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779286932; x=1779891732; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oBuciKtsv55phlnwoaqJyqg+oYWkIO5mpoMRpr07QBs=; b=Ne38J2T+FkjAPvpNo8HEacXgBo/SCPnE8zZU4TS87adVz3Plzkx9YdwWmOgGjWYbjr 3HT63z6Bo/eoQaR1Fq4rEgihBBFu0tYgS6URkDunFaqagevtbSsh42KX3VEYqs984RgL qSdotQuDAjKDBUK0t8mDBOOpf7nFeVXUOSmBPETZuSiURvBqFyseDJXHaMMQB5qr3VfR rgxPt0WDEU8lyuw8HqasbUDjcsm+6g8oGscDnqR+4V1HsjJhUhu1+ATLgybCTJxeadrQ 0bQ0ACmAP1kH4BQpkFPE+H9s+0qSAivrAVYiZ6EpyM3rbLX6FIj0pfFUTWHhN484iHQo 2Qeg== X-Gm-Message-State: AOJu0YwUd+9X9o3lrZex2y5Fd1RKE7HZAkG/MehI5BXAk6GK6qnCgZck 4S6OVmrE5rALP0IE58GVHvoR+YOo4qkyQvSR3q7t68Kceu7VWDsHltduCrGRXo8bz+kqCZIGmcv IL9PTmIOod3OJbKNFBgVQzfdIw5dVviPunNmqvLKasvKQcSaDhu1+TYQ9F3gYKA== X-Gm-Gg: Acq92OFu8GRKBmDguJ7bZqGZLqS2o9E5ET7p2QesYe9uW2DCE7J1EaVlbk6NwlucUTt 9MlRSCmbcUAtC4JWNnYokA46D6F98lIPxwQ0KZSZiP1Lry+/oRjM7QetWv5q0r09LeQkSrGELDy OlGPqZDQkgVGs7UzK8QjDzyyLmqcUEzI+LRaDH2il424hhRXqD6VJigeOHwiquhLB5/AdDchCo1 Tt6XWh9HBltjipDScsXFPhOPpV9ARe+ZnO5GpONmF1mz/n5LibhHJ2hHm7fjrQ8CwWZJu1x1XjM BpdPS9JutRrL6ncRGHqC87r1iF2P8LHhLBzu1wRrbt1u2H/69ZujdbcFrL043i7E2vgX/02dIql XrBnWaoN2mIea5cBjQQ2uqBa62hl4RYQf X-Received: by 2002:a05:600c:6992:b0:48e:6f39:f7be with SMTP id 5b1f17b1804b1-48fe60ea533mr362060445e9.10.1779286931961; Wed, 20 May 2026 07:22:11 -0700 (PDT) X-Received: by 2002:a05:600c:6992:b0:48e:6f39:f7be with SMTP id 5b1f17b1804b1-48fe60ea533mr362059875e9.10.1779286931436; Wed, 20 May 2026 07:22:11 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45e6a135f0csm35776893f8f.27.2026.05.20.07.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 07:22:10 -0700 (PDT) From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 1/3] treewide: Add SOCK_CLOEXEC to accept() calls that are missing it Message-ID: <20260520162209.344f7232@elisabeth> In-Reply-To: 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> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Wed, 20 May 2026 16:22:10 +0200 (CEST) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: N423d_uNU-ehnT75BsFqgbgOllO4VrZg9IcwT-3SnGY_1779286932 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: SSVGHD5P7P4RRB6XQX6OMNCCCRQU7OT6 X-Message-ID-Hash: SSVGHD5P7P4RRB6XQX6OMNCCCRQU7OT6 X-MailFrom: sbrivio@redhat.com 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: On Wed, 20 May 2026 22:52:47 +1000 David Gibson wrote: > 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 cre= ate. This > > > > > > > seems to be generally accepted security best practice these d= ays, and we > > > > > > > never fork(), so certainly have no need to pass fds to childr= en. =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 do= n't see > > > > > > a reason to skip O_CLOEXEC for c->fd_tap, this conclusion shoul= dn'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, forget= ting > > > > > that this has nothing to do with fork() or clone() and is, as it = 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 woul= d 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 w= e > > > 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. Oops, I missed the (2). > > $ grep execv *.c | grep -v qrap > > arch.c:=09=09execv(new_path, argv); > > pasta.c:=09execvp(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 ef= fect 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. 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. 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. --=20 Stefano