From nobody Wed Mar 12 17:33:27 2025 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1741215068; cv=none; d=zohomail.com; s=zohoarc; b=K2ojCoBFyxLLIIP+l2hyMdIGSPX/HikWlRs5DMzvBRTA3HaNQXjL4voUIy5MzU1OzOutFCgetNyQYZV5T+8DucI/zaLCFUq/IZ5JuQXtsu50ih7G2xBgS4Zdf//YqqQT7QzOOkdu0IXe1o1OoTndLilqU49nJ4De25M2hrDEA84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741215068; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=pqvuSIf+aYNOMy/B52VKnszyrC363/Ut7VnHcX4mvcY=; b=kiaVJ4r2SUfJLtk2fVLYRuEJh7tAa244CSiACBQATfNmQsh413S48Igqk+yoWZtviF63u1b5dEEkGHZovSmEN1pi56sngLtX7zXiWapB1hUXshC6ayFBK/yNTGvetcy1oKwIao6/EymmMwHKIJNxkXyPEJd3oxccsu1AIlehTBg= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1741215067998125.03285981804083; Wed, 5 Mar 2025 14:51:07 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 00822178C; Wed, 5 Mar 2025 17:51:06 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CC0461629; Wed, 5 Mar 2025 17:50:07 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id BEA1714E3; Wed, 5 Mar 2025 17:50:03 -0500 (EST) Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 CAECC14E0 for ; Wed, 5 Mar 2025 17:50:02 -0500 (EST) Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-abf5358984bso6192766b.3 for ; Wed, 05 Mar 2025 14:50:02 -0800 (PST) Received: from localhost (205-201-32-8.scinternet.net. [205.201.32.8]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7349fd03d95sm13527663b3a.0.2025.03.05.14.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 14:50:01 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1741215001; x=1741819801; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=35dEyg2yRw3uM+Le4foaG5LgKI3/K1rzj5vjSpdt/ZA=; b=TMG19SmKExAEYISAH+3A3lU1Tf68eO0TM3P5qIB9j1idyDM3bemmCol3varrS2qQTx oP5jnm0Y3HJO6p/Vpt4nk+WBo3LtHYAVMEbF+IKn5oU8ssVeSB3hBR0hxHmMc1ciRN4Z QHD3NFYGBzPNOioMKDGLIJXnAxyzDM/sLdTSVyA+m6BuzOm13TLD3Wdmqu4tmgyGW3c1 S4WqjgSYyFpqCDWMCPZvPvxov+aTp3OY/THS9tF+6Z1vP4aKrHiIDpVRFbYKvRg6lYFb /AHMPFbYyBY4miU5ztdPa6ifdtBg6ekuCmhM+ZdBrytslLJkz5xSE6fGG1+bk4IrRcfi cJ9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741215001; x=1741819801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=35dEyg2yRw3uM+Le4foaG5LgKI3/K1rzj5vjSpdt/ZA=; b=ntg14zn0oSdVmZrkGkZEb3I8GnD5n+7TJjwi7gb6hPEMspCS9YG9CNXVqsX+1wRPKB yM5XLhgS6ibRG2kzWyIoj7nvHO7u9FOxQ1bHYlkJZ5V5nJ2UlMOkM1GNCKdE6ldDOkAi Xi00eyzLUtJDLYSs6vRnwsYSFHYJS5obpwnH762SM6MvED0UZy7U6dp0Uczk7Y4HnCGl 8Zerh11ivwlZwXnO+w58hycIaANyTpC6QMjYGLXLzFV3mbCuRnuiphe9Vp/TeLaGCcqJ dRQW8CEXUVHxWszteo5bZzo/MHvlciOZ2SmhPJIqu28jwxRi45v44TapbF24G2Qk18p4 06SA== X-Gm-Message-State: AOJu0YwYQwn9nqOmE33s1fT8QZZF5EFEgEC0Xi+h/mHEKRTquhJynGho J2Z15leVsEqvkTIQIgqiyYt2JvYFePXYyUdY3VO+FP1wOLyaftcAYpmgwS06tzuSnHUKLXB8crQ v X-Gm-Gg: ASbGncvaQ/yzzwAbHBqA1RGbwlUInMT1r9HCWthQMuxnIsIkqxQwkuQJwJ6uu3wfFKM 2sOblYiylAi7BUc4+5zC8E3saJU/l3Gvova4pwV75tVoTM7TprgyFTas8CbwzkqDNTV84V4f/lD VkzV/T2nhN3a25C3yW+EDUSD/UbBMOaflUTb0jxfbh/Dc0kv4uOJ2Nf5RuWQRT8LDtEp//L7wBM 3Bn+C9C9h5bx7P2g7IKjdbhruX/dWaLsunNaCvJgsueU66JYl9dzizKfg73/hWxvUt0ZdHfZ7kj a1J+OREpYNLjlV+bKnbfUrHw7B/0EJO97l/417/DJ8t1O8cFjGwdA7iFhuo9BY0= X-Google-Smtp-Source: AGHT+IFduZPoaVrTfPenuTdnTEQJVnAlda9TkBkCPJpJZeb5Ocfcl7/GDjsVcVegPsBl/VEwO/eZ0w== X-Received: by 2002:a17:906:7950:b0:abf:4521:eb2a with SMTP id a640c23a62f3a-ac20db09298mr560818366b.49.1741215001603; Wed, 05 Mar 2025 14:50:01 -0800 (PST) To: devel@lists.libvirt.org Subject: [PATCH V4 01/18] lib: virDomain{Save,Restore}Params: Ensure absolute path Date: Wed, 5 Mar 2025 15:48:10 -0700 Message-ID: <20250305224957.5369-2-jfehlig@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250305224957.5369-1-jfehlig@suse.com> References: <20250305224957.5369-1-jfehlig@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: R24DUTKE4HYWOTQG65PTHCTXVMS74XTL X-Message-ID-Hash: R24DUTKE4HYWOTQG65PTHCTXVMS74XTL X-MailFrom: jfehlig@suse.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 CC: farosas@suse.de 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: From: Jim Fehlig via Devel Reply-To: Jim Fehlig X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1741215068762019100 Content-Type: text/plain; charset="utf-8" When invoking virDomainSaveParams with a relative path, the image is saved to the daemon's CWD. Similarly, when providing virDomainRestoreParams with a relative path, it attempts to restore from the daemon's CWD. In most configurations, the daemon's CWD is set to '/'. Ensure a relative path is converted to absolute before invoking the driver domain{Save,Restore}Params functions. Signed-off-by: Jim Fehlig --- src/libvirt-domain.c | 89 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 16 deletions(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 18451ebdb9..0ee7c6f45b 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -1023,6 +1023,11 @@ virDomainSaveParams(virDomainPtr domain, unsigned int flags) { virConnectPtr conn; + virTypedParameterPtr params_copy =3D NULL; + int nparams_copy =3D 0; + const char *to =3D NULL; + g_autofree char *absolute_to =3D NULL; + int ret =3D -1; =20 VIR_DOMAIN_DEBUG(domain, "params=3D%p, nparams=3D%d, flags=3D0x%x", params, nparams, flags); @@ -1033,23 +1038,46 @@ virDomainSaveParams(virDomainPtr domain, virCheckDomainReturn(domain, -1); conn =3D domain->conn; =20 - virCheckReadOnlyGoto(conn->flags, error); + virCheckReadOnlyGoto(conn->flags, done); =20 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING, VIR_DOMAIN_SAVE_PAUSED, - error); + done); + + /* We must absolutize the file path as the save is done out of process= */ + virTypedParamsCopy(¶ms_copy, params, nparams); + nparams_copy =3D nparams; + if (virTypedParamsGetString(params_copy, nparams_copy, + VIR_DOMAIN_SAVE_PARAM_FILE, &to) < 0) + goto done; + + if (to) { + if (!(absolute_to =3D g_canonicalize_filename(to, NULL))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("could not build absolute output file path")); + goto done; + } + + if (virTypedParamsReplaceString(¶ms_copy, &nparams_copy, + VIR_DOMAIN_SAVE_PARAM_FILE, + absolute_to) < 0) + goto done; + } =20 if (conn->driver->domainSaveParams) { - if (conn->driver->domainSaveParams(domain, params, nparams, flags)= < 0) - goto error; - return 0; + if (conn->driver->domainSaveParams(domain, params_copy, nparams_co= py, flags) < 0) + goto done; + ret =3D 0; + } else { + virReportUnsupportedError(); } =20 - virReportUnsupportedError(); + done: + if (ret < 0) + virDispatchError(domain->conn); + virTypedParamsFree(params_copy, nparams_copy); =20 - error: - virDispatchError(domain->conn); - return -1; + return ret; } =20 =20 @@ -1206,6 +1234,12 @@ virDomainRestoreParams(virConnectPtr conn, virTypedParameterPtr params, int nparams, unsigned int flags) { + virTypedParameterPtr params_copy =3D NULL; + int nparams_copy =3D 0; + const char *from =3D NULL; + g_autofree char *absolute_from =3D NULL; + int ret =3D -1; + VIR_DEBUG("conn=3D%p, params=3D%p, nparams=3D%d, flags=3D0x%x", conn, params, nparams, flags); VIR_TYPED_PARAMS_DEBUG(params, nparams); @@ -1213,23 +1247,46 @@ virDomainRestoreParams(virConnectPtr conn, virResetLastError(); =20 virCheckConnectReturn(conn, -1); - virCheckReadOnlyGoto(conn->flags, error); + virCheckReadOnlyGoto(conn->flags, done); =20 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING, VIR_DOMAIN_SAVE_PAUSED, - error); + done); =20 if (conn->driver->domainRestoreParams) { + /* We must absolutize the file path as the save is done out of pro= cess */ + virTypedParamsCopy(¶ms_copy, params, nparams); + nparams_copy =3D nparams; + if (virTypedParamsGetString(params_copy, nparams_copy, + VIR_DOMAIN_SAVE_PARAM_FILE, &from) < 0) + goto done; + + if (from) { + if (!(absolute_from =3D g_canonicalize_filename(from, NULL))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("could not build absolute output file pat= h")); + goto done; + } + + if (virTypedParamsReplaceString(¶ms_copy, &nparams_copy, + VIR_DOMAIN_SAVE_PARAM_FILE, + absolute_from) < 0) + goto done; + } + if (conn->driver->domainRestoreParams(conn, params, nparams, flags= ) < 0) - goto error; - return 0; + goto done; + ret =3D 0; } =20 virReportUnsupportedError(); =20 - error: - virDispatchError(conn); - return -1; + done: + if (ret < 0) + virDispatchError(conn); + virTypedParamsFree(params_copy, nparams_copy); + + return ret; } =20 =20 --=20 2.43.0