From nobody Fri May 17 07:07:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587405535; cv=none; d=zohomail.com; s=zohoarc; b=QMDoFjRv7OiXKdT52JGO5CLDQT9Jt8Oq+rB7IHONdw5helnq8EFAwV8Cfpoch5GW6PeHrpGKRGd5+THOgMzZHlN6OAl858BgOLrEZbqZAKG8V13oo9H/tQgMGtHFzKo3F1IWsJADMmaALnBVzckeRkFQJCMGvecUGrQ6/dyYWHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587405535; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3P+njxzp3Lmcfu/1uJRc/Eo2AmUeLCf+wLUBObG0sX0=; b=jQMdDKxudU3bczB3uZShQxHV3MX13lG/sU/ddgCn3nrSNtryzwD/fS+ryR7312L2oQDzeD4w4wUX0SHPJfIYFUssbLhieDgn1Dy+X2jl95dz018QdZJPwTRbhWbRqls5MVZp7gTaQzREP9860AqIl7AXPm1ZUjs4cEg1jOA0r0s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587405535718376.2641421732551; Mon, 20 Apr 2020 10:58:55 -0700 (PDT) Received: from localhost ([::1]:40054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQah4-0007sW-5T for importer@patchew.org; Mon, 20 Apr 2020 13:58:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36658 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQabf-0007Nh-Jp for qemu-devel@nongnu.org; Mon, 20 Apr 2020 13:53:20 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQabe-0004tG-4u for qemu-devel@nongnu.org; Mon, 20 Apr 2020 13:53:18 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:44841 helo=us-smtp-1.mimecast.com) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jQabd-0004oJ-KH for qemu-devel@nongnu.org; Mon, 20 Apr 2020 13:53:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-fGWRDdDzPG2fthAgax_6Kw-1; Mon, 20 Apr 2020 13:53:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8905C800D5C; Mon, 20 Apr 2020 17:53:13 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-80.rdu2.redhat.com [10.10.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16803A103F; Mon, 20 Apr 2020 17:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587405196; 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=3P+njxzp3Lmcfu/1uJRc/Eo2AmUeLCf+wLUBObG0sX0=; b=K8GKDiAhI6klzhUNU6OgJk9tQ7NF8AK2WAn6OGwAC7egk/p1HTcuNd/O4IKOkPntr6w7g5 zTXVRS6aljqs8LgCfZ0kVKMLtzpAFc/97B0qxSzzmlyoen46YcpLs1FNvTnBkfjmtAnEuC tXgybS2BdnYcFqfUJ9Bzk3SYd7bgpGE= X-MC-Unique: fGWRDdDzPG2fthAgax_6Kw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH 1/2] hax: Fix setting of FD_CLOEXEC Date: Mon, 20 Apr 2020 12:53:07 -0500 Message-Id: <20200420175309.75894-2-eblake@redhat.com> In-Reply-To: <20200420175309.75894-1-eblake@redhat.com> References: <20200420175309.75894-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=207.211.31.120; envelope-from=eblake@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs1p.gnu.org: First seen = 2020/04/20 03:29:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Eduardo Habkost , qemu-trivial@nongnu.org, "open list:X86 HAXM CPUs" , Colin Xu , Wenchao Wang , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Blindly setting FD_CLOEXEC without a read-modify-write will inadvertently clear any other intentionally-set bits, such as a proposed new bit for designating a fd that must behave in 32-bit mode. Use our wrapper function instead of an incorrect hand-rolled version. Signed-off-by: Eric Blake Reviewed-by: Colin Xu Reviewed-by: Peter Maydell --- target/i386/hax-posix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/target/i386/hax-posix.c b/target/i386/hax-posix.c index 3bad89f13337..5f9d1b803dec 100644 --- a/target/i386/hax-posix.c +++ b/target/i386/hax-posix.c @@ -23,7 +23,7 @@ hax_fd hax_mod_open(void) fprintf(stderr, "Failed to open the hax module\n"); } - fcntl(fd, F_SETFD, FD_CLOEXEC); + qemu_set_cloexec(fd); return fd; } @@ -147,7 +147,7 @@ hax_fd hax_host_open_vm(struct hax_state *hax, int vm_i= d) fd =3D open(vm_name, O_RDWR); g_free(vm_name); - fcntl(fd, F_SETFD, FD_CLOEXEC); + qemu_set_cloexec(fd); return fd; } @@ -200,7 +200,7 @@ hax_fd hax_host_open_vcpu(int vmid, int vcpuid) if (fd < 0) { fprintf(stderr, "Failed to open the vcpu devfs\n"); } - fcntl(fd, F_SETFD, FD_CLOEXEC); + qemu_set_cloexec(fd); return fd; } --=20 2.26.1 From nobody Fri May 17 07:07:50 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=1587405437; cv=none; d=zohomail.com; s=zohoarc; b=aPZv7T2dZRUxpv1lbqn0tXECn9fO47RNTVYKmkk9wCvo4y8OQAXRX+CQN+nZCdha/FzDvogt2/mvV0Vp5FVrX7GZRwIo38BrR8tF/CjfKfndTOEJS7V6ABxC9MrpQoNnARDKBY9XZCuX38CPAVxxYruG9ny8j3FQJAVBz/0EkQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587405437; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=K4ofxEhdp2LKF3VnjVWmK4rtE3cwGs/aI9dibt/RcMI=; b=D16okdkGD1mnh4MoGYPsWLCsYlZOM4sjuyQc31Q2rafplO0+EyOgESC1LZmz79LQlouZOQ8poQPAdZZS1pu6l3EJ7bd2JDm9jSw6/IHmvxO+nlRVNM5zEbSVZmtdm7Gr5zWTbqxNEe7iLo/0STia34b2pl6C9xWtqMYvFy9Q1y0= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587405437589483.0143372625506; Mon, 20 Apr 2020 10:57:17 -0700 (PDT) Received: from localhost ([::1]:40022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQafU-0004v0-AU for importer@patchew.org; Mon, 20 Apr 2020 13:57:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36680 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQabk-0007UM-6I for qemu-devel@nongnu.org; Mon, 20 Apr 2020 13:53:27 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQabg-0004xV-Pk for qemu-devel@nongnu.org; Mon, 20 Apr 2020 13:53:23 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:41087 helo=us-smtp-1.mimecast.com) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jQabf-0004we-Nh for qemu-devel@nongnu.org; Mon, 20 Apr 2020 13:53:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-84-wtAowj7mOXO-BHX1fCvbtw-1; Mon, 20 Apr 2020 13:53:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F67F8017F6; Mon, 20 Apr 2020 17:53:14 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-80.rdu2.redhat.com [10.10.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9187A103F; Mon, 20 Apr 2020 17:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587405199; 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=K4ofxEhdp2LKF3VnjVWmK4rtE3cwGs/aI9dibt/RcMI=; b=ZWef3dvG1JXjF6tq2hSlxtmR1DZLBoqPE++VNJU3iPm4yJXApiMlhIRczy2C6YE8XNoA94 g7l+zfCM4ICfmK3gBzX5mKoYqxopNjfJECIhzKKBcAGFqmQEIpUsN3okR2tqUMnTtcZ80O +6I/9WDIGGwqo4i2kUIz5uP5MMSv6us= X-MC-Unique: wtAowj7mOXO-BHX1fCvbtw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH 2/2] tools: Fix use of fcntl(F_SETFD) during socket activation Date: Mon, 20 Apr 2020 12:53:08 -0500 Message-Id: <20200420175309.75894-3-eblake@redhat.com> In-Reply-To: <20200420175309.75894-1-eblake@redhat.com> References: <20200420175309.75894-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=205.139.110.120; envelope-from=eblake@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs1p.gnu.org: First seen = 2020/04/20 04:32:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Blindly setting FD_CLOEXEC without a read-modify-write will inadvertently clear any other intentionally-set bits, such as a proposed new bit for designating a fd that must behave in 32-bit mode. However, we cannot use our wrapper qemu_set_cloexec(), because that wrapper intentionally abort()s on failure, whereas the probe here intentionally tolerates failure to deal with incorrect socket activation gracefully. Instead, fix the code to do the proper read-modify-write. Signed-off-by: Eric Blake Reviewed-by: Peter Maydell --- util/systemd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/systemd.c b/util/systemd.c index 1dd0367d9a84..5bcac9b40169 100644 --- a/util/systemd.c +++ b/util/systemd.c @@ -23,6 +23,7 @@ unsigned int check_socket_activation(void) unsigned long nr_fds; unsigned int i; int fd; + int f; int err; s =3D getenv("LISTEN_PID"); @@ -54,7 +55,8 @@ unsigned int check_socket_activation(void) /* So the file descriptors don't leak into child processes. */ for (i =3D 0; i < nr_fds; ++i) { fd =3D FIRST_SOCKET_ACTIVATION_FD + i; - if (fcntl(fd, F_SETFD, FD_CLOEXEC) =3D=3D -1) { + f =3D fcntl(fd, F_GETFD); + if (f =3D=3D -1 || fcntl(fd, F_SETFD, f | FD_CLOEXEC) =3D=3D -1) { /* If we cannot set FD_CLOEXEC then it probably means the file * descriptor is invalid, so socket activation has gone wrong * and we should exit. --=20 2.26.1