ANDROID: mnt: Add filesystem private data to mount points (v2)

This starts to add private data associated directly
to mount points. The intent is to give filesystems
a sense of where they have come from, as a means of
letting a filesystem take different actions based on
this information.

(v2)
Changes due to commit:
68847c941700 ("namespace: take lock_mount_hash() directly when changing flags")

Bug: 62094374
Bug: 120446149
Bug: 122428178
Change-Id: Ie769d7b3bb2f5972afe05c1bf16cf88c91647ab2
Signed-off-by: Daniel Rosenberg <drosen@google.com>
[adelva: Folded 89a54ed3bf68 ("ANDROID: mnt: Fix next_descendent")
            into this patch]
[drosen: Folded 138993e ("Android: mnt: Propagate remount
         correctly") into this patch, integrated fs_context things
	 Now has update_mnt_data instead of needing remount2
[maennich: Folded cbfbd9e932de ("ANDROID: mnt: Fix null pointer
           dereference") into this patch]
Signed-off-by: Alistair Delva <adelva@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
This commit is contained in:
Mauro Rossi authored and Yumi Yukimura committed 2025-08-31 23:56:41 +08:00
1 parent 0144617f5f
commit 11464a6b51
5 files changed
+54 -1

No files matched your search

+33 -1
View File
@@ -201,6 +201,7 @@ static struct mount *alloc_vfsmnt(const char *name)
mnt->mnt_count = 1; mnt->mnt_count = 1;
mnt->mnt_writers = 0; mnt->mnt_writers = 0;
#endif #endif
mnt->mnt.data = NULL;
INIT_HLIST_NODE(&mnt->mnt_hash); INIT_HLIST_NODE(&mnt->mnt_hash);
INIT_LIST_HEAD(&mnt->mnt_child); INIT_LIST_HEAD(&mnt->mnt_child);
@@ -540,6 +541,7 @@ int sb_prepare_remount_readonly(struct super_block *sb)
static void free_vfsmnt(struct mount *mnt) static void free_vfsmnt(struct mount *mnt)
{ {
kfree(mnt->mnt.data);
kfree_const(mnt->mnt_devname); kfree_const(mnt->mnt_devname);
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
free_percpu(mnt->mnt_pcp); free_percpu(mnt->mnt_pcp);
@@ -942,14 +944,26 @@ static struct mount *skip_mnt_tree(struct mount *p)
struct vfsmount *vfs_create_mount(struct fs_context *fc) struct vfsmount *vfs_create_mount(struct fs_context *fc)
{ {
struct mount *mnt; struct mount *mnt;
struct super_block *sb;
if (!fc->root) if (!fc->root)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
sb = fc->root->d_sb;
mnt = alloc_vfsmnt(fc->source ?: "none"); mnt = alloc_vfsmnt(fc->source ?: "none");
if (!mnt) if (!mnt)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (fc->fs_type->alloc_mnt_data) {
mnt->mnt.data = fc->fs_type->alloc_mnt_data();
if (!mnt->mnt.data) {
mnt_free_id(mnt);
free_vfsmnt(mnt);
return ERR_PTR(-ENOMEM);
}
if (sb->s_op->update_mnt_data)
sb->s_op->update_mnt_data(mnt->mnt.data, fc);
}
if (fc->sb_flags & SB_KERNMOUNT) if (fc->sb_flags & SB_KERNMOUNT)
mnt->mnt.mnt_flags = MNT_INTERNAL; mnt->mnt.mnt_flags = MNT_INTERNAL;
@@ -1033,6 +1047,14 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
if (!mnt) if (!mnt)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (sb->s_op->clone_mnt_data) {
mnt->mnt.data = sb->s_op->clone_mnt_data(old->mnt.data);
if (!mnt->mnt.data) {
err = -ENOMEM;
goto out_free;
}
}
if (flag & (CL_SLAVE | CL_PRIVATE | CL_SHARED_TO_SLAVE)) if (flag & (CL_SLAVE | CL_PRIVATE | CL_SHARED_TO_SLAVE))
mnt->mnt_group_id = 0; /* not a peer of original */ mnt->mnt_group_id = 0; /* not a peer of original */
else else
@@ -2409,7 +2431,17 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags,
err = -EPERM; err = -EPERM;
if (ns_capable(sb->s_user_ns, CAP_SYS_ADMIN)) { if (ns_capable(sb->s_user_ns, CAP_SYS_ADMIN)) {
err = reconfigure_super(fc); err = reconfigure_super(fc);
if (!err) { if (!err && sb->s_op->update_mnt_data) {
sb->s_op->update_mnt_data(mnt->mnt.data, fc);
lock_mount_hash();
set_mount_attributes(mnt, mnt_flags);
unlock_mount_hash();
namespace_lock();
lock_mount_hash();
propagate_remount(mnt);
unlock_mount_hash();
namespace_unlock();
} else if (!err) {
lock_mount_hash(); lock_mount_hash();
set_mount_attributes(mnt, mnt_flags); set_mount_attributes(mnt, mnt_flags);
unlock_mount_hash(); unlock_mount_hash();
+15
View File
@@ -607,3 +607,18 @@ int propagate_umount(struct list_head *list)
return 0; return 0;
} }
void propagate_remount(struct mount *mnt)
{
struct mount *parent = mnt->mnt_parent;
struct mount *p = mnt, *m;
struct super_block *sb = mnt->mnt.mnt_sb;
if (!sb->s_op->copy_mnt_data)
return;
for (p = propagation_next(parent, parent); p;
p = propagation_next(p, parent)) {
m = __lookup_mnt(&p->mnt, mnt->mnt_mountpoint);
if (m)
sb->s_op->copy_mnt_data(m->mnt.data, mnt->mnt.data);
}
}
+1
View File
@@ -44,6 +44,7 @@ int propagate_mnt(struct mount *, struct mountpoint *, struct mount *,
int propagate_umount(struct list_head *); int propagate_umount(struct list_head *);
int propagate_mount_busy(struct mount *, int); int propagate_mount_busy(struct mount *, int);
void propagate_mount_unlock(struct mount *); void propagate_mount_unlock(struct mount *);
void propagate_remount(struct mount *);
void mnt_release_group_id(struct mount *); void mnt_release_group_id(struct mount *);
int get_dominating_id(struct mount *mnt, const struct path *root); int get_dominating_id(struct mount *mnt, const struct path *root);
unsigned int mnt_get_count(struct mount *mnt); unsigned int mnt_get_count(struct mount *mnt);
+4
View File
@@ -1974,6 +1974,9 @@ struct super_operations {
int (*unfreeze_fs) (struct super_block *); int (*unfreeze_fs) (struct super_block *);
int (*statfs) (struct dentry *, struct kstatfs *); int (*statfs) (struct dentry *, struct kstatfs *);
int (*remount_fs) (struct super_block *, int *, char *); int (*remount_fs) (struct super_block *, int *, char *);
void *(*clone_mnt_data) (void *);
void (*copy_mnt_data) (void *, void *);
void (*update_mnt_data) (void *, struct fs_context *);
void (*umount_begin) (struct super_block *); void (*umount_begin) (struct super_block *);
void (*umount_end)(struct super_block *sb, int flags); void (*umount_end)(struct super_block *sb, int flags);
@@ -2254,6 +2257,7 @@ struct file_system_type {
const struct fs_parameter_description *parameters; const struct fs_parameter_description *parameters;
struct dentry *(*mount) (struct file_system_type *, int, struct dentry *(*mount) (struct file_system_type *, int,
const char *, void *); const char *, void *);
void *(*alloc_mnt_data) (void);
void (*kill_sb) (struct super_block *); void (*kill_sb) (struct super_block *);
struct module *owner; struct module *owner;
struct file_system_type * next; struct file_system_type * next;
+1
View File
@@ -70,6 +70,7 @@ struct vfsmount {
struct dentry *mnt_root; /* root of the mounted tree */ struct dentry *mnt_root; /* root of the mounted tree */
struct super_block *mnt_sb; /* pointer to superblock */ struct super_block *mnt_sb; /* pointer to superblock */
int mnt_flags; int mnt_flags;
void *data;
ANDROID_KABI_RESERVE(1); ANDROID_KABI_RESERVE(1);
ANDROID_KABI_RESERVE(2); ANDROID_KABI_RESERVE(2);
ANDROID_KABI_RESERVE(3); ANDROID_KABI_RESERVE(3);