Skip to contentSkip to conversation

Unable to access fuse mountpoint with seteuid()

DISCUSSION Nikolaus Rath 2 participants 2 messages May 15, 2020 – May 18, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello,

I've written a setuid root program that tries to access a FUSE mountpoint owned by the calling user. I'm running seteuid(getuid()) to drop privileges, but still don't seem to be able to access the mountpoint.

Is that a bug or a feature? If it's a feature, is there any other way to get access to the mountpoint? All I want is the st_dev value...

Best,
-Nikolaus

Signature · 3 lines
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«
maintainer
#1 lore raw
Quoted 10 lines · Nikolaus Rath

Hello,

I've written a setuid root program that tries to access a FUSE mountpoint owned by the calling user. I'm running seteuid(getuid()) to drop privileges, but still don't seem to be able to access the mountpoint.

Is that a bug or a feature? If it's a feature, is there any other way to get access to the mountpoint? All I want is the st_dev value...

It's a feature:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/fuse/dir.c?h=v5.6#n1071

However, st_dev is definitely not something that could be used for DoS (it's not even controlled by the fuse daemon). The attached patch (untested) allows querying st_dev with statx(2) and a zero mask argument.

The other option is to parse /proc/self/mountinfo, but that comes with some caveats.

Thanks,
Miklos

fs/fuse/dir.c +11 -1
index de1e2fde60bd..26f028bc760b 100644
@@ -1689,8 +1689,18 @@ static int fuse_getattr(const struct path *path, struct kstat *stat,
 	struct inode *inode = d_inode(path->dentry);
 	struct fuse_conn *fc = get_fuse_conn(inode);
 
-	if (!fuse_allow_current_process(fc))
+	if (!fuse_allow_current_process(fc)) {
+		if (!request_mask) {
+			/*
+			 * If user explicitly requested *nothing* then don't
+			 * error out, but return st_dev only.
+			 */
+			stat->result_mask = 0;
+			stat->dev = inode->i_sb->s_dev;
+			return 0;
+		}
 		return -EACCES;
+	}
 
 	return fuse_update_get_attr(inode, NULL, stat, request_mask, flags);
 }