From nobody Mon Nov 25 08:22:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1716393888569747.4946581646208; Wed, 22 May 2024 09:04:48 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7996F1BDB; Wed, 22 May 2024 12:04:47 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0FBEE1D31; Wed, 22 May 2024 12:00:45 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2D17F1A34; Wed, 22 May 2024 12:00:28 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 91A491A1F for ; Wed, 22 May 2024 12:00:27 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-JlOJ_sJfP9yW3UJHK2ZNpw-1; Wed, 22 May 2024 12:00:25 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5192F3C000A8 for ; Wed, 22 May 2024 16:00:24 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id B893DC15BB1 for ; Wed, 22 May 2024 16:00:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716393627; 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: in-reply-to:in-reply-to:references:references; bh=L8CeT9bi7ISnUSqss/4UENDIcVBk10psK+hp6M1Ndbo=; b=LpNMLJ+XJt9T39wZeiyDwBGBE5O1lI5UlqwWC6IFiWhCwJ0w6ZDEib1a6AnNhNfQMDg3Tx oM+956QnXEjewKsY3SFXzXNgkX2w7ryijUX4C5LO/1RzkapfW0ssUgyTP4y45NklLhySRw 9fua32v6jllJ0O6VgM9/yU1SgdnVJQ8= X-MC-Unique: JlOJ_sJfP9yW3UJHK2ZNpw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 3/4] virFileOpenForked: Fix handling of return value from virSocketSendFD() Date: Wed, 22 May 2024 18:00:18 +0200 Message-ID: <12b39b4b76a4a74a737f9f1a51c651e58c1796a5.1716393556.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QH3VNPZY6DUGQ4HBNQN54IXIWHQOAR35 X-Message-ID-Hash: QH3VNPZY6DUGQ4HBNQN54IXIWHQOAR35 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1716393890373100001 Content-Type: text/plain; charset="utf-8" Commit 91f4ebbac81bc3829da6d5a71d7520a6fc9e358e (v10.0.0-185-g91f4ebbac8) changed the return value of virSocketSendFD() from 0 to 1 on success. Unfortunately in 'virFileOpenForked' the return value was used to report the error back to the main process from the fork'd child. As process return codes are positive only, the code negates the value of 'ret' and reports it. This resulted in the parent thinking the process exited with failure: # virsh save avocado-vt-vm1 /mnt/save error: Failed to save domain 'avocado-vt-vm1' to /mnt/save error: Error from child process creating '/mnt/save': Unknown error 255 This error reproduces on NFS mounts with 'root_squash' enabled. I've also observed it in one specific migration case when root_squash NFS is used with following error: Failed to open file '/var/lib/libvirt/images/alpine.qcow2': Unknown error= 255' To fix the issue the code is refactored so that it doesn't actually touch the 'ret' variable needlessly and assigns to it only on failure cases, which prevents the '1' to be propagated to the parent process as '255' after negating and storing in the process return code. Fixes: 91f4ebbac81bc3829da6d5a71d7520a6fc9e358e Resolves: https://issues.redhat.com/browse/RHEL-36721 Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/util/virfile.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index c4d22921ce..d820172405 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2441,8 +2441,7 @@ virFileOpenForked(const char *path, created =3D true; /* File is successfully open. Set permissions if requested. */ - ret =3D virFileOpenForceOwnerMode(path, fd, mode, uid, gid, flags); - if (ret < 0) { + if (virFileOpenForceOwnerMode(path, fd, mode, uid, gid, flags) < 0= ) { ret =3D -errno; virReportSystemError(errno, _("child process failed to force owner mo= de file '%1$s'"), @@ -2450,9 +2449,7 @@ virFileOpenForked(const char *path, goto childerror; } - ret =3D virSocketSendFD(pair[1], fd); - - if (ret < 0) { + if (virSocketSendFD(pair[1], fd) < 0) { ret =3D -errno; virReportSystemError(errno, "%s", _("child process failed to send fd to par= ent")); --=20 2.45.1