fs: port ->tmpfile() to pass mnt_idmap

Convert to struct mnt_idmap.

Last cycle we merged the necessary infrastructure in
256c8aed2b ("fs: introduce dedicated idmap type for mounts").
This is just the conversion to struct mnt_idmap.

Currently we still pass around the plain namespace that was attached to a
mount. This is in general pretty convenient but it makes it easy to
conflate namespaces that are relevant on the filesystem with namespaces
that are relevent on the mount level. Especially for non-vfs developers
without detailed knowledge in this area this can be a potential source for
bugs.

Once the conversion to struct mnt_idmap is done all helpers down to the
really low-level helpers will take a struct mnt_idmap argument instead of
two namespace arguments. This way it becomes impossible to conflate the two
eliminating the possibility of any bugs. All of the vfs and all filesystems
only operate on struct mnt_idmap.

Acked-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2023-01-13 12:49:18 +01:00 коммит произвёл Christian Brauner (Microsoft)
Родитель e18275ae55
Коммит 011e2b717b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 91C61BC06578DCA2
17 изменённых файлов: 22 добавлений и 17 удалений

Просмотреть файл

@ -79,7 +79,7 @@ prototypes::
int (*atomic_open)(struct inode *, struct dentry *,
struct file *, unsigned open_flag,
umode_t create_mode);
int (*tmpfile) (struct user_namespace *, struct inode *,
int (*tmpfile) (struct mnt_idmap *, struct inode *,
struct file *, umode_t);
int (*fileattr_set)(struct user_namespace *mnt_userns,
struct dentry *dentry, struct fileattr *fa);

Просмотреть файл

@ -442,7 +442,7 @@ As of kernel 2.6.22, the following members are defined:
void (*update_time)(struct inode *, struct timespec *, int);
int (*atomic_open)(struct inode *, struct dentry *, struct file *,
unsigned open_flag, umode_t create_mode);
int (*tmpfile) (struct user_namespace *, struct inode *, struct file *, umode_t);
int (*tmpfile) (struct mnt_idmap *, struct inode *, struct file *, umode_t);
struct posix_acl * (*get_acl)(struct user_namespace *, struct dentry *, int);
int (*set_acl)(struct user_namespace *, struct dentry *, struct posix_acl *, int);
int (*fileattr_set)(struct user_namespace *mnt_userns,

Просмотреть файл

@ -146,7 +146,7 @@ static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry,
return -EIO;
}
static int bad_inode_tmpfile(struct user_namespace *mnt_userns,
static int bad_inode_tmpfile(struct mnt_idmap *idmap,
struct inode *inode, struct file *file,
umode_t mode)
{

Просмотреть файл

@ -10095,9 +10095,10 @@ static int btrfs_permission(struct user_namespace *mnt_userns,
return generic_permission(mnt_userns, inode, mask);
}
static int btrfs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
static int btrfs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
struct btrfs_fs_info *fs_info = btrfs_sb(dir->i_sb);
struct btrfs_trans_handle *trans;
struct btrfs_root *root = BTRFS_I(dir)->root;

Просмотреть файл

@ -119,7 +119,7 @@ static int ext2_create (struct mnt_idmap * idmap,
return ext2_add_nondir(dentry, inode);
}
static int ext2_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
static int ext2_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode)
{
struct inode *inode = ext2_new_inode(dir, mode, NULL);

Просмотреть файл

@ -2863,9 +2863,10 @@ retry:
return err;
}
static int ext4_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
static int ext4_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
handle_t *handle;
struct inode *inode;
int err, retries = 0;

Просмотреть файл

@ -911,9 +911,10 @@ out:
return err;
}
static int f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
static int f2fs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
int err;

Просмотреть файл

@ -802,7 +802,7 @@ static int fuse_create(struct mnt_idmap *idmap, struct inode *dir,
return fuse_mknod(&nop_mnt_idmap, dir, entry, mode, 0);
}
static int fuse_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
static int fuse_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode)
{
struct fuse_conn *fc = get_fuse_conn(dir);

Просмотреть файл

@ -1050,7 +1050,7 @@ static int hugetlbfs_create(struct mnt_idmap *idmap,
return hugetlbfs_mknod(&nop_mnt_idmap, dir, dentry, mode | S_IFREG, 0);
}
static int hugetlbfs_tmpfile(struct user_namespace *mnt_userns,
static int hugetlbfs_tmpfile(struct mnt_idmap *idmap,
struct inode *dir, struct file *file,
umode_t mode)
{

Просмотреть файл

@ -52,7 +52,7 @@ static int minix_mknod(struct mnt_idmap *idmap, struct inode *dir,
return error;
}
static int minix_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
static int minix_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode)
{
int error;

Просмотреть файл

@ -3613,7 +3613,7 @@ static int vfs_tmpfile(struct mnt_idmap *idmap,
file->f_path.mnt = parentpath->mnt;
file->f_path.dentry = child;
mode = vfs_prepare_mode(mnt_userns, dir, mode, mode, mode);
error = dir->i_op->tmpfile(mnt_userns, dir, file, mode);
error = dir->i_op->tmpfile(idmap, dir, file, mode);
dput(child);
if (error)
return error;

Просмотреть файл

@ -145,7 +145,7 @@ static int ramfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
return error;
}
static int ramfs_tmpfile(struct user_namespace *mnt_userns,
static int ramfs_tmpfile(struct mnt_idmap *idmap,
struct inode *dir, struct file *file, umode_t mode)
{
struct inode *inode;

Просмотреть файл

@ -426,7 +426,7 @@ static void unlock_2_inodes(struct inode *inode1, struct inode *inode2)
mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
}
static int ubifs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
static int ubifs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode)
{
struct dentry *dentry = file->f_path.dentry;

Просмотреть файл

@ -625,7 +625,7 @@ static int udf_create(struct mnt_idmap *idmap, struct inode *dir,
return udf_add_nondir(dentry, inode);
}
static int udf_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
static int udf_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode)
{
struct inode *inode = udf_new_inode(dir, mode);

Просмотреть файл

@ -1098,11 +1098,13 @@ xfs_vn_fiemap(
STATIC int
xfs_vn_tmpfile(
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct inode *dir,
struct file *file,
umode_t mode)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
int err = xfs_generic_create(mnt_userns, dir, file->f_path.dentry, mode, 0, file);
return finish_open_simple(file, err);

Просмотреть файл

@ -2162,7 +2162,7 @@ struct inode_operations {
int (*atomic_open)(struct inode *, struct dentry *,
struct file *, unsigned open_flag,
umode_t create_mode);
int (*tmpfile) (struct user_namespace *, struct inode *,
int (*tmpfile) (struct mnt_idmap *, struct inode *,
struct file *, umode_t);
struct posix_acl *(*get_acl)(struct user_namespace *, struct dentry *,
int);

Просмотреть файл

@ -2946,7 +2946,7 @@ out_iput:
}
static int
shmem_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
shmem_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
struct file *file, umode_t mode)
{
struct inode *inode;