Skip to contentSkip to conversation

ROOT_DEV usage in hostfs

DISCUSSION Christoph Hellwig 4 participants 4 messages Jan 25, 2005 VFS

lore
Share & tools
lore
#0 lore raw

Could someone explain why hosts does thnings like:

	if((ino->i_sb->s_dev == ROOT_DEV) && (ino->i_uid == getuid()))
		ino->i_uid = 0;

(in fs/hostfs/hostfs_kern.c:read_name())

and

	if(attr->ia_valid & ATTR_UID){
		if((dentry->d_inode->i_sb->s_dev == ROOT_DEV) &&
		   (attr->ia_uid == 0))
			attr->ia_uid = getuid();
		attrs.ia_valid |= HOSTFS_ATTR_UID;
		attrs.ia_uid = attr->ia_uid;
	}
	if(attr->ia_valid & ATTR_GID){
		if((dentry->d_inode->i_sb->s_dev == ROOT_DEV) &&
		   (attr->ia_gid == 0))
			attr->ia_gid = getuid();
		attrs.ia_valid |= HOSTFS_ATTR_GID;
		attrs.ia_gid = attr->ia_gid;
	}

(hostfs_getattr)

A filesystems shouldn't have special casing for the rootfs, and chowning files from root to the current user sounds like an extremly bad idea to me aswell.

It's also the last thing preventing us from exporting ROOT_DEV

#1 lore raw
Quoted 1 line

It's also the last thing preventing us from exporting ROOT_DEV

unexporting

#2 lore raw
In reply to Christoph Hellwig

Dear diary, on Tue, Jan 25, 2005 at 10:10:39AM CET, I got a letter, where Christoph Hellwig <[email protected]> told me, that...

Quoted 24 lines

Could someone explain why hosts does thnings like:

	if((ino->i_sb->s_dev == ROOT_DEV) && (ino->i_uid == getuid()))
		ino->i_uid = 0;

(in fs/hostfs/hostfs_kern.c:read_name())

and

	if(attr->ia_valid & ATTR_UID){
		if((dentry->d_inode->i_sb->s_dev == ROOT_DEV) &&
		   (attr->ia_uid == 0))
			attr->ia_uid = getuid();
		attrs.ia_valid |= HOSTFS_ATTR_UID;
		attrs.ia_uid = attr->ia_uid;
	}
	if(attr->ia_valid & ATTR_GID){
		if((dentry->d_inode->i_sb->s_dev == ROOT_DEV) &&
		   (attr->ia_gid == 0))
			attr->ia_gid = getuid();
		attrs.ia_valid |= HOSTFS_ATTR_GID;
		attrs.ia_gid = attr->ia_gid;
	}
Quoted 7 lines

(hostfs_getattr)

A filesystems shouldn't have special casing for the rootfs, and chowning files from root to the current user sounds like an extremly bad idea to me aswell.

It's also the last thing preventing us from exporting ROOT_DEV

Hmm, I pretty much forgot it all, but it seems to do a trick that if you run UML with a non-root UID (if that's actually possible), the files owned by you on the host system are owned by root inside of the UML (which does not seem to be so unreasonable, but should be probably configurable if it's the case) - depends on what context getuid() runs in, which I'm not sure of anymore neither.

The gid handling is clearly buggy. It should test that in read_name() too and use getgid().

I don't know why it happens only on ROOT_DEV, perhaps some heuristic. Anyway, this comes (almost) verbatim from the 2.4.19 version by Jeff Dike, so he will hopefully come with a better explanation :-).

Signature · 3 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
98% of the time I am right. Why worry about the other 3%.
#3 lore raw
In reply to Christoph Hellwig
Quoted 3 lines · [email protected] said:

Could someone explain why hosts does thnings like:

	if((ino->i_sb->s_dev == ROOT_DEV) && (ino->i_uid == getuid()))
		ino->i_uid = 0; 

Don't let that stop you unexporting ROOT_DEV. It was a nasty kludge to make booting from a host filesystem kind of work. It would flip permissions around in order to make everything in the root filesystem owned by root, when the real ownership on the host is some normal user.

I have a better way of doing ownerships properly, so this was going to die anyway.

Jeff