aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeth Forshee <seth.forshee@canonical.com>2014-12-11 11:15:45 -0500
committerEric W. Biederman <ebiederm@xmission.com>2016-07-05 16:13:21 -0400
commit81754357770ebd900801231e7bc8d151ddc00498 (patch)
treefe0e30f8ef4847787e8be19b21087fdb0d369580
parent0b3c9761d1e405514a551ed24d3ea89aea26ce14 (diff)
fs: Update i_[ug]id_(read|write) to translate relative to s_user_ns
For filesystems mounted from a user namespace on-disk ids should be translated relative to s_users_ns rather than init_user_ns. When an id in the filesystem doesn't exist in s_user_ns the associated id in the inode will be set to INVALID_[UG]ID, which turns these into de facto "nobody" ids. This actually maps pretty well into the way most code already works, and those places where it didn't were fixed in previous patches. Moving forward vfs code needs to be careful to handle instances where ids in inodes may be invalid. Signed-off-by: Seth Forshee <seth.forshee@canonical.com> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
-rw-r--r--include/linux/fs.h50
1 files changed, 25 insertions, 25 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h
index cb25ceb6d1ef..8aa9b72e0bc5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -831,31 +831,6 @@ static inline void i_size_write(struct inode *inode, loff_t i_size)
831#endif 831#endif
832} 832}
833 833
834/* Helper functions so that in most cases filesystems will
835 * not need to deal directly with kuid_t and kgid_t and can
836 * instead deal with the raw numeric values that are stored
837 * in the filesystem.
838 */
839static inline uid_t i_uid_read(const struct inode *inode)
840{
841 return from_kuid(&init_user_ns, inode->i_uid);
842}
843
844static inline gid_t i_gid_read(const struct inode *inode)
845{
846 return from_kgid(&init_user_ns, inode->i_gid);
847}
848
849static inline void i_uid_write(struct inode *inode, uid_t uid)
850{
851 inode->i_uid = make_kuid(&init_user_ns, uid);
852}
853
854static inline void i_gid_write(struct inode *inode, gid_t gid)
855{
856 inode->i_gid = make_kgid(&init_user_ns, gid);
857}
858
859static inline unsigned iminor(const struct inode *inode) 834static inline unsigned iminor(const struct inode *inode)
860{ 835{
861 return MINOR(inode->i_rdev); 836 return MINOR(inode->i_rdev);
@@ -1461,6 +1436,31 @@ struct super_block {
1461 struct list_head s_inodes; /* all inodes */ 1436 struct list_head s_inodes; /* all inodes */
1462}; 1437};
1463 1438
1439/* Helper functions so that in most cases filesystems will
1440 * not need to deal directly with kuid_t and kgid_t and can
1441 * instead deal with the raw numeric values that are stored
1442 * in the filesystem.
1443 */
1444static inline uid_t i_uid_read(const struct inode *inode)
1445{
1446 return from_kuid(inode->i_sb->s_user_ns, inode->i_uid);
1447}
1448
1449static inline gid_t i_gid_read(const struct inode *inode)
1450{
1451 return from_kgid(inode->i_sb->s_user_ns, inode->i_gid);
1452}
1453
1454static inline void i_uid_write(struct inode *inode, uid_t uid)
1455{
1456 inode->i_uid = make_kuid(inode->i_sb->s_user_ns, uid);
1457}
1458
1459static inline void i_gid_write(struct inode *inode, gid_t gid)
1460{
1461 inode->i_gid = make_kgid(inode->i_sb->s_user_ns, gid);
1462}
1463
1464extern struct timespec current_fs_time(struct super_block *sb); 1464extern struct timespec current_fs_time(struct super_block *sb);
1465 1465
1466/* 1466/*