History

fs: port higher-level mapping helpers

Enable the mapped_fs{g,u}id() helpers to support filesystems mounted with an idmapping. Apart from core mapping helpers that use mapped_fs{g,u}id() to initialize struct inode's i_{g,u}id fields xfs is the only place that uses these low-level helpers directly. The patch only extends the helpers to be able to take the filesystem idmapping into account. Since we don't actually yet pass the filesystem's idmapping in no functional changes happen. This will happen in a final patch.

Christian Brauner committed 4 years ago

Commit 209188c1 parent 02e40794 files · +18 −14Browse files

Showing the changes to include (2 of 4 files). Show all

Unified · Split

2 files
  1. include/linux/fs.h +4 −4
  2. include/linux/mnt_idmapping.h +8 −4
include/linux/fs.h+4−4
@@ -1664,7 +1664,7 @@ static inline kgid_t i_gid_into_mnt(struct user_namespace *mnt_userns, · 1663 unmodified lines
1664static inline void inode_fsuid_set(struct inode *inode,1664static inline void inode_fsuid_set(struct inode *inode,
1665 struct user_namespace *mnt_userns)1665 struct user_namespace *mnt_userns)
1666{1666{
1667 inode->i_uid = mapped_fsuid(mnt_userns);1667 inode->i_uid = mapped_fsuid(mnt_userns, &init_user_ns);
1668}1668}
1669 1669
1670/**1670/**
@@ -1678,7 +1678,7 @@ static inline void inode_fsuid_set(struct inode *inode, · 7 unmodified lines
1678static inline void inode_fsgid_set(struct inode *inode,1678static inline void inode_fsgid_set(struct inode *inode,
1679 struct user_namespace *mnt_userns)1679 struct user_namespace *mnt_userns)
1680{1680{
1681 inode->i_gid = mapped_fsgid(mnt_userns);1681 inode->i_gid = mapped_fsgid(mnt_userns, &init_user_ns);
1682}1682}
1683 1683
1684/**1684/**
@@ -1699,10 +1699,10 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb, · 14 unmodified lines
1699 kuid_t kuid;1699 kuid_t kuid;
1700 kgid_t kgid;1700 kgid_t kgid;
1701 1701
1702 kuid = mapped_fsuid(mnt_userns);1702 kuid = mapped_fsuid(mnt_userns, &init_user_ns);
1703 if (!uid_valid(kuid))1703 if (!uid_valid(kuid))
1704 return false;1704 return false;
1705 kgid = mapped_fsgid(mnt_userns);1705 kgid = mapped_fsgid(mnt_userns, &init_user_ns);
1706 if (!gid_valid(kgid))1706 if (!gid_valid(kgid))
1707 return false;1707 return false;
1708 return kuid_has_mapping(fs_userns, kuid) &&1708 return kuid_has_mapping(fs_userns, kuid) &&
include/linux/mnt_idmapping.h+8−4
@@ -196,6 +196,7 @@ static inline kgid_t mapped_kgid_user(struct user_namespace *mnt_userns, · 195 unmodified lines
196/**196/**
197 * mapped_fsuid - return caller's fsuid mapped up into a mnt_userns197 * mapped_fsuid - return caller's fsuid mapped up into a mnt_userns
198 * @mnt_userns: the mount's idmapping198 * @mnt_userns: the mount's idmapping
199 * @fs_userns: the filesystem's idmapping
199 *200 *
200 * Use this helper to initialize a new vfs or filesystem object based on201 * Use this helper to initialize a new vfs or filesystem object based on
201 * the caller's fsuid. A common example is initializing the i_uid field of202 * the caller's fsuid. A common example is initializing the i_uid field of
@@ -205,14 +206,16 @@ static inline kgid_t mapped_kgid_user(struct user_namespace *mnt_userns, · 3 unmodified lines
205 *206 *
206 * Return: the caller's current fsuid mapped up according to @mnt_userns.207 * Return: the caller's current fsuid mapped up according to @mnt_userns.
207 */208 */
208static inline kuid_t mapped_fsuid(struct user_namespace *mnt_userns)209static inline kuid_t mapped_fsuid(struct user_namespace *mnt_userns,
210 struct user_namespace *fs_userns)
209{211{
210 return mapped_kuid_user(mnt_userns, &init_user_ns, current_fsuid());212 return mapped_kuid_user(mnt_userns, fs_userns, current_fsuid());
211}213}
212 214
213/**215/**
214 * mapped_fsgid - return caller's fsgid mapped up into a mnt_userns216 * mapped_fsgid - return caller's fsgid mapped up into a mnt_userns
215 * @mnt_userns: the mount's idmapping217 * @mnt_userns: the mount's idmapping
218 * @fs_userns: the filesystem's idmapping
216 *219 *
217 * Use this helper to initialize a new vfs or filesystem object based on220 * Use this helper to initialize a new vfs or filesystem object based on
218 * the caller's fsgid. A common example is initializing the i_gid field of221 * the caller's fsgid. A common example is initializing the i_gid field of
@@ -222,9 +225,10 @@ static inline kuid_t mapped_fsuid(struct user_namespace *mnt_userns) · 3 unmodified lines
222 *225 *
223 * Return: the caller's current fsgid mapped up according to @mnt_userns.226 * Return: the caller's current fsgid mapped up according to @mnt_userns.
224 */227 */
225static inline kgid_t mapped_fsgid(struct user_namespace *mnt_userns)228static inline kgid_t mapped_fsgid(struct user_namespace *mnt_userns,
229 struct user_namespace *fs_userns)
226{230{
227 return mapped_kgid_user(mnt_userns, &init_user_ns, current_fsgid());231 return mapped_kgid_user(mnt_userns, fs_userns, current_fsgid());
228}232}
229 233
230#endif /* _LINUX_MNT_IDMAPPING_H */234#endif /* _LINUX_MNT_IDMAPPING_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t