* [RFC PATCH] fs/resctrl: Fix use-after-free during unmount
@ 2026-05-13 22:40 Tony Luck
0 siblings, 0 replies; only message in thread
From: Tony Luck @ 2026-05-13 22:40 UTC (permalink / raw)
To: Fenghua Yu, Reinette Chatre, Maciej Wieczor-Retman, Peter Newman,
James Morse, Babu Moger, Drew Fustini, Dave Martin, Chen Yu
Cc: Borislav Petkov, x86, linux-kernel, patches, Tony Luck
Sashiko reported[1] this issue:
During unmount or failure teardown, resctrl_fs_teardown() calls
mon_put_kn_priv() (which frees all mon_data structures) followed
by rdtgroup_destroy_root() (which destroys kernfs nodes). However, the
RDT_DELETED flag is never set for rdtgroup_default.
If a concurrent reader (e.g., rdtgroup_mondata_show()) invokes
rdtgroup_kn_lock_live(), it drops kernfs active protection and blocks on
rdtgroup_mutex. resctrl_fs_teardown() (holding the mutex) proceeds to free
the private data and destroy the nodes without waiting for the reader.
When the mutex is released, the reader wakes up, observes that RDT_DELETED is
not set for the default group, and dereferences the already-freed of->kn->priv
pointer.
Set RDT_DELETED for the default group (if there are any tasks waiting).
Signed-off-by: Tony Luck <tony.luck@intel.com>
Link: https://sashiko.dev/#/patchset/20260508182143.14592-1-tony.luck%40intel.com?part=2 [1]
---
Yet another side-quest from Sashiko. RFC for some human eyes before I
add to my series and post a new version;
1) Is this real? It looks like it is to me.
2) Is my fix reasonable?
3) Better way to fix it?
fs/resctrl/rdtgroup.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index eac7e4f8574d..668ebe0b0ec6 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -594,7 +594,8 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
static void rdtgroup_remove(struct rdtgroup *rdtgrp)
{
kernfs_put(rdtgrp->kn);
- kfree(rdtgrp);
+ if (rdtgrp != &rdtgroup_default)
+ kfree(rdtgrp);
}
static void _update_task_closid_rmid(void *task)
@@ -2965,6 +2966,8 @@ static void resctrl_fs_teardown(void)
mon_put_kn_priv();
rdt_pseudo_lock_release();
rdtgroup_default.mode = RDT_MODE_SHAREABLE;
+ if (atomic_read(&rdtgroup_default.waitcount) != 0)
+ rdtgroup_default.flags = RDT_DELETED;
closid_exit();
schemata_list_destroy();
rdtgroup_destroy_root();
@@ -4291,6 +4294,7 @@ static int rdtgroup_setup_root(struct rdt_fs_context *ctx)
ctx->kfc.root = rdt_root;
rdtgroup_default.kn = kernfs_root_to_node(rdt_root);
+ rdtgroup_default.flags = 0;
return 0;
}
--
2.54.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-13 22:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13 22:40 [RFC PATCH] fs/resctrl: Fix use-after-free during unmount Tony Luck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox