From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 766F45A004F for ; Wed, 07 Aug 2024 09:29:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723015777; 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=mEQExVghQ0YcOrBqTknA/42VdXk95A9D1d9//J1k+Go=; b=YDSudoUIZbi2D9cx2l+RAtIzhB3CiUKu67mA8WwjlK1O7vgMr/pWqJIuKZXsj/7iE+cnRa xZQ3zvWq0nCio4dvYgYa+0c4nMl7pW9Jiqfqr49jUoB72dGbqFMXUImWI94emACRz5fhjO eSgj/W2LjsomNZhfSXEJzUlgzXNQyTU= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-529-r3wmJ4uPNQeTSQw9n0EgzA-1; Wed, 07 Aug 2024 03:29:35 -0400 X-MC-Unique: r3wmJ4uPNQeTSQw9n0EgzA-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-369bbbdb5a1so253895f8f.1 for ; Wed, 07 Aug 2024 00:29:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723015774; x=1723620574; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mEQExVghQ0YcOrBqTknA/42VdXk95A9D1d9//J1k+Go=; b=p3I7KsgMwLciBOH9B5RILyaeMLRxJht3f770OIE9yKrtWc6dfWbXzBqloGW2l9XWuL rSIbrbIsOaLaiIEiCqxIQm5CGFGfHidaNgoUfX2D5QBH+LFgs+dzGhVLaGMAqfbfipGq MWwCjD9wJQkxP7zndJHNsvXnRemx6n0x1V9beRDe2RwHdChK/OYBKNTT/ieyag+wSYAv K/qr9+A+7qf3IcnYt4ZnvmN/bL4RQBtxl0qj9i9Q/lwaEUvn/BrCYeiXN17ho3k2pCg4 1WK7WgVKVKEVTE/Lc2qSkSngg46VAHAy7WSpj/3iOi4kx6ObhvYDuBlq8z/GFrsd4R7b uDwQ== X-Gm-Message-State: AOJu0Yywqr0BxhNErsTiFzWmyqasPySpbAfrZms2Ta+LwMt6Fb6K5zNu pcUxqukjLDCAWEArA/mI2bScP8rBsuIpBAu9YoTEgVo3BDhl/X9fKfRt5ZoTelHgipjGWYrcoxE Vq/ulTMhNyKS5fvo/5l0Z2FsS2Diy7BFyi2rL8oeUoRgkAVmRJw== X-Received: by 2002:a5d:47cf:0:b0:366:e9fa:17b with SMTP id ffacd0b85a97d-36bf0d98d2cmr961207f8f.1.1723015773904; Wed, 07 Aug 2024 00:29:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGuEjP4dsAdLV3Wkx2c/4XMiIbZJ1Wi8sTRLNRqOE01+4VxfDNA2Ed/Fz/TneK4P0eziVMd9w== X-Received: by 2002:a5d:47cf:0:b0:366:e9fa:17b with SMTP id ffacd0b85a97d-36bf0d98d2cmr961184f8f.1.1723015773331; Wed, 07 Aug 2024 00:29:33 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbcf0cc9csm15146288f8f.17.2024.08.07.00.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 00:29:32 -0700 (PDT) Date: Wed, 7 Aug 2024 09:29:31 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH] passt, util: Close any open file that the parent might have leaked Message-ID: <20240807092931.62ad47f4@elisabeth> In-Reply-To: References: <20240806183837.548257-1-sbrivio@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: HJOOBFNVT733LYTRFXYNKLAPHOAUK7CE X-Message-ID-Hash: HJOOBFNVT733LYTRFXYNKLAPHOAUK7CE 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, Paul Holzinger 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, 7 Aug 2024 11:44:01 +1000 David Gibson wrote: > On Tue, Aug 06, 2024 at 08:38:37PM +0200, Stefano Brivio wrote: > > If a parent accidentally or due to implementation reasons leaks any > > open file, we don't want to have access to them, except for the file > > passed via --fd, if any. > > > > This is the case for Podman when Podman's parent leaks files into > > Podman: it's not practical for Podman to close unrelated files before > > starting pasta, as reported by Paul. > > > > Use close_range(2) to close all open files except for standard streams > > and the one from --fd. > > > > Given that parts of conf() depend on other files to be already opened, > > such as the epoll file descriptor, we can't easily defer this to a > > more convenient point, where --fd was already parsed. Introduce a > > minimal, duplicate version of --fd parsing to keep this simple. > > > > Suggested-by: Paul Holzinger > > Signed-off-by: Stefano Brivio > > --- > > conf.c | 1 + > > passt.c | 2 ++ > > util.c | 36 ++++++++++++++++++++++++++++++++++++ > > util.h | 1 + > > 4 files changed, 40 insertions(+) > > > > diff --git a/conf.c b/conf.c > > index 14d8ece..89f5b3d 100644 > > --- a/conf.c > > +++ b/conf.c > > @@ -1260,6 +1260,7 @@ void conf(struct ctx *c, int argc, char **argv) > > c->tcp.fwd_in.mode = c->tcp.fwd_out.mode = FWD_UNSET; > > c->udp.fwd_in.mode = c->udp.fwd_out.mode = FWD_UNSET; > > > > + optind = 1; > > do { > > name = getopt_long(argc, argv, optstring, options, NULL); > > > > diff --git a/passt.c b/passt.c > > index ea5bece..be7e84a 100644 > > --- a/passt.c > > +++ b/passt.c > > @@ -211,6 +211,8 @@ int main(int argc, char **argv) > > > > arch_avx2_exec(argv); > > > > + close_open_files(argc, argv); > > Any reason not to fold this logic into isolate_initial()? Seems like > it is part of self-isolation handling. I also thought of doing that, for the simple fact that isolate_initial() is called just after this, and reducing clutter didn't sound like a valid reason to move this to a place it doesn't really belong to (it's not about "isolation"). On the other hand, reading the isolate_*() functions again, we're assigning a rather broad scope to "isolation"... so it could actually fit. > Also, I think this could wait until after the existing > isolate_initial() logic. Dropping caps before examining the command > line seems like a sensible precaution. Oh, right, we don't drop much there but at least we make sure we don't have CAP_DAC_OVERRIDE and friends. I'll move this to the end of isolate_initial() then. -- Stefano