From nobody Fri May 17 05:00:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1679672341; cv=none; d=zohomail.com; s=zohoarc; b=G5KJcIo/vuvPNdp6p9hh5DkYS69LwqzoUvTYsvEw8jiQq0O+ebbPpELGgGm1SICe/qaYBcmkno3Ltxg6UVgkJwif+h0RaqzBPauyEfg1kqK/Jy0dvOHnbrbGeu8BbX+D6Wh+8Jr2TMiNLN+s45U6O/HmIFCtlg2YL6/VtWZV9ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679672341; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=mAbBS99Tk9MDN9Xt1Z8xKBYlOLKgeBrUM86VYJIwmRw=; b=CB9+YO3LVUShwpc1P+oaDQrejfjxoG6PskVMlISQ7GDoakVb/eC0wA5INHbf9j5fKuGHhsywZ/l+Q6nbbMnv1yFQYmV1r+UwwW6RJfWdTLoP9/jFgeanAvXat1UbQPJ3W4A+Hr34WuCy+4WMsnnR+Talymq/GMKlfCiDAUNIyjE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1679672341590449.1362025655394; Fri, 24 Mar 2023 08:39:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfjQb-0000MX-G5; Fri, 24 Mar 2023 11:34:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfjQY-0000Kw-7T for qemu-devel@nongnu.org; Fri, 24 Mar 2023 11:34:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfjQV-0008LD-Vc for qemu-devel@nongnu.org; Fri, 24 Mar 2023 11:34:01 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-Oe1Kg4kHOFCe83_YFWW3zw-1; Fri, 24 Mar 2023 11:33:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A041685C069 for ; Fri, 24 Mar 2023 15:33:51 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EA8D2166B29 for ; Fri, 24 Mar 2023 15:33:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679672033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mAbBS99Tk9MDN9Xt1Z8xKBYlOLKgeBrUM86VYJIwmRw=; b=RbFsZZgOnMlwLk6GrzgSsXs1xXYJRbvF7/iqDojKT0+qlvvtlYSbdnYRXRADIxLGRDCEt8 exa8oSTuB3uwb3mW/K5xu5rTKklPpMSl4dTHbl9tBL5DvBzNeiImJmT+c6cBKeCJkfZnwF e9B3gH0tumfKdHbBqKyt0bQncRvEMek= X-MC-Unique: Oe1Kg4kHOFCe83_YFWW3zw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH] systemd: Also clear LISTEN_FDNAMES during systemd socket activation Date: Fri, 24 Mar 2023 10:33:49 -0500 Message-Id: <20230324153349.1123774-1-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1679672342021100001 Content-Type: text/plain; charset="utf-8" Some time after systemd documented LISTEN_PID and LISTEN_FDS for socket activation, they later added LISTEN_FDNAMES; now documented at: https://www.freedesktop.org/software/systemd/man/sd_listen_fds.html In particular, look at the implementation of sd_listen_fds_with_names(): https://github.com/systemd/systemd/blob/main/src/libsystemd/sd-daemon/sd-da= emon.c If we ever pass LISTEN_PID=3Dxxx and LISTEN_FDS=3Dn to a child process, but leave LISTEN_FDNAMES=3D... unchanged as inherited from our parent process, then our child process using sd_listen_fds_with_names() might see a mismatch in the number of names (unexpected -EINVAL failure), or even if the number of names matches the values of those names may be unexpected (with even less predictable results). Usually, this is not an issue - the point of LISTEN_PID is to tell systemd socket activation to ignore all other LISTEN_* if they were not directed to this particular pid. But if we end up consuming a socket directed to this qemu process, and later decide to spawn a child process that also needs systemd socket activation, we must ensure we are not leaking any stale systemd variables through to that child. The easiest way to do this is to wipe ALL LISTEN_* variables at the time we consume a socket, even if we do not yet care about a LISTEN_FDNAMES passed in from the parent process. See also https://lists.freedesktop.org/archives/systemd-devel/2023-March/04= 8920.html Thanks: Laszlo Ersek Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- util/systemd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/systemd.c b/util/systemd.c index 5bcac9b4016..ced518f771b 100644 --- a/util/systemd.c +++ b/util/systemd.c @@ -51,6 +51,7 @@ unsigned int check_socket_activation(void) /* So these are not passed to any child processes we might start. */ unsetenv("LISTEN_FDS"); unsetenv("LISTEN_PID"); + unsetenv("LISTEN_FDNAMES"); /* So the file descriptors don't leak into child processes. */ for (i =3D 0; i < nr_fds; ++i) { --=20 2.39.2