From patchwork Thu Mar 12 10:41:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 184437 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp387837ile; Thu, 12 Mar 2020 03:42:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsISHcihP0NvxADNU+izPIj3+DDhVSFRfofdDLR8wu4XrT3T8VTIKobSbmjlIfXqhMARNR7 X-Received: by 2002:a37:a0d6:: with SMTP id j205mr6909656qke.455.1584009764970; Thu, 12 Mar 2020 03:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584009764; cv=none; d=google.com; s=arc-20160816; b=ksJoK2Hwf875uh4ql0tcqJN4qNOK5lKyUX2jWL2NjGrsmHj/a62125JhgfIFqdqT3k nXwkrvs3oHshnZjK7KkMAypFJi+vbn7ZNX0pqJc2xAdIlwEt1fuugIouQtBVf23h0yV2 /S3YIyT5dLRQyaVQgJd3HtbBWConG2rGU2xZy87jRh0jceTgoaHozs0vUUZEuLI0jOBW gGAbeOISiHDfbBC+aA7DOp4kqNBgsSz7E1wcdR4j6xnCvpYrmDAKlQki18S7BKbYMVGm OFDXsrsntx+EJHXeAqGPhdShx7WfYkiJlSV/GP2/Q3Ld3aT176jEXREF2z6MOrxzYXc8 F6fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=LLFZrAobltgmvU6vJlk0C1lJO1F1EEmqYIwXBsGSKfs=; b=JgJAzTj8Dbb8E9CucRZ7FWhK6pPNbqe8YA0sXYM0eNZvoY64C4y0DvJVPi+8qOJ7TQ XCm2EJOlK/3fWTcLWJGDNoYXscCe58De5fL2DnIoexRN1GxsszJNSgMYU1n3I9qZXpme zTqTXKaeJyXxda0qP1o5FZl7GCsZlvDnS88atON6U3AxtsKFSJKRbdyX6FxaXIoYeix1 2Bx/W/268N1zv1nSlLqEmCXIdjWgCkEwr/XIeXJV7cAWa28edtJrXAoTlQFSXLddXcwn brEaZXFvWMnMulq2+4Pf3MCyK+vh5ZdATCyXzRMfOIMBL7L8fighvLXDapKjOZiw0umy WICg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bgpLSYwU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y11si2512285qka.354.2020.03.12.03.42.44 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Mar 2020 03:42:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bgpLSYwU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCLIa-000221-GQ for patch@linaro.org; Thu, 12 Mar 2020 06:42:44 -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) 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-Received: by 2002:a7b:c950:: with SMTP id i16mr4143395wml.97.1584009710297; Thu, 12 Mar 2020 03:41:50 -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) From: =?utf-8?q?Alex_Benn=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 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_Benn=C3=A9e?= , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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ée --- 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(-) -- 2.20.1 Reviewed-by: Stefan Hajnoczi 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 Listen on vhost-user UNIX domain socket at PATH. +.. option:: --socket-group=GROUP + + Set the vhost-user UNIX domain socket gid to GROUP. + .. option:: --fd=FDNUM Accept connections from vhost-user UNIX domain socket file descriptor FDNUM. 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_lowlevel.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[] = { LL_OPTION("--debug", debug, 1), LL_OPTION("allow_root", deny_others, 1), LL_OPTION("--socket-path=%s", vu_socket_path, 0), + LL_OPTION("--socket-group=%s", vu_socket_group, 0), LL_OPTION("--fd=%d", vu_listen_fd, 0), LL_OPTION("--thread-pool-size=%d", thread_pool_size, 0), FUSE_OPT_END @@ -2630,6 +2631,11 @@ struct fuse_session *fuse_session_new(struct fuse_args *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; + } se->bufsize = FUSE_MAX_MAX_PAGES * getpagesize() + FUSE_BUFFER_HEADER_SIZE; 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 #include "contrib/libvhost-user/libvhost-user.h" @@ -924,15 +926,29 @@ static int fv_create_listen_socket(struct fuse_session *se) /* * 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 = umask(0077); + if (se->vu_socket_group) { + old_umask = umask(S_IROTH | S_IWOTH | S_IXOTH); + } else { + old_umask = umask(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH); + } if (bind(listen_sock, (struct sockaddr *)&un, addr_len) == -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 = 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); if (listen(listen_sock, 1) == -1) {