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
16641664 static inline void inode_fsuid_set(struct inode *inode,
16651665 struct user_namespace *mnt_userns)
16661666 {
1667− inode->i_uid = mapped_fsuid(mnt_userns);
1667+ inode->i_uid = mapped_fsuid(mnt_userns, &init_user_ns);
16681668 }
16691669
16701670 /**
@@ -1678,7 +1678,7 @@ static inline void inode_fsuid_set(struct inode *inode, · 7 unmodified lines
16781678 static inline void inode_fsgid_set(struct inode *inode,
16791679 struct user_namespace *mnt_userns)
16801680 {
1681− inode->i_gid = mapped_fsgid(mnt_userns);
1681+ inode->i_gid = mapped_fsgid(mnt_userns, &init_user_ns);
16821682 }
16831683
16841684 /**
@@ -1699,10 +1699,10 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb, · 14 unmodified lines
16991699 kuid_t kuid;
17001700 kgid_t kgid;
17011701
1702− kuid = mapped_fsuid(mnt_userns);
1702+ kuid = mapped_fsuid(mnt_userns, &init_user_ns);
17031703 if (!uid_valid(kuid))
17041704 return false;
1705− kgid = mapped_fsgid(mnt_userns);
1705+ kgid = mapped_fsgid(mnt_userns, &init_user_ns);
17061706 if (!gid_valid(kgid))
17071707 return false;
17081708 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
196196 /**
197197 * mapped_fsuid - return caller's fsuid mapped up into a mnt_userns
198198 * @mnt_userns: the mount's idmapping
199+ * @fs_userns: the filesystem's idmapping
199200 *
200201 * Use this helper to initialize a new vfs or filesystem object based on
201202 * 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
205206 *
206207 * Return: the caller's current fsuid mapped up according to @mnt_userns.
207208 */
208−static inline kuid_t mapped_fsuid(struct user_namespace *mnt_userns)
209+static inline kuid_t mapped_fsuid(struct user_namespace *mnt_userns,
210+ struct user_namespace *fs_userns)
209211 {
210− return mapped_kuid_user(mnt_userns, &init_user_ns, current_fsuid());
212+ return mapped_kuid_user(mnt_userns, fs_userns, current_fsuid());
211213 }
212214
213215 /**
214216 * mapped_fsgid - return caller's fsgid mapped up into a mnt_userns
215217 * @mnt_userns: the mount's idmapping
218+ * @fs_userns: the filesystem's idmapping
216219 *
217220 * Use this helper to initialize a new vfs or filesystem object based on
218221 * 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
222225 *
223226 * Return: the caller's current fsgid mapped up according to @mnt_userns.
224227 */
225−static inline kgid_t mapped_fsgid(struct user_namespace *mnt_userns)
228+static inline kgid_t mapped_fsgid(struct user_namespace *mnt_userns,
229+ struct user_namespace *fs_userns)
226230 {
227− return mapped_kgid_user(mnt_userns, &init_user_ns, current_fsgid());
231+ return mapped_kgid_user(mnt_userns, fs_userns, current_fsgid());
228232 }
229233
230234 #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