diff options
author | Miklos Szeredi <mszeredi@redhat.com> | 2023-10-25 16:01:59 +0200 |
---|---|---|
committer | Christian Brauner <brauner@kernel.org> | 2023-11-18 14:56:16 +0100 |
commit | 98d2b43081972abeb5bb5a087bc3e3197531c46e (patch) | |
tree | b56d8e448127d642c39b6fad6f14a5166666d3f1 /fs/namespace.c | |
parent | Linux 6.7-rc1 (diff) | |
download | linux-98d2b43081972abeb5bb5a087bc3e3197531c46e.tar.xz linux-98d2b43081972abeb5bb5a087bc3e3197531c46e.zip |
add unique mount ID
If a mount is released then its mnt_id can immediately be reused. This is
bad news for user interfaces that want to uniquely identify a mount.
Implementing a unique mount ID is trivial (use a 64bit counter).
Unfortunately userspace assumes 32bit size and would overflow after the
counter reaches 2^32.
Introduce a new 64bit ID alongside the old one. Initialize the counter to
2^32, this guarantees that the old and new IDs are never mixed up.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Link: https://lore.kernel.org/r/20231025140205.3586473-2-mszeredi@redhat.com
Reviewed-by: Ian Kent <raven@themaw.net>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs/namespace.c')
-rw-r--r-- | fs/namespace.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/namespace.c b/fs/namespace.c index fbf0e596fcd3..0bcba81402b5 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -68,6 +68,9 @@ static u64 event; static DEFINE_IDA(mnt_id_ida); static DEFINE_IDA(mnt_group_ida); +/* Don't allow confusion with old 32bit mount ID */ +static atomic64_t mnt_id_ctr = ATOMIC64_INIT(1ULL << 32); + static struct hlist_head *mount_hashtable __ro_after_init; static struct hlist_head *mountpoint_hashtable __ro_after_init; static struct kmem_cache *mnt_cache __ro_after_init; @@ -131,6 +134,7 @@ static int mnt_alloc_id(struct mount *mnt) if (res < 0) return res; mnt->mnt_id = res; + mnt->mnt_id_unique = atomic64_inc_return(&mnt_id_ctr); return 0; } |