From nobody Thu May 2 03:02:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613148164; cv=none; d=zohomail.com; s=zohoarc; b=g+h+9axzaYtgN3rlAszQvXnl26eezss7Ef+89WRALSKDLdm1PGgUvkZW3stNUuX6yHcs3UUq/FjI1xyURzHzAFtGX/Wq7A7D60cIYPVZCn4iNZEghsJ+Gv8SxEcscv6ATnc2BSu4MpUwwIcNnbSJ/4PTDxzo8Cm1LlQtOGdTeIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613148164; 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=URnkEQawYcZIVdN8NJwQrnnQsDyhDhKwBNa/oxJJz/w=; b=GRT2jsIsSgzA1ySU4RSRkHXw7knoCi9XzfO5dKBhsuKy+aBVLZlwogGV5EcEbkel8B9eoT9E+PqGlGrEdpa1zpCodND+DdsbNCG2raArjdOwys4vqn37aSsT0KQ4oaWR8B3F0oKFrps5kvbWxir8DM3qsxqJ8DCQ/fXIb1rpV9E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1613148164356862.22214487018; Fri, 12 Feb 2021 08:42:44 -0800 (PST) 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-235-sfo3zavsMmuNVZWrFYUPDg-1; Fri, 12 Feb 2021 11:42:38 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 053AB106BB23; Fri, 12 Feb 2021 16:42:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B63CA19811; Fri, 12 Feb 2021 16:42:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2670C4E58D; Fri, 12 Feb 2021 16:42:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11CGgPnO002251 for ; Fri, 12 Feb 2021 11:42:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 342235C277; Fri, 12 Feb 2021 16:42:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A911A5C3E0 for ; Fri, 12 Feb 2021 16:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613148163; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=URnkEQawYcZIVdN8NJwQrnnQsDyhDhKwBNa/oxJJz/w=; b=N7DqphzeFiZOtkN068NKYonst86lJM8Kd/H5bKu5JRxQckB5ZjUix8ebBKrbkeVyndB5Bt 7HFnH4XnSUe59iepkF7Tv0TiBfKyRhEVfLSend2AKdowY6AdP6qQZrG8ZEYSWVPjrbaDpB /D0P7NOHyxPy7IA4/nCaEQf8kkfir2I= X-MC-Unique: sfo3zavsMmuNVZWrFYUPDg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] qemu_shim: URI escape root directory Date: Fri, 12 Feb 2021 17:42:19 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The root directory can be provided by user (or a temporary one is generated) and is always formatted into connection URI for both secret driver and QEMU driver, like this: qemu:///embed?root=3D$root But if it so happens that there is an URI unfriendly character in root directory or path to it (say a space) then invalid URI is formatted which results in unexpected results. We can trust g_dir_make_tmp() to generate valid URI but we can't trust user. Escape user provided root directory. Always. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1920400 Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_shim.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_shim.c b/src/qemu/qemu_shim.c index 18bdc99256..c10598df4b 100644 --- a/src/qemu/qemu_shim.c +++ b/src/qemu/qemu_shim.c @@ -140,7 +140,8 @@ int main(int argc, char **argv) g_autofree char *xml =3D NULL; g_autofree char *uri =3D NULL; g_autofree char *suri =3D NULL; - char *root =3D NULL; + const char *root =3D NULL; + g_autofree char *escaped =3D NULL; bool tmproot =3D false; int ret =3D 1; g_autoptr(GError) error =3D NULL; @@ -216,6 +217,8 @@ int main(int argc, char **argv) } } =20 + escaped =3D g_uri_escape_string(root, NULL, true); + virFileActivateDirOverrideForProg(argv[0]); =20 if (verbose) @@ -242,7 +245,7 @@ int main(int argc, char **argv) eventLoopThread =3D g_thread_new("event-loop", qemuShimEventLoop, NULL= ); =20 if (secrets && *secrets) { - suri =3D g_strdup_printf("secret:///embed?root=3D%s", root); + suri =3D g_strdup_printf("secret:///embed?root=3D%s", escaped); =20 if (verbose) g_printerr("%s: %lld: opening %s\n", @@ -303,7 +306,7 @@ int main(int argc, char **argv) } } =20 - uri =3D g_strdup_printf("qemu:///embed?root=3D%s", root); + uri =3D g_strdup_printf("qemu:///embed?root=3D%s", escaped); =20 if (verbose) g_printerr("%s: %lld: opening %s\n", --=20 2.26.2