From nobody Tue Feb 10 07:38:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=polymtl.ca ARC-Seal: i=1; a=rsa-sha256; t=1681802153; cv=none; d=zohomail.com; s=zohoarc; b=fXpWnWMh7PYJHRATepONU8rPZji46y/FFfJJoDrF7/sgybXpo62Es7l9oXpE+DkezRF4bK4WvfYF8DfRnny4EF1vI+sJjaVcg5FdqII/02s9aiLxlQWd7LWs97jpJYbj//clk0BCTC1979pddVzp9YSyTW9UlIU+tC0RlI0eWGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681802153; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=HoIr+IPhJ+u7VSUv0Iaw83248yvQhadO3aqtXXJriT4=; b=jTiXVvmDQHRrOQnbeV6s36IH59R32sPlA+PbjLI08vP95/J53vsyJZUIKoTButEkTy7KnIqsob19iW2dbkwQXijbmGX9YNeMlfKZ7Ar5YKL0Zd72Un77pBDNtWSPkt2tZVZikIi69mGDz3Hwk579V9r+zr1V0denEPq4UQiv+a4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1681802153096634.3267594204511; Tue, 18 Apr 2023 00:15:53 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-aPWrh2_yNoyvoF2eyiWGWA-1; Tue, 18 Apr 2023 03:15:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 50B9188B7A8; Tue, 18 Apr 2023 07:15:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 193082027044; Tue, 18 Apr 2023 07:15:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CF4A3194658D; Tue, 18 Apr 2023 07:15:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2A372194658C for ; Tue, 18 Apr 2023 07:15:39 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1C2E5C15BBA; Tue, 18 Apr 2023 07:15:39 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1507AC15BB8 for ; Tue, 18 Apr 2023 07:15:39 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EDE483815F07 for ; Tue, 18 Apr 2023 07:15:38 +0000 (UTC) Received: from joplin.neuro.polymtl.ca (joplin.neuro.polymtl.ca [132.207.65.211]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-364-URbq3Iy6Oe-RUtJxzjVVQw-1; Tue, 18 Apr 2023 03:07:09 -0400 Received: from localhost (joplin.neuro.polymtl.ca [local]) by joplin.neuro.polymtl.ca (OpenSMTPD) with ESMTPA id bc0c6104; Tue, 18 Apr 2023 06:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681802152; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HoIr+IPhJ+u7VSUv0Iaw83248yvQhadO3aqtXXJriT4=; b=OcfSW1qG5D2PEMnwz4OjhWGLw/wIT+IcL+qid63UfuymnjcfBQ/C5vEgatjuiItZWiedjL tK/kEnuL+OrlWTUcRQoG3DzEJL/z2LpN+Iqwwlk3M00BK9qEpJTWiClouV1pYMuIvFmrkH AOVcvo8qjBtLVBCoxUnhLZFdjb4zPPo= X-MC-Unique: aPWrh2_yNoyvoF2eyiWGWA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: URbq3Iy6Oe-RUtJxzjVVQw-1 From: Nick Guenther To: libvir-list@redhat.com Subject: [libvirt PATCH] qemu: Allow sockets in long or deep paths. Date: Tue, 18 Apr 2023 02:59:26 -0400 Message-Id: <20230418065926.23025-1-nick.guenther@polymtl.ca> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nick Guenther Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: polymtl.ca Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681802153877100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The qemu driver creates IPC sockets using absolute paths, but under POSIX socket paths are constrained pretty tightly. On systems with homedirs on an unusual mount point, like network homedirs, or just particularly long usernames, this could make starting VMs under qemu:///session impossible. Resolves https://gitlab.com/libvirt/libvirt/-/issues/466 Signed-off-by: Nick Guenther --- src/qemu/qemu_command.c | 52 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 4ca93bf3dc..3f180d5fb6 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -53,6 +53,7 @@ #include "virmdev.h" #include "virutil.h" =20 +#include #include #include =20 @@ -4866,6 +4867,37 @@ qemuOpenChrChardevUNIXSocket(const virDomainChrSourc= eDef *dev) struct sockaddr_un addr; socklen_t addrlen =3D sizeof(addr); int fd; + char* wd =3D NULL; + char* socket_dir_c =3D NULL; + char* socket_name_c =3D NULL; + char* socket_dir =3D NULL; + char* socket_name =3D NULL; + + /* The path length is limited to what fits in sockaddr_un. + * It's pretty short: 108 on Linux, and this is too easy to hit. + * Work around this limit by using a *relative path*. + * + * background: https://stackoverflow.com/questions/34829600/why-is-the= -maximal-path-length-allowed-for-unix-sockets-on-linux-108 + * + * docker added a different workaround: https://github.com/moby/moby/p= ull/13408 + */ + if ((wd =3D getcwd(NULL, 0)) =3D=3D NULL) { + virReportSystemError(errno, "%s", + _("Unable to get working directory")); + goto error; + } + + socket_dir_c =3D strdup(dev->data.nix.path); // dirname edits the stri= ng given it, so it must be copied + socket_name_c =3D strdup(dev->data.nix.path); + + socket_dir =3D dirname(socket_dir_c); + socket_name =3D basename(socket_name_c); + + if (chdir(socket_dir) < 0) { + virReportSystemError(errno, "%s", + _("Unable to get change to socket directory")= ); + goto error; + } =20 if ((fd =3D socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { virReportSystemError(errno, "%s", @@ -4875,10 +4907,10 @@ qemuOpenChrChardevUNIXSocket(const virDomainChrSour= ceDef *dev) =20 memset(&addr, 0, sizeof(addr)); addr.sun_family =3D AF_UNIX; - if (virStrcpyStatic(addr.sun_path, dev->data.nix.path) < 0) { + if (virStrcpyStatic(addr.sun_path, socket_name) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("UNIX socket path '%1$s' too long"), - dev->data.nix.path); + _("UNIX socket name '%1$s' too long"), + socket_name); goto error; } =20 @@ -4909,9 +4941,23 @@ qemuOpenChrChardevUNIXSocket(const virDomainChrSourc= eDef *dev) if (virFileUpdatePerm(dev->data.nix.path, 0002, 0664) < 0) goto error; =20 + /* restore working directory */ + if (chdir(wd) < 0) { + virReportSystemError(errno, "%s", + _("Unable to restore working directory")); + goto error; + } + + free(socket_name_c); + free(socket_dir_c); + free(wd); + return fd; =20 error: + if (socket_name_c !=3D NULL) { free(socket_name_c); } + if (socket_dir_c !=3D NULL) { free(socket_dir_c); } + if (wd !=3D NULL) { free(wd); } VIR_FORCE_CLOSE(fd); return -1; } --=20 2.34.1