Skip to content

Commit 549c729

Browse files
author
Christian Brauner
committed
fs: make helpers idmap mount aware
Extend some inode methods with an additional user namespace argument. A filesystem that is aware of idmapped mounts will receive the user namespace the mount has been marked with. This can be used for additional permission checking and also to enable filesystems to translate between uids and gids if they need to. We have implemented all relevant helpers in earlier patches. As requested we simply extend the exisiting inode method instead of introducing new ones. This is a little more code churn but it's mostly mechanical and doesnt't leave us with additional inode methods. Link: https://lore.kernel.org/r/20210121131959.646623-25-christian.brauner@ubuntu.com Cc: Christoph Hellwig <hch@lst.de> Cc: David Howells <dhowells@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
1 parent 1ab2996 commit 549c729

182 files changed

Lines changed: 1121 additions & 756 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/filesystems/vfs.rst‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -415,28 +415,29 @@ As of kernel 2.6.22, the following members are defined:
415415
.. code-block:: c
416416
417417
struct inode_operations {
418-
int (*create) (struct inode *,struct dentry *, umode_t, bool);
418+
int (*create) (struct user_namespace *, struct inode *,struct dentry *, umode_t, bool);
419419
struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
420420
int (*link) (struct dentry *,struct inode *,struct dentry *);
421421
int (*unlink) (struct inode *,struct dentry *);
422-
int (*symlink) (struct inode *,struct dentry *,const char *);
423-
int (*mkdir) (struct inode *,struct dentry *,umode_t);
422+
int (*symlink) (struct user_namespace *, struct inode *,struct dentry *,const char *);
423+
int (*mkdir) (struct user_namespace *, struct inode *,struct dentry *,umode_t);
424424
int (*rmdir) (struct inode *,struct dentry *);
425-
int (*mknod) (struct inode *,struct dentry *,umode_t,dev_t);
426-
int (*rename) (struct inode *, struct dentry *,
425+
int (*mknod) (struct user_namespace *, struct inode *,struct dentry *,umode_t,dev_t);
426+
int (*rename) (struct user_namespace *, struct inode *, struct dentry *,
427427
struct inode *, struct dentry *, unsigned int);
428428
int (*readlink) (struct dentry *, char __user *,int);
429429
const char *(*get_link) (struct dentry *, struct inode *,
430430
struct delayed_call *);
431-
int (*permission) (struct inode *, int);
431+
int (*permission) (struct user_namespace *, struct inode *, int);
432432
int (*get_acl)(struct inode *, int);
433-
int (*setattr) (struct dentry *, struct iattr *);
434-
int (*getattr) (const struct path *, struct kstat *, u32, unsigned int);
433+
int (*setattr) (struct user_namespace *, struct dentry *, struct iattr *);
434+
int (*getattr) (struct user_namespace *, const struct path *, struct kstat *, u32, unsigned int);
435435
ssize_t (*listxattr) (struct dentry *, char *, size_t);
436436
void (*update_time)(struct inode *, struct timespec *, int);
437437
int (*atomic_open)(struct inode *, struct dentry *, struct file *,
438438
unsigned open_flag, umode_t create_mode);
439-
int (*tmpfile) (struct inode *, struct dentry *, umode_t);
439+
int (*tmpfile) (struct user_namespace *, struct inode *, struct dentry *, umode_t);
440+
int (*set_acl)(struct user_namespace *, struct inode *, struct posix_acl *, int);
440441
};
441442
442443
Again, all methods are called without any locks being held, unless

‎arch/powerpc/platforms/cell/spufs/inode.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ spufs_new_inode(struct super_block *sb, umode_t mode)
9191
}
9292

9393
static int
94-
spufs_setattr(struct dentry *dentry, struct iattr *attr)
94+
spufs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
95+
struct iattr *attr)
9596
{
9697
struct inode *inode = d_inode(dentry);
9798

‎drivers/android/binderfs.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,17 @@ static inline bool is_binderfs_control_device(const struct dentry *dentry)
355355
return info->control_dentry == dentry;
356356
}
357357

