From nobody Fri Nov 22 05:26:01 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 1716393680280485.1901878881905; Wed, 22 May 2024 09:01:20 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CA2BF1C6B; Wed, 22 May 2024 12:01:18 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 084F01A48; Wed, 22 May 2024 12:00:29 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EE0961A1F; Wed, 22 May 2024 12:00:24 -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 739C91A12 for ; Wed, 22 May 2024 12:00:24 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-401-6ReJoSq5MwCi8RHOB_G0zQ-1; Wed, 22 May 2024 12:00:22 -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 67B8D101A55E for ; Wed, 22 May 2024 16:00:22 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE59DC15BB9 for ; Wed, 22 May 2024 16:00:21 +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=1716393624; 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=uM2SFycEWb1xNhDJTuP7ZA4nyC2cRvbgQKAdlh7LE3U=; b=HbcR41EODiUY3uZ6hv9Rkwvn37qGONwxF8g/yn+01d86I+BHEZ5LYQAtQ8fXt4yhfKa1Wv b5dh2GJMhGDKnzX4U7+2ge7UJj/PJ73zkSv/CHTdaKUQC14vfCaXcLh+EBhCvBKmzkXyWQ 92SX+tsJTI9WjBFl+6pRgoHJ3GwEIh8= X-MC-Unique: 6ReJoSq5MwCi8RHOB_G0zQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/4] virfile: Modernize definition of virFileOpenForked/virFileOpenForceOwnerMode/virFileOpenAs Date: Wed, 22 May 2024 18:00:16 +0200 Message-ID: <2bf1ebbf530384b21e954af15a0c712af54db45d.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: U4RDH2HA3EX37X5N7X7WVUAJYFHR6Q25 X-Message-ID-Hash: U4RDH2HA3EX37X5N7X7WVUAJYFHR6Q25 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: 1716393681194100001 Content-Type: text/plain; charset="utf-8" Declare one argument per line and one variable per line and use boolean operators at the end of the line rather than at the beginning. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/util/virfile.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index c769f7d650..f66ecd29a2 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2330,8 +2330,12 @@ virFileAccessibleAs(const char *path, int mode, * opened as "fd" if it's not correct AND the flags say it should be * forced. */ static int -virFileOpenForceOwnerMode(const char *path, int fd, mode_t mode, - uid_t uid, gid_t gid, unsigned int flags) +virFileOpenForceOwnerMode(const char *path, + int fd, + mode_t mode, + uid_t uid, + gid_t gid, + unsigned int flags) { int ret =3D 0; struct stat st; @@ -2381,11 +2385,16 @@ virFileOpenForceOwnerMode(const char *path, int fd,= mode_t mode, * buildVol backend function expects the file to be deleted on error. */ static int -virFileOpenForked(const char *path, int openflags, mode_t mode, - uid_t uid, gid_t gid, unsigned int flags) +virFileOpenForked(const char *path, + int openflags, + mode_t mode, + uid_t uid, + gid_t gid, + unsigned int flags) { pid_t pid; - int status =3D 0, ret =3D 0; + int status =3D 0; + int ret =3D 0; int recvfd_errno =3D 0; int fd =3D -1; int pair[2] =3D { -1, -1 }; @@ -2546,10 +2555,15 @@ virFileOpenForked(const char *path, int openflags, = mode_t mode, * expects the file to be deleted on error. */ int -virFileOpenAs(const char *path, int openflags, mode_t mode, - uid_t uid, gid_t gid, unsigned int flags) +virFileOpenAs(const char *path, + int openflags, + mode_t mode, + uid_t uid, + gid_t gid, + unsigned int flags) { - int ret =3D 0, fd =3D -1; + int ret =3D 0; + int fd =3D -1; bool created =3D false; /* allow using -1 to mean "current value" */ @@ -2563,9 +2577,9 @@ virFileOpenAs(const char *path, int openflags, mode_t= mode, if (!(flags & (VIR_FILE_OPEN_NOFORK|VIR_FILE_OPEN_FORK))) flags |=3D VIR_FILE_OPEN_NOFORK|VIR_FILE_OPEN_FORK; - if ((flags & VIR_FILE_OPEN_NOFORK) - || (geteuid() !=3D 0) - || ((uid =3D=3D 0) && (gid =3D=3D 0))) { + if ((flags & VIR_FILE_OPEN_NOFORK) || + (geteuid() !=3D 0) || + ((uid =3D=3D 0) && (gid =3D=3D 0))) { if ((fd =3D open(path, openflags, mode)) < 0) { ret =3D -errno; --=20 2.45.1 From nobody Fri Nov 22 05:26:01 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 1716393737842600.1747318500016; Wed, 22 May 2024 09:02:17 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ABDEB1D63; Wed, 22 May 2024 12:02:16 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 043ED1B95; Wed, 22 May 2024 12:00:30 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 658891A48; Wed, 22 May 2024 12:00:26 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 C284D1A1F for ; Wed, 22 May 2024 12:00:25 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-446-98ob-t6jODKXC3KJHvWntA-1; Wed, 22 May 2024 12:00:23 -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 5DDA4801948 for ; Wed, 22 May 2024 16:00:23 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id C16B6C15BB1 for ; Wed, 22 May 2024 16:00:22 +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=1716393625; 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=8lLOt9Wvy/D34ZHkEp8QKSbX/Dl1HzF1IJ2MxNvkI8c=; b=IhLG+VZ5japXG4sxY3+sDNbWk1bJnASaO0q1Kad1DJ5OLS7UVJdMMFkJ93hwdanLD+rgTH pwNaBpTrFO8X5Ea5JnH28L1YLq6YAO0l9+YykRS+jOtkxn+ZR6yi2a+bdj3aWNjtiAPant mS77zwCVB1JrbjDV1ZqcaztLF0XOwzc= X-MC-Unique: 98ob-t6jODKXC3KJHvWntA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 2/4] virGetGroupList: Refactor and fix callers Date: Wed, 22 May 2024 18:00:17 +0200 Message-ID: <263b922fa2a52e7a77f45ad81f734c84d4909727.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: QUN7WR6NQW62PPEFRSAVK7F4A7ZSB577 X-Message-ID-Hash: QUN7WR6NQW62PPEFRSAVK7F4A7ZSB577 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: 1716393739473100001 Content-Type: text/plain; charset="utf-8" Use contemporary style for declarations and automatic memory clearing for a helper string. Since the function can't fail any more, remove any mention of returning errno and remove error checks from all callers. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/lxc/lxc_container.c | 4 ++-- src/security/security_dac.c | 7 +------ src/util/vircommand.c | 3 +-- src/util/virfile.c | 8 -------- src/util/virutil.c | 16 ++++++++-------- tests/commandtest.c | 5 ++--- tools/virt-login-shell-helper.c | 3 +-- 7 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 652697890f..7e460544fb 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -2059,8 +2059,8 @@ static int lxcContainerChild(void *data) /* TODO is it safe to call it here or should this call be moved in * front of the clone() as otherwise there might be a risk for a * deadlock */ - if ((ngroups =3D virGetGroupList(virCommandGetUID(cmd), virCommandGetG= ID(cmd), - &groups)) < 0) + ngroups =3D virGetGroupList(virCommandGetUID(cmd), virCommandGetGID(cm= d), + &groups); goto cleanup; ret =3D 0; diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 4e850e219e..669b90125c 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -524,14 +524,9 @@ static int virSecurityDACPreFork(virSecurityManager *mgr) { virSecurityDACData *priv =3D virSecurityManagerGetPrivateData(mgr); - int ngroups; g_clear_pointer(&priv->groups, g_free); - priv->ngroups =3D 0; - if ((ngroups =3D virGetGroupList(priv->user, priv->group, - &priv->groups)) < 0) - return -1; - priv->ngroups =3D ngroups; + priv->ngroups =3D virGetGroupList(priv->user, priv->group, &priv->grou= ps); return 0; } diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 81e74deee0..07bee9b12e 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -735,8 +735,7 @@ virExec(virCommand *cmd) childerr =3D null; } - if ((ngroups =3D virGetGroupList(cmd->uid, cmd->gid, &groups)) < 0) - goto cleanup; + ngroups =3D virGetGroupList(cmd->uid, cmd->gid, &groups); pid =3D virFork(); diff --git a/src/util/virfile.c b/src/util/virfile.c index f66ecd29a2..c4d22921ce 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2285,8 +2285,6 @@ virFileAccessibleAs(const char *path, int mode, return access(path, mode); ngroups =3D virGetGroupList(uid, gid, &groups); - if (ngroups < 0) - return -1; pid =3D virFork(); @@ -2408,8 +2406,6 @@ virFileOpenForked(const char *path, * NFS servers. */ ngroups =3D virGetGroupList(uid, gid, &groups); - if (ngroups < 0) - return -errno; if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) < 0) { ret =3D -errno; @@ -2709,8 +2705,6 @@ virFileRemove(const char *path, gid =3D getegid(); ngroups =3D virGetGroupList(uid, gid, &groups); - if (ngroups < 0) - return -errno; pid =3D virFork(); @@ -2883,8 +2877,6 @@ virDirCreate(const char *path, gid =3D getegid(); ngroups =3D virGetGroupList(uid, gid, &groups); - if (ngroups < 0) - return -errno; pid =3D virFork(); diff --git a/src/util/virutil.c b/src/util/virutil.c index bd3bbe3f0d..dc5009f11d 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -880,14 +880,16 @@ VIR_WARNINGS_NO_POINTER_SIGN * storing a malloc'd result into @list. If uid is -1 or doesn't exist in = the * system database querying of the supplementary groups is skipped. * - * Returns the size of the list on success, or -1 on failure with error - * reported and errno set. May not be called between fork and exec. + * Returns the size of the list. Doesn't have an error path. + * May not be called between fork and exec. * */ int -virGetGroupList(uid_t uid, gid_t gid, gid_t **list) +virGetGroupList(uid_t uid, + gid_t gid, + gid_t **list) { int ret =3D 0; - char *user =3D NULL; + g_autofree char *user =3D NULL; gid_t primary; *list =3D NULL; @@ -925,14 +927,12 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) for (i =3D 0; i < ret; i++) { if ((*list)[i] =3D=3D gid) - goto cleanup; + return ret; } VIR_APPEND_ELEMENT(*list, i, gid); - ret =3D i; + return i; } - cleanup: - VIR_FREE(user); return ret; } diff --git a/tests/commandtest.c b/tests/commandtest.c index aa108ce583..08fbe1801a 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -908,9 +908,8 @@ static int test25(const void *unused G_GNUC_UNUSED) goto cleanup; } - if ((ngroups =3D virGetGroupList(virCommandGetUID(cmd), virCommandGetG= ID(cmd), - &groups)) < 0) - goto cleanup; + ngroups =3D virGetGroupList(virCommandGetUID(cmd), virCommandGetGID(cm= d), + &groups); /* Now, fork and try to exec a nonexistent binary. */ pid =3D virFork(); diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helpe= r.c index cb94c49720..1627ba85e5 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -260,8 +260,7 @@ main(int argc, char **argv) if (!(conf =3D virConfReadFile(login_shell_path, 0))) goto cleanup; - if ((ngroups =3D virGetGroupList(uid, gid, &groups)) < 0) - goto cleanup; + ngroups =3D virGetGroupList(uid, gid, &groups); if (virLoginShellAllowedUser(conf, name, groups, ngroups) < 0) goto cleanup; --=20 2.45.1 From nobody Fri Nov 22 05:26:01 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 From nobody Fri Nov 22 05:26:01 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 1716393845123532.3822412654499; Wed, 22 May 2024 09:04:05 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EEF711D0C; Wed, 22 May 2024 12:04:03 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 68F331BAF; Wed, 22 May 2024 12:00:40 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C6E041A6E; Wed, 22 May 2024 12:00:27 -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 57F531A12 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-81-U1mW1nv1OlKSsTGRfGFCQw-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 457D03C0CEE1 for ; Wed, 22 May 2024 16:00:25 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABE29C15BB1 for ; Wed, 22 May 2024 16:00:24 +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=G+4N/cZEhTE4rEjDNUs3Ebon6Dx7/YhuWwQr3SetgbI=; b=bpAv5BoaxSQCIBUdMFNhiu8Xv+nFIEPHiTMJiSbKvWfzVogkSgFZQN1Vqfxq0Jlwylxw5W kIgUgmOamW8Wn0AmaRP3dB+gox27Pop7pbGjZOVtAd/S4DWCk74gH4pwlDGMA4WUq+k0ou O0ni4sCkqCrrSFeTjp9v0s8rQCgcbHw= X-MC-Unique: U1mW1nv1OlKSsTGRfGFCQw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 4/4] NEWS: Mention migration/save bug on root_squash NFS Date: Wed, 22 May 2024 18:00:19 +0200 Message-ID: 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: KJXTCT4X5HT7DQTO5R7RHOGTY4G7RQGL X-Message-ID-Hash: KJXTCT4X5HT7DQTO5R7RHOGTY4G7RQGL 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: 1716393846133100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- NEWS.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index b6985980ba..4a532bb673 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -51,7 +51,14 @@ v10.4.0 (unreleased) $ virsh help list + * qemu: Fix ``virsh save`` and migration when storage in question is roo= t_squashed NFS + Attempting to save a VM to a root_squash NFS mount or migrating with d= isks + hosted on such mount could, in some scenarios, result in error stating= :: + + 'Unknown error 255' + + The bug was introduced in `v10.1.0 (2024-03-01)`_. v10.3.0 (2024-05-02) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --=20 2.45.1