aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext2/inode.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-05-23 20:42:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-23 20:42:39 -0400
commit644473e9c60c1ff4f6351fed637a6e5551e3dce7 (patch)
tree10316518bedc735a2c6552886658d69dfd9f1eb0 /fs/ext2/inode.c
parentfb827ec68446c83e9e8754fa9b55aed27ecc4661 (diff)
parent4b06a81f1daee668fbd6de85557bfb36dd36078f (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull user namespace enhancements from Eric Biederman: "This is a course correction for the user namespace, so that we can reach an inexpensive, maintainable, and reasonably complete implementation. Highlights: - Config guards make it impossible to enable the user namespace and code that has not been converted to be user namespace safe. - Use of the new kuid_t type ensures the if you somehow get past the config guards the kernel will encounter type errors if you enable user namespaces and attempt to compile in code whose permission checks have not been updated to be user namespace safe. - All uids from child user namespaces are mapped into the initial user namespace before they are processed. Removing the need to add an additional check to see if the user namespace of the compared uids remains the same. - With the user namespaces compiled out the performance is as good or better than it is today. - For most operations absolutely nothing changes performance or operationally with the user namespace enabled. - The worst case performance I could come up with was timing 1 billion cache cold stat operations with the user namespace code enabled. This went from 156s to 164s on my laptop (or 156ns to 164ns per stat operation). - (uid_t)-1 and (gid_t)-1 are reserved as an internal error value. Most uid/gid setting system calls treat these value specially anyway so attempting to use -1 as a uid would likely cause entertaining failures in userspace. - If setuid is called with a uid that can not be mapped setuid fails. I have looked at sendmail, login, ssh and every other program I could think of that would call setuid and they all check for and handle the case where setuid fails. - If stat or a similar system call is called from a context in which we can not map a uid we lie and return overflowuid. The LFS experience suggests not lying and returning an error code might be better, but the historical precedent with uids is different and I can not think of anything that would break by lying about a uid we can't map. - Capabilities are localized to the current user namespace making it safe to give the initial user in a user namespace all capabilities. My git tree covers all of the modifications needed to convert the core kernel and enough changes to make a system bootable to runlevel 1." Fix up trivial conflicts due to nearby independent changes in fs/stat.c * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (46 commits) userns: Silence silly gcc warning. cred: use correct cred accessor with regards to rcu read lock userns: Convert the move_pages, and migrate_pages permission checks to use uid_eq userns: Convert cgroup permission checks to use uid_eq userns: Convert tmpfs to use kuid and kgid where appropriate userns: Convert sysfs to use kgid/kuid where appropriate userns: Convert sysctl permission checks to use kuid and kgids. userns: Convert proc to use kuid/kgid where appropriate userns: Convert ext4 to user kuid/kgid where appropriate userns: Convert ext3 to use kuid/kgid where appropriate userns: Convert ext2 to use kuid/kgid where appropriate. userns: Convert devpts to use kuid/kgid where appropriate userns: Convert binary formats to use kuid/kgid where appropriate userns: Add negative depends on entries to avoid building code that is userns unsafe userns: signal remove unnecessary map_cred_ns userns: Teach inode_capable to understand inodes whose uids map to other namespaces. userns: Fail exec for suid and sgid binaries with ids outside our user namespace. userns: Convert stat to return values mapped from kuids and kgids userns: Convert user specfied uids and gids in chown into kuids and kgid userns: Use uid_eq gid_eq helpers when comparing kuids and kgids in the vfs ...
Diffstat (limited to 'fs/ext2/inode.c')
-rw-r--r--fs/ext2/inode.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 740cad8dcd8d..f9fa95f8443d 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -1293,6 +1293,8 @@ struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
1293 struct inode *inode; 1293 struct inode *inode;
1294 long ret = -EIO; 1294 long ret = -EIO;
1295 int n; 1295 int n;
1296 uid_t i_uid;
1297 gid_t i_gid;
1296 1298
1297 inode = iget_locked(sb, ino); 1299 inode = iget_locked(sb, ino);
1298 if (!inode) 1300 if (!inode)
@@ -1310,12 +1312,14 @@ struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
1310 } 1312 }
1311 1313
1312 inode->i_mode = le16_to_cpu(raw_inode->i_mode); 1314 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
1313 inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low); 1315 i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
1314 inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low); 1316 i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
1315 if (!(test_opt (inode->i_sb, NO_UID32))) { 1317 if (!(test_opt (inode->i_sb, NO_UID32))) {
1316 inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16; 1318 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
1317 inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16; 1319 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
1318 } 1320 }
1321 i_uid_write(inode, i_uid);
1322 i_gid_write(inode, i_gid);
1319 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count)); 1323 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
1320 inode->i_size = le32_to_cpu(raw_inode->i_size); 1324 inode->i_size = le32_to_cpu(raw_inode->i_size);
1321 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime); 1325 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
@@ -1413,8 +1417,8 @@ static int __ext2_write_inode(struct inode *inode, int do_sync)
1413 struct ext2_inode_info *ei = EXT2_I(inode); 1417 struct ext2_inode_info *ei = EXT2_I(inode);
1414 struct super_block *sb = inode->i_sb; 1418 struct super_block *sb = inode->i_sb;
1415 ino_t ino = inode->i_ino; 1419 ino_t ino = inode->i_ino;
1416 uid_t uid = inode->i_uid; 1420 uid_t uid = i_uid_read(inode);
1417 gid_t gid = inode->i_gid; 1421 gid_t gid = i_gid_read(inode);
1418 struct buffer_head * bh; 1422 struct buffer_head * bh;
1419 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh); 1423 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
1420 int n; 1424 int n;
@@ -1529,8 +1533,8 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
1529 1533
1530 if (is_quota_modification(inode, iattr)) 1534 if (is_quota_modification(inode, iattr))
1531 dquot_initialize(inode); 1535 dquot_initialize(inode);
1532 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) || 1536 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
1533 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) { 1537 (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
1534 error = dquot_transfer(inode, iattr); 1538 error = dquot_transfer(inode, iattr);
1535 if (error) 1539 if (error)
1536 return error; 1540 return error;