358-
static int binderfs_rename(struct inode *old_dir, struct dentry *old_dentry,
358+
static int binderfs_rename(struct user_namespace *mnt_userns,
359+
struct inode *old_dir, struct dentry *old_dentry,
359360
struct inode *new_dir, struct dentry *new_dentry,
360361
unsigned int flags)
361362
{
362363
if (is_binderfs_control_device(old_dentry) ||
363364
is_binderfs_control_device(new_dentry))
364365
return -EPERM;
365366

366-
return simple_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
367+
return simple_rename(&init_user_ns, old_dir, old_dentry, new_dir,
368+
new_dentry, flags);
367369
}
368370

369371
static int binderfs_unlink(struct inode *dir, struct dentry *dentry)

‎fs/9p/acl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
280280
struct iattr iattr = { 0 };
281281
struct posix_acl *old_acl = acl;
282282

283-
retval = posix_acl_update_mode(mnt_userns, inode,
283+
retval = posix_acl_update_mode(&init_user_ns, inode,
284284
&iattr.ia_mode, &acl);
285285
if (retval)
286286
goto err_out;
@@ -299,7 +299,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
299299
* What is the following setxattr update the
300300
* mode ?
301301
*/
302-
v9fs_vfs_setattr_dotl(dentry, &iattr);
302+
v9fs_vfs_setattr_dotl(&init_user_ns, dentry, &iattr);
303303
}
304304
break;
305305
case ACL_TYPE_DEFAULT:

‎fs/9p/v9fs.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
135135
unsigned int flags);
136136
extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);
137137
extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d);
138-
extern int v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
138+
extern int v9fs_vfs_rename(struct user_namespace *mnt_userns,
139+
struct inode *old_dir, struct dentry *old_dentry,
139140
struct inode *new_dir, struct dentry *new_dentry,
140141
unsigned int flags);
141142
extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,

‎fs/9p/v9fs_vfs.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat);
5959
int v9fs_uflags2omode(int uflags, int extended);
6060

6161
void v9fs_blank_wstat(struct p9_wstat *wstat);
62-
int v9fs_vfs_setattr_dotl(struct dentry *, struct iattr *);
62+
int v9fs_vfs_setattr_dotl(struct user_namespace *, struct dentry *,
63+
struct iattr *);
6364
int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end,
6465
int datasync);
6566
int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode);

‎fs/9p/vfs_inode.c‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
676676
*/
677677

678678
static int
679-
v9fs_vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
680-
bool excl)
679+
v9fs_vfs_create(struct user_namespace *mnt_userns, struct inode *dir,
680+
struct dentry *dentry, umode_t mode, bool excl)
681681
{
682682
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
683683
u32 perm = unixmode2p9mode(v9ses, mode);
@@ -702,7 +702,8 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
702702
*
703703
*/
704704

705-
static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
705+
static int v9fs_vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
706+
struct dentry *dentry, umode_t mode)
706707
{
707708
int err;
708709
u32 perm;
@@ -907,9 +908,9 @@ int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
907908
*/
908909

909910
int
910-
v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
911-
struct inode *new_dir, struct dentry *new_dentry,
912-
unsigned int flags)
911+
v9fs_vfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
912+
struct dentry *old_dentry, struct inode *new_dir,
913+
struct dentry *new_dentry, unsigned int flags)
913914
{
914915
int retval;
915916
struct inode *old_inode;
@@ -1016,8 +1017,8 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
10161017
*/
10171018

10181019
static int
1019-
v9fs_vfs_getattr(const struct path *path, struct kstat *stat,
1020-
u32 request_mask, unsigned int flags)
1020+
v9fs_vfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
1021+
struct kstat *stat, u32 request_mask, unsigned int flags)
10211022
{
10221023
struct dentry *dentry = path->dentry;
10231024
struct v9fs_session_info *v9ses;
@@ -1054,7 +1055,8 @@ v9fs_vfs_getattr(const struct path *path, struct kstat *stat,
10541055
*
10551056
*/
10561057

1057-
static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
1058+
static int v9fs_vfs_setattr(struct user_namespace *mnt_userns,
1059+
struct dentry *dentry, struct iattr *iattr)
10581060
{
10591061
int retval, use_dentry = 0;
10601062
struct v9fs_session_info *v9ses;
@@ -1295,7 +1297,8 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
12951297
*/
12961298

12971299
static int
1298-
v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1300+
v9fs_vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir,
1301+
struct dentry *dentry, const char *symname)
12991302
{
13001303
p9_debug(P9_DEBUG_VFS, " %lu,%pd,%s\n",
13011304
dir->i_ino, dentry, symname);
@@ -1348,7 +1351,8 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
13481351
*/
13491352

13501353
static int
1351-
v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev)
1354+
v9fs_vfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
1355+
struct dentry *dentry, umode_t mode, dev_t rdev)
13521356
{
13531357
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
13541358
int retval;

‎fs/9p/vfs_inode_dotl.c‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#include "acl.h"
3434

3535
static int
36-
v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
37-
dev_t rdev);
36+
v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, struct inode *dir,
37+
struct dentry *dentry, umode_t omode, dev_t rdev);
3838

