* [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes
@ 2026-11-17 5:52 Eva Kurchatova
2026-11-17 5:52 ` [Devel] [PATCH hci-8.1 1/2] ms/ext4: free the sbi after a grace period Eva Kurchatova
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Eva Kurchatova @ 2026-11-17 5:52 UTC (permalink / raw)
To: khorenko; +Cc: devel
Patchset for task https://virtuozzo.atlassian.net/browse/VSTOR-155414
Christian Brauner (2):
ms/ext4: free the sbi after a grace period
ms/unicode: free the map after a grace period
fs/ext4/ext4.h | 2 ++
fs/ext4/extents_status.c | 7 ++++++-
fs/ext4/extents_status.h | 1 +
fs/ext4/super.c | 13 +++++++++++--
fs/unicode/utf8-core.c | 21 +++++++++++++++++----
include/linux/unicode.h | 1 +
6 files changed, 38 insertions(+), 7 deletions(-)
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Devel] [PATCH hci-8.1 1/2] ms/ext4: free the sbi after a grace period
2026-11-17 5:52 [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes Eva Kurchatova
@ 2026-11-17 5:52 ` Eva Kurchatova
2026-11-17 6:02 ` no-reply
2026-11-17 5:52 ` [Devel] [PATCH hci-8.1 2/2] ms/unicode: free the map " Eva Kurchatova
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Eva Kurchatova @ 2026-11-17 5:52 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Christian Brauner <brauner@kernel.org>
[ Upstream commit c17b44266a1f9fcb49b894d4611d1254bf1aa313 ]
ext4_get_link() follows a symlink that keeps its target in a data block
in rcu pathwalk mode with ext4_getblk(EXT4_GET_BLOCKS_CACHED_NOWAIT).
That reads s_mount_state in the ASSERT() of ext4_getblk() and again in
ext4_es_lookup_extent(), and the lookup bumps the extent status hit or
miss counter, all through sb->s_fs_info.
ext4_put_super() destroys those counters, clears sb->s_fs_info and frees
the sbi without waiting for a grace period. A pathwalk that is still in
ext4_get_link() when the last reference to the mount goes away then
dereferences a NULL s_fs_info, the freed sbi or the destroyed percpu
counters.
With a pathwalk held up in ext4_get_link() while the last reference
goes away:
KASAN: null-ptr-deref in range [0x00000000000000a8-0x00000000000000af]
RIP: 0010:ext4_getblk+0xf0/0x640
Call Trace:
<TASK>
ext4_get_link+0x26c/0x410
pick_link+0xf96/0x1780
step_into_slowpath+0x9b8/0x1250
path_lookupat+0x484/0xb00
filename_lookup+0x1f1/0x5b0
vfs_statx+0xd7/0x3b0
vfs_fstatat+0x4d/0x90
__do_sys_newfstatat+0xa0/0x100
do_syscall_64+0x10e/0x5e0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
So far that has been hard to hit. umount(2) waits for a grace period in
namespace_unlock() before it drops the mount, so only a mount whose last
reference goes away elsewhere, like the close of a file or a chdir out of
a lazily unmounted directory, can race a walker.
Keep sb->s_fs_info and free the sbi together with the extent status
counters after a grace period. Split the counters out of
ext4_es_unregister_shrinker() for that. The shrinker still gets wasted
in ext4_put_super(), the counters go with the sbi.
Fixes: 6493792d3299 ("ext4: convert symlink external data block mapping to bdev")
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261009-work-fixes-rcu-v1-1-7446d2d335e6@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
[ sashal: omitted ext4_es_destroy_stats() integration with the extent KUnit tests ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 4ce0e27ea610663a9cdc04e3bca38559147428d4)
https://virtuozzo.atlassian.net/browse/VSTOR-155414
Feature: fix ms/fs
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
fs/ext4/ext4.h | 2 ++
fs/ext4/extents_status.c | 7 ++++++-
fs/ext4/extents_status.h | 1 +
fs/ext4/super.c | 13 +++++++++++--
4 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 3fe70a19e2a7..3de0fc6e77f2 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1690,6 +1690,8 @@ struct ext4_sb_info {
struct list_head s_es_list; /* List of inodes with reclaimable extents */
long s_es_nr_inode;
struct ext4_es_stats s_es_stats;
+ /* ext4_get_link() reads the sbi in rcu pathwalk */
+ struct rcu_head s_rcu;
struct mb_cache *s_ea_block_cache;
struct mb_cache *s_ea_inode_cache;
spinlock_t s_es_lock ____cacheline_aligned_in_smp;
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 89fc81a80f9a..cb3432b812a6 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -1804,12 +1804,17 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi)
}
void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi)
+{
+ shrinker_free(sbi->s_es_shrinker);
+}
+
+/* ext4_get_link() bumps the hit and miss counters in rcu pathwalk */
+void ext4_es_destroy_stats(struct ext4_sb_info *sbi)
{
percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_hits);
percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses);
percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt);
percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt);
- shrinker_free(sbi->s_es_shrinker);
}
/*
diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h
index 8f9c008d11e8..502d9110a73c 100644
--- a/fs/ext4/extents_status.h
+++ b/fs/ext4/extents_status.h
@@ -238,6 +238,7 @@ static inline void ext4_es_store_pblock_status(struct extent_status *es,
extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi);
extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi);
+extern void ext4_es_destroy_stats(struct ext4_sb_info *sbi);
extern int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e292c0597eaf..e450ea1df71d 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1273,6 +1273,14 @@ static void ext4_flex_groups_free(struct ext4_sb_info *sbi)
rcu_read_unlock();
}
+static void ext4_put_sbi_rcu(struct rcu_head *head)
+{
+ struct ext4_sb_info *sbi = container_of(head, struct ext4_sb_info, s_rcu);
+
+ ext4_es_destroy_stats(sbi);
+ kfree(sbi);
+}
+
static void ext4_put_super(struct super_block *sb)
{
struct ext4_sb_info *sbi = EXT4_SB(sb);
@@ -1369,7 +1377,6 @@ static void ext4_put_super(struct super_block *sb)
ext4_stop_mmpd(sbi);
brelse(sbi->s_sbh);
- sb->s_fs_info = NULL;
/*
* Now that we are completely done shutting down the
* superblock, we need to actually destroy the kobject.
@@ -1382,7 +1389,8 @@ static void ext4_put_super(struct super_block *sb)
#if IS_ENABLED(CONFIG_UNICODE)
utf8_unload(sb->s_encoding);
#endif
- kfree(sbi);
+ /* ext4_get_link() reads the sbi and the counters in rcu pathwalk */
+ call_rcu(&sbi->s_rcu, ext4_put_sbi_rcu);
}
static struct kmem_cache *ext4_inode_cachep;
@@ -5777,6 +5785,7 @@ failed_mount8: __maybe_unused
}
failed_mount3a:
ext4_es_unregister_shrinker(sbi);
+ ext4_es_destroy_stats(sbi);
failed_mount3:
/* flush s_sb_upd_work before sbi destroy */
flush_work(&sbi->s_sb_upd_work);
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Devel] [PATCH hci-8.1 2/2] ms/unicode: free the map after a grace period
2026-11-17 5:52 [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes Eva Kurchatova
2026-11-17 5:52 ` [Devel] [PATCH hci-8.1 1/2] ms/ext4: free the sbi after a grace period Eva Kurchatova
@ 2026-11-17 5:52 ` Eva Kurchatova
2026-11-17 5:59 ` no-reply
2026-11-17 15:15 ` [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes Konstantin Khorenko
2026-11-17 15:15 ` Konstantin Khorenko
3 siblings, 1 reply; 7+ messages in thread
From: Eva Kurchatova @ 2026-11-17 5:52 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Christian Brauner <brauner@kernel.org>
commit a96c5299bd7305eb984377681eb3222a57376405 upstream.
generic_ci_d_hash() and generic_ci_d_compare() read sb->s_encoding and
dereference the unicode map while a pathwalk in rcu mode holds nothing
but rcu_read_lock(). The filesystems that use them, ext4, f2fs and
tmpfs, drop the map with utf8_unload() from ->put_super(), which runs
when the last reference to the mount goes away. A lookup that is still
inside such a filesystem at that point reads a freed map.
With a pathwalk held up in utf8_casefold_hash() while the last reference
to a casefolded tmpfs goes away:
BUG: KASAN: slab-use-after-free in utf8nlookup+0x74c/0x950
Read of size 8 at addr ff110001030fe658 by task walker/98
Call Trace:
<TASK>
utf8nlookup+0x74c/0x950
utf8byte+0x160/0x1560
utf8_casefold_hash+0x167/0x230
generic_ci_d_hash+0xdd/0x1c0
link_path_walk+0x11ad/0x1d30
path_lookupat+0x63/0xb00
filename_lookup+0x1f1/0x5b0
vfs_statx+0xd7/0x3b0
[...]
Allocated by task 94:
__kmalloc_cache_noprof+0x249/0x560
utf8_load+0x4e/0x570
shmem_parse_opt_casefold.isra.0+0x92/0x270
[...]
Freed by task 97:
kfree+0x1db/0x5b0
shmem_put_super+0x72/0x170
generic_shutdown_super+0x14c/0x530
kill_anon_super+0x3a/0x60
deactivate_locked_super+0x9c/0xf0
cleanup_mnt+0x9f/0x130
So far that has been hard to hit. umount(2) waits for a grace period
in namespace_unlock() before it drops the mount, so only a mount whose
last reference goes away elsewhere, like the close of a file or a chdir
out of a lazily unmounted directory, can race a walker. So it is
reachable.
Delay the free until a grace period has passed. The map and the data
table it holds a reference to then outlive any pathwalk that found the
superblock before the mount went away. The reference on the data table
module is dropped from the rcu callback as well. utf8-core is built in
whenever CONFIG_UNICODE is set, so there is no module exit that would
have to wait for the callbacks.
Overlayfs points the s_encoding of an overlay at the map of its first
layer without taking a reference of its own. That stays correct. The
layer is held by the overlay, so its map is dropped only after the
overlay is gone.
Fixes: b886ee3e778e ("ext4: Support case-insensitive file name lookups")
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261009-work-fixes-rcu-v1-6-7446d2d335e6@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 69a0d6b31d05e856c7335509222f25321e3c69ca)
https://virtuozzo.atlassian.net/browse/VSTOR-155414
Feature: fix ms/fs
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
fs/unicode/utf8-core.c | 21 +++++++++++++++++----
include/linux/unicode.h | 1 +
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c
index 8395066341a4..48ba70fba830 100644
--- a/fs/unicode/utf8-core.c
+++ b/fs/unicode/utf8-core.c
@@ -3,6 +3,7 @@
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/slab.h>
+#include <linux/rcupdate.h>
#include <linux/parser.h>
#include <linux/errno.h>
#include <linux/stringhash.h>
@@ -205,12 +206,24 @@ struct unicode_map *utf8_load(unsigned int version)
}
EXPORT_SYMBOL(utf8_load);
+static void utf8_unload_rcu(struct rcu_head *head)
+{
+ struct unicode_map *um = container_of(head, struct unicode_map, rcu);
+
+ symbol_put(utf8_data_table);
+ kfree(um);
+}
+
+/*
+ * A pathwalk in rcu mode may still be in ->d_hash() or ->d_compare() of a
+ * filesystem that is being torn down and read the map through its
+ * superblock, so the map and the tables it points to have to outlive the
+ * grace period.
+ */
void utf8_unload(struct unicode_map *um)
{
- if (um) {
- symbol_put(utf8_data_table);
- kfree(um);
- }
+ if (um)
+ call_rcu(&um->rcu, utf8_unload_rcu);
}
EXPORT_SYMBOL(utf8_unload);
diff --git a/include/linux/unicode.h b/include/linux/unicode.h
index 4d39e6e11a95..f5ee53dc4dff 100644
--- a/include/linux/unicode.h
+++ b/include/linux/unicode.h
@@ -51,6 +51,7 @@ struct unicode_map {
unsigned int version;
const struct utf8data *ntab[UTF8_NMAX];
const struct utf8data_table *tables;
+ struct rcu_head rcu;
};
int utf8_validate(const struct unicode_map *um, const struct qstr *str);
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Devel] [PATCH hci-8.1 2/2] ms/unicode: free the map after a grace period
2026-11-17 5:52 ` [Devel] [PATCH hci-8.1 2/2] ms/unicode: free the map " Eva Kurchatova
@ 2026-11-17 5:59 ` no-reply
0 siblings, 0 replies; 7+ messages in thread
From: no-reply @ 2026-11-17 5:59 UTC (permalink / raw)
To: Eva Kurchatova, khorenko; +Cc: devel
> From: Christian Brauner <brauner@kernel.org>
>
> commit a96c5299bd7305eb984377681eb3222a57376405 upstream.
>
> generic_ci_d_hash() and generic_ci_d_compare() read sb->s_encoding and
> dereference the unicode map while a pathwalk in rcu mode holds nothing
> but rcu_read_lock(). The filesystems that use them, ext4, f2fs and
> tmpfs, drop the map with utf8_unload() from ->put_super(), which runs
> when the last reference to the mount goes away. A lookup that is still
> inside such a filesystem at that point reads a freed map.
>
> With a pathwalk held up in utf8_casefold_hash() while the last reference
> to a casefolded tmpfs goes away:
>
> BUG: KASAN: slab-use-after-free in utf8nlookup+0x74c/0x950
> [ ... ]
>
> https://virtuozzo.atlassian.net/browse/VSTOR-155414
> Feature: fix ms/fs
>
> Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261117055330.810827-1-eva.kurchatova@virtuozzo.com?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Devel] [PATCH hci-8.1 1/2] ms/ext4: free the sbi after a grace period
2026-11-17 5:52 ` [Devel] [PATCH hci-8.1 1/2] ms/ext4: free the sbi after a grace period Eva Kurchatova
@ 2026-11-17 6:02 ` no-reply
0 siblings, 0 replies; 7+ messages in thread
From: no-reply @ 2026-11-17 6:02 UTC (permalink / raw)
To: Eva Kurchatova, khorenko; +Cc: devel
> From: Christian Brauner <brauner@kernel.org>
>
> [ Upstream commit c17b44266a1f9fcb49b894d4611d1254bf1aa313 ]
>
> ext4_get_link() follows a symlink that keeps its target in a data block
> in rcu pathwalk mode with ext4_getblk(EXT4_GET_BLOCKS_CACHED_NOWAIT).
> That reads s_mount_state in the ASSERT() of ext4_getblk() and again in
> ext4_es_lookup_extent(), and the lookup bumps the extent status hit or
> miss counter, all through sb->s_fs_info.
>
> ext4_put_super() destroys those counters, clears sb->s_fs_info and frees
> the sbi without waiting for a grace period. A pathwalk that is still in
> ext4_get_link() when the last reference to the mount goes away then
> dereferences a NULL s_fs_info, the freed sbi or the destroyed percpu
> counters.
> [ ... ]
>
> https://virtuozzo.atlassian.net/browse/VSTOR-155414
> Feature: fix ms/fs
>
> Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261117055330.810827-1-eva.kurchatova@virtuozzo.com?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes
2026-11-17 5:52 [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes Eva Kurchatova
2026-11-17 5:52 ` [Devel] [PATCH hci-8.1 1/2] ms/ext4: free the sbi after a grace period Eva Kurchatova
2026-11-17 5:52 ` [Devel] [PATCH hci-8.1 2/2] ms/unicode: free the map " Eva Kurchatova
@ 2026-11-17 15:15 ` Konstantin Khorenko
2026-11-17 15:15 ` Konstantin Khorenko
3 siblings, 0 replies; 7+ messages in thread
From: Konstantin Khorenko @ 2026-11-17 15:15 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
Applying as is.
On Tue, 17 Nov 2026 07:52:11 +0200, Eva Kurchatova wrote:
> Christian Brauner (2):
> ms/ext4: free the sbi after a grace period
> ms/unicode: free the map after a grace period
Both are the 6.12.y commits; the ext4 one rightly leaves out the KUnit
hunks. Note that 2/2 compiles to nothing in our kernels, CONFIG_UNICODE
is not set; it is fine to keep it for parity with 6.12.y.
Separate patches, not needed for this series; I created a task for
each:
1. Patch 5 of the same upstream series, f0e48172a59e5 ("ipc: drop the
mqueue mount with kern_unmount() on setup failure"), with
7229d74e5e8c1 before it: create_ipc_ns() here never drops
ns->mq_mnt when it fails after mq_init_ns(), so the mqueue mount
leaks on a failed CT start or unshare(CLONE_NEWIPC).
https://virtuozzo.atlassian.net/browse/VSTOR-155528
2. 496bb99b7e66f ("ext4: fix the might_sleep() warnings in kvfree()"),
de009e11f31a8 in 6.12.y: ext4_group_desc_free() and
ext4_flex_groups_free() still call kvfree() under rcu_read_lock().
https://virtuozzo.atlassian.net/browse/VSTOR-155529
Thanks.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes
2026-11-17 5:52 [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes Eva Kurchatova
` (2 preceding siblings ...)
2026-11-17 15:15 ` [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes Konstantin Khorenko
@ 2026-11-17 15:15 ` Konstantin Khorenko
3 siblings, 0 replies; 7+ messages in thread
From: Konstantin Khorenko @ 2026-11-17 15:15 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
On Tue, 17 Nov 2026 07:52:11 +0200, Eva Kurchatova wrote:
> ms/fs: backport RCU pathwalk UAF fixes
>
> Patchset for task https://virtuozzo.atlassian.net/browse/VSTOR-155414
>
> Christian Brauner (2):
> ms/ext4: free the sbi after a grace period
> ms/unicode: free the map after a grace period
>
> [...]
Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.24.3.vz10, thanks!
[1/2] ms/ext4: free the sbi after a grace period
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/99424b6de72d
[2/2] ms/unicode: free the map after a grace period
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/246d1c0af8c4
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-17 15:17 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 5:52 [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes Eva Kurchatova
2026-11-17 5:52 ` [Devel] [PATCH hci-8.1 1/2] ms/ext4: free the sbi after a grace period Eva Kurchatova
2026-11-17 6:02 ` no-reply
2026-11-17 5:52 ` [Devel] [PATCH hci-8.1 2/2] ms/unicode: free the map " Eva Kurchatova
2026-11-17 5:59 ` no-reply
2026-11-17 15:15 ` [Devel] [PATCH hci-8.1 0/2] ms/fs: backport RCU pathwalk UAF fixes Konstantin Khorenko
2026-11-17 15:15 ` Konstantin Khorenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.