From nobody Thu Nov 13 21:52:15 2025 Delivered-To: importer@patchew.org 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; 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1584009751; cv=none; d=zohomail.com; s=zohoarc; b=S9wTbOXHp5rad2ASBPlXekUXWDaRFeDJoAFUwLcd3b+JwmD6vxFtvD2bngTghL9PWna3FUwgje9CZUxD+D406Ie/Bjj+mIqTGqtHg9DMkaIwAQCAELMlVNAUHBoaBs28aygOe4jNa+v0SEL3TzKscJjxUTQQgSc0ZFyEs/Qf0MY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584009751; 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=LLFZrAobltgmvU6vJlk0C1lJO1F1EEmqYIwXBsGSKfs=; b=IwujrniY7Ft8vML4QRwlKxC8vx7SKIyUZSYiCeCd7IXlfVbcOmXVHnrz3e/H/qF4wpkKlS1KeiPZEIjCPgn+MwZ1yA/VEh2MEaIUoSDBzApoS2yZbRF6Vbvm0RohMlouCxB2d436LtX1VuAfLWMgmk3nnba8gsyCbULBm37M82g= 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 1584009751635395.97376095773984; Thu, 12 Mar 2020 03:42:31 -0700 (PDT) Received: from localhost ([::1]:39126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCLIL-0001cK-PD for importer@patchew.org; Thu, 12 Mar 2020 06:42:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41977) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCLHl-0001DY-AM for qemu-devel@nongnu.org; Thu, 12 Mar 2020 06:41:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCLHj-0007Y0-S7 for qemu-devel@nongnu.org; Thu, 12 Mar 2020 06:41:52 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:54909) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jCLHj-0007Xl-Kp for qemu-devel@nongnu.org; Thu, 12 Mar 2020 06:41:51 -0400 Received: by mail-wm1-x343.google.com with SMTP id n8so5511933wmc.4 for ; Thu, 12 Mar 2020 03:41:51 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f207sm13047158wme.9.2020.03.12.03.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:41:49 -0700 (PDT) Received: from zen.home.arpa (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7CDBB1FF7E; Thu, 12 Mar 2020 10:41:48 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LLFZrAobltgmvU6vJlk0C1lJO1F1EEmqYIwXBsGSKfs=; b=bgpLSYwU1oaYIXTZNNsLCl6uhLkgTrLY0+0239Nqp1qWHQlB7xiuZOrjBBGVz+atUo 6Dovzo6TkKkiD/OBS8Co1DH6MOYvmOJxb3Klj7OsK3+Ed6dIzc0aB0K68+BjTvZJaZqO d3cFvhOZF0O2CR8R+ftngf1pYU1LQGPZyd+2abq3mmAGv9jC4GRJA6uEKVLFBWB54T4N f/kDtSy7z1H6jQHUqLpZFnI8n/YzDF2W45CDL3j91px90iind4wSipANg1lXEpjX7oad dnb5aZA0Q856eKTbmPLl61LZHydKNz0zgnGMKWoG/yXeJSY2xoUDKwI6rKE1d4F03t+4 HQHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LLFZrAobltgmvU6vJlk0C1lJO1F1EEmqYIwXBsGSKfs=; b=mgy3NaxrXgqZ5l5vtoQCQSxzo7mTv0BnSq9IX6kQgy8iAPGab9HO0VVgWXK/bgNX42 bdrywclXE81QE6anWSK+FoqojSkSUkvcLEFQgU+sCvep5/isVBDZJS3RnZMytyoesS+a n3st8X8djX2gBsGkV4dwEKEPu+G6eKCygr6iqyPBlyttQoGLIYUu27G7fLCmUetZgWtw tuTIiy24tjWdFegpZZqV3W6OKPbaEss2LmNKjprBTIBOmiT30aglTzPfsCycz+1m9Xm7 DoWRmJywcwPYlwptHtAMpX+0B9ftYCb4O5Uk5ENrpKBLfC9uBe+AwESlYOd17nk4zgY0 MNjg== X-Gm-Message-State: ANhLgQ3YEdIFXpyl6ROFh+bEwscZl7x+HrU5i18bqINmRNu/uuFnAZbi 6RbW0U4PyVPvxojqMlaoMBLiMQ== X-Google-Smtp-Source: ADFU+vuDyISQ7PavORnR+PNxv0MtvejMBrNGQXZLzb3tldhjIaxSW21kwpbY5mRPSYlEIaBHxUnH2g== X-Received: by 2002:a7b:c950:: with SMTP id i16mr4143395wml.97.1584009710297; Thu, 12 Mar 2020 03:41:50 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH] tools/virtiofsd: add support for --socket-group Date: Thu, 12 Mar 2020 10:41:42 +0000 Message-Id: <20200312104142.21259-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 --- v1 - tweak documentation and commentary --- docs/tools/virtiofsd.rst | 4 ++++ tools/virtiofsd/fuse_i.h | 1 + tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ tools/virtiofsd/fuse_virtio.c | 20 ++++++++++++++++++-- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index 378594c422a..5a8246b74f8 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -85,6 +85,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 1240828208a..492e002181e 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 2dd36ec03b6..4d1ba2925d1 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 3b6d16a0417..331f9fc65c5 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,29 @@ 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_IWOT= H | 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.20.1