3939
/**
4040
* v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
@@ -218,10 +218,10 @@ int v9fs_open_to_dotl_flags(int flags)
218218
*/
219219

220220
static int
221-
v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
222-
bool excl)
221+
v9fs_vfs_create_dotl(struct user_namespace *mnt_userns, struct inode *dir,
222+
struct dentry *dentry, umode_t omode, bool excl)
223223
{
224-
return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0);
224+
return v9fs_vfs_mknod_dotl(mnt_userns, dir, dentry, omode, 0);
225225
}
226226

227227
static int
@@ -367,8 +367,9 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
367367
*
368368
*/
369369

370-
static int v9fs_vfs_mkdir_dotl(struct inode *dir,
371-
struct dentry *dentry, umode_t omode)
370+
static int v9fs_vfs_mkdir_dotl(struct user_namespace *mnt_userns,
371+
struct inode *dir, struct dentry *dentry,
372+
umode_t omode)
372373
{
373374
int err;
374375
struct v9fs_session_info *v9ses;
@@ -457,8 +458,9 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
457458
}
458459

459460
static int
460-
v9fs_vfs_getattr_dotl(const struct path *path, struct kstat *stat,
461-
u32 request_mask, unsigned int flags)
461+
v9fs_vfs_getattr_dotl(struct user_namespace *mnt_userns,
462+
const struct path *path, struct kstat *stat,
463+
u32 request_mask, unsigned int flags)
462464
{
463465
struct dentry *dentry = path->dentry;
464466
struct v9fs_session_info *v9ses;
@@ -540,7 +542,8 @@ static int v9fs_mapped_iattr_valid(int iattr_valid)
540542
*
541543
*/
542544

543-
int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
545+
int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_userns,
546+
struct dentry *dentry, struct iattr *iattr)
544547
{
545548
int retval, use_dentry = 0;
546549
struct p9_fid *fid = NULL;
@@ -684,8 +687,8 @@ v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,
684687
}
685688

686689
static int
687-
v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
688-
const char *symname)
690+
v9fs_vfs_symlink_dotl(struct user_namespace *mnt_userns, struct inode *dir,
691+
struct dentry *dentry, const char *symname)
689692
{
690693
int err;
691694
kgid_t gid;
@@ -824,8 +827,8 @@ v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
824827
*
825828
*/
826829
static int
827-
v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
828-
dev_t rdev)
830+
v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, struct inode *dir,
831+
struct dentry *dentry, umode_t omode, dev_t rdev)
829832
{
830833
int err;
831834
kgid_t gid;

‎fs/adfs/adfs.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ struct adfs_discmap {
144144
/* Inode stuff */
145145
struct inode *adfs_iget(struct super_block *sb, struct object_info *obj);
146146
int adfs_write_inode(struct inode *inode, struct writeback_control *wbc);
147-
int adfs_notify_change(struct dentry *dentry, struct iattr *attr);
147+
int adfs_notify_change(struct user_namespace *mnt_userns, struct dentry *dentry,
148+
struct iattr *attr);
148149

149150
/* map.c */
150151
int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset);

‎fs/adfs/inode.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ adfs_iget(struct super_block *sb, struct object_info *obj)
292292
* later.
293293
*/
294294
int
295-
adfs_notify_change(struct dentry *dentry, struct iattr *attr)
295+
adfs_notify_change(struct user_namespace *mnt_userns, struct dentry *dentry,
296+
struct iattr *attr)
296297
{
297298
struct inode *inode = d_inode(dentry);
298299
struct super_block *sb = inode->i_sb;

0 commit comments

Comments
 (0)