From: Vivek Goyal <vgoyal@redhat.com>
To: qemu-devel@nongnu.org
Cc: berrange@redhat.com, vromanso@redhat.com, dgilbert@redhat.com,
virtio-fs@redhat.com, stefanha@redhat.com, vgoyal@redhat.com
Subject: [PATCH 2/5] virtiofsd: create lock/pid file in per user cache dir
Date: Wed, 29 Jul 2020 18:14:07 -0400 [thread overview]
Message-ID: <20200729221410.147556-3-vgoyal@redhat.com> (raw)
In-Reply-To: <20200729221410.147556-1-vgoyal@redhat.com>
Right now we create lock/pid file in /usr/local/var/... and unprivliged
user does not have access to create files there.
So create this file in per user cache dir as queried as specified
by environment variable XDG_RUNTIME_DIR.
Note: "su $USER" does not update XDG_RUNTIME_DIR and it still points to
root user's director. So for now I create a directory /tmp/$UID to save
lock/pid file. Dan pointed out that it can be a problem if a malicious
app already has /tmp/$UID created. So we probably need to get rid of this.
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
---
tools/virtiofsd/fuse_virtio.c | 40 ++++++++++++++++++++++++++++++-----
1 file changed, 35 insertions(+), 5 deletions(-)
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
index 6b21a93841..f763a70ba5 100644
--- a/tools/virtiofsd/fuse_virtio.c
+++ b/tools/virtiofsd/fuse_virtio.c
@@ -972,13 +972,43 @@ static bool fv_socket_lock(struct fuse_session *se)
g_autofree gchar *pidfile = NULL;
g_autofree gchar *dir = NULL;
Error *local_err = NULL;
+ gboolean unprivileged = false;
- dir = qemu_get_local_state_pathname("run/virtiofsd");
+ if (geteuid() != 0)
+ unprivileged = true;
- if (g_mkdir_with_parents(dir, S_IRWXU) < 0) {
- fuse_log(FUSE_LOG_ERR, "%s: Failed to create directory %s: %s",
- __func__, dir, strerror(errno));
- return false;
+ /*
+ * Unpriviliged users don't have access to /usr/local/var. Hence
+ * store lock/pid file in per user directory. Use environment
+ * variable XDG_RUNTIME_DIR.
+ * If one logs into the system as root and then does "su" then
+ * XDG_RUNTIME_DIR still points to root user directory. In that
+ * case create a directory for user in /tmp/$UID
+ */
+ if (unprivileged) {
+ gchar *user_dir = NULL;
+ gboolean create_dir = false;
+ user_dir = g_strdup(g_get_user_runtime_dir());
+ if (!user_dir || g_str_has_suffix(user_dir, "/0")) {
+ user_dir = g_strdup_printf("/tmp/%d", geteuid());
+ create_dir = true;
+ }
+
+ if (create_dir && g_mkdir_with_parents(user_dir, S_IRWXU) < 0) {
+ fuse_log(FUSE_LOG_ERR, "%s: Failed to create directory %s: %s",
+ __func__, user_dir, strerror(errno));
+ g_free(user_dir);
+ return false;
+ }
+ dir = g_strdup(user_dir);
+ g_free(user_dir);
+ } else {
+ dir = qemu_get_local_state_pathname("run/virtiofsd");
+ if (g_mkdir_with_parents(dir, S_IRWXU) < 0) {
+ fuse_log(FUSE_LOG_ERR, "%s: Failed to create directory %s: %s",
+ __func__, dir, strerror(errno));
+ return false;
+ }
}
sk_name = g_strdup(se->vu_socket_path);
--
2.25.4
next prev parent reply other threads:[~2020-07-29 22:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-29 22:14 [RFC PATCH 0/5] virtiofsd: Add notion of unprivileged mode Vivek Goyal
2020-07-29 22:14 ` [PATCH 1/5] " Vivek Goyal
2020-07-29 22:14 ` Vivek Goyal [this message]
2020-07-30 8:59 ` [PATCH 2/5] virtiofsd: create lock/pid file in per user cache dir Daniel P. Berrangé
2020-07-30 14:10 ` Vivek Goyal
2020-07-29 22:14 ` [PATCH 3/5] virtiofsd: open /proc/self/fd/ in sandbox=NONE mode Vivek Goyal
2020-07-29 22:14 ` [PATCH 4/5] virtiofsd: Open lo->source while setting up root " Vivek Goyal
2020-07-29 22:14 ` [PATCH 5/5] virtiofsd: Skip setup_capabilities() " Vivek Goyal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200729221410.147556-3-vgoyal@redhat.com \
--to=vgoyal@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=virtio-fs@redhat.com \
--cc=vromanso@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).