From nobody Mon Nov 17 01:31:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602184470; cv=none; d=zohomail.com; s=zohoarc; b=d2oY7zEooYeFQxT+rvSjavaEtqaigq1JYDUcQUjllRBeL/3dExHsbI7/LI5UzqWRBubnXJQwfGe50znpdszFAkXhdQ7zb4BtUk3Q6o+i0h/dwutzHWFokNHJqspa4KYvoLUXBq80RkIGmTXXmqBA6WkrucFH7ZVlZH5FdmcxOxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602184470; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MIs8GSYndujj/IUhzFBYJYVlEAHzu8gUjnP34Xj8hpI=; b=K1LBhlc+TERbPpmoD6srTRMSLtwiKTiQJxNxGVjjaL9gKcPrT6sqKdadCmk+RWekDpGhSLDa/qL6Byt5+RCBvPKEqp9vrp3sbVXFIO06dydoiM4UfJrbVPYByW+2tAU0ZFP4i7zeJmiXN4XnBtDu1Tn13bTiL/z1QFvsaXPn4Dw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602184470717720.2750739271754; Thu, 8 Oct 2020 12:14:30 -0700 (PDT) Received: from localhost ([::1]:48838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQbMz-0006g3-Cp for importer@patchew.org; Thu, 08 Oct 2020 15:14:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQbJh-0001wr-Eg for qemu-devel@nongnu.org; Thu, 08 Oct 2020 15:11:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57845) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQbJf-00059W-AU for qemu-devel@nongnu.org; Thu, 08 Oct 2020 15:11:05 -0400 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-525-yXOcXuw5MkWT9eB7P_1LYw-1; Thu, 08 Oct 2020 15:11:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74A78107AFC7; Thu, 8 Oct 2020 19:10:59 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-212.ams2.redhat.com [10.36.114.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 083485C1BD; Thu, 8 Oct 2020 19:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602184262; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=MIs8GSYndujj/IUhzFBYJYVlEAHzu8gUjnP34Xj8hpI=; b=M3o9V4O2x6fA7qSQdEJKCZ/pSPIJbkEYv6NhOCQiY5/NrAp1PnVtUOJ2u3y1qY4do25pi8 ZSV2on59ZNzaDhZvmNf3hTMf5wioAYBfhgkAMVteAvQUJJlODR948wSJQxqBtskBVba/bi WTrj5k3F50flxom2gld0vB7iVZeD0os= X-MC-Unique: yXOcXuw5MkWT9eB7P_1LYw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, alex.bennee@linaro.org, zhengchuan@huawei.com, stefanha@redhat.com, peterx@redhat.com Subject: [PULL 02/10] tools/virtiofsd: add support for --socket-group Date: Thu, 8 Oct 2020 20:10:38 +0100 Message-Id: <20201008191046.272549-3-dgilbert@redhat.com> In-Reply-To: <20201008191046.272549-1-dgilbert@redhat.com> References: <20201008191046.272549-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/08 02:56:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Alex Benn=C3=A9e If you like running QEMU as a normal user (very common for TCG runs) but you have to run virtiofsd as a root user you run into connection problems. Adding support for an optional --socket-group allows the users to keep using the command line. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Stefan Hajnoczi Message-Id: <20200925125147.26943-2-alex.bennee@linaro.org> Signed-off-by: Dr. David Alan Gilbert dgilbert: Split long line --- docs/tools/virtiofsd.rst | 4 ++++ tools/virtiofsd/fuse_i.h | 1 + tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ tools/virtiofsd/fuse_virtio.c | 21 +++++++++++++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index ae02938a95..7ecee49834 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -87,6 +87,10 @@ Options =20 Listen on vhost-user UNIX domain socket at PATH. =20 +.. option:: --socket-group=3DGROUP + + Set the vhost-user UNIX domain socket gid to GROUP. + .. option:: --fd=3DFDNUM =20 Accept connections from vhost-user UNIX domain socket file descriptor FD= NUM. diff --git a/tools/virtiofsd/fuse_i.h b/tools/virtiofsd/fuse_i.h index 1240828208..492e002181 100644 --- a/tools/virtiofsd/fuse_i.h +++ b/tools/virtiofsd/fuse_i.h @@ -68,6 +68,7 @@ struct fuse_session { size_t bufsize; int error; char *vu_socket_path; + char *vu_socket_group; int vu_listen_fd; int vu_socketfd; struct fv_VuDev *virtio_dev; diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 2dd36ec03b..4d1ba2925d 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -2523,6 +2523,7 @@ static const struct fuse_opt fuse_ll_opts[] =3D { LL_OPTION("--debug", debug, 1), LL_OPTION("allow_root", deny_others, 1), LL_OPTION("--socket-path=3D%s", vu_socket_path, 0), + LL_OPTION("--socket-group=3D%s", vu_socket_group, 0), LL_OPTION("--fd=3D%d", vu_listen_fd, 0), LL_OPTION("--thread-pool-size=3D%d", thread_pool_size, 0), FUSE_OPT_END @@ -2630,6 +2631,11 @@ struct fuse_session *fuse_session_new(struct fuse_ar= gs *args, "fuse: --socket-path and --fd cannot be given together\n"= ); goto out4; } + if (se->vu_socket_group && !se->vu_socket_path) { + fuse_log(FUSE_LOG_ERR, + "fuse: --socket-group can only be used with --socket-path= \n"); + goto out4; + } =20 se->bufsize =3D FUSE_MAX_MAX_PAGES * getpagesize() + FUSE_BUFFER_HEADE= R_SIZE; =20 diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index d5c8e98253..89f537f79b 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include =20 #include "contrib/libvhost-user/libvhost-user.h" @@ -924,15 +926,30 @@ static int fv_create_listen_socket(struct fuse_sessio= n *se) =20 /* * Unfortunately bind doesn't let you set the mask on the socket, - * so set umask to 077 and restore it later. + * so set umask appropriately and restore it later. */ - old_umask =3D umask(0077); + if (se->vu_socket_group) { + old_umask =3D umask(S_IROTH | S_IWOTH | S_IXOTH); + } else { + old_umask =3D umask(S_IRGRP | S_IWGRP | S_IXGRP | + S_IROTH | S_IWOTH | S_IXOTH); + } if (bind(listen_sock, (struct sockaddr *)&un, addr_len) =3D=3D -1) { fuse_log(FUSE_LOG_ERR, "vhost socket bind: %m\n"); close(listen_sock); umask(old_umask); return -1; } + if (se->vu_socket_group) { + struct group *g =3D getgrnam(se->vu_socket_group); + if (g) { + if (!chown(se->vu_socket_path, -1, g->gr_gid)) { + fuse_log(FUSE_LOG_WARNING, + "vhost socket failed to set group to %s (%d)\n", + se->vu_socket_group, g->gr_gid); + } + } + } umask(old_umask); =20 if (listen(listen_sock, 1) =3D=3D -1) { --=20 2.28.0