From: "Denis V. Lunev" <den@openvz.org>
To: khorenko@virtuozzo.com, ptikhomirov@virtuozzo.com,
vasileios.almpanis@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2] fs: fix use-after-free in fs_send_uevent_work()
Date: Mon, 30 Nov 2026 14:19:52 +0100 [thread overview]
Message-ID: <20261130131952.2329425-1-den@openvz.org> (raw)
From: Denis V. Lunev <den@openvz.org>
fs_send_uevent() queues a work item that carries plain pointers to the
superblock and to the filesystem kobject. Nothing keeps them alive
until the worker runs; each filesystem is expected to flush
fs_events_wq before it frees them. That cannot hold for ERROR and
ABORT events, which are raised from error handlers, for example by
ext4_put_super() when the journal cannot be written on unmount. The
event is queued after the only flush, the unmount completes, and the
worker walks a freed kobject:
BUG: kernel NULL pointer dereference, address: 0000000000000000
RIP: 0010:strlen+0x4/0x30
fill_kobj_path
kobject_get_path
kobject_uevent_env
fs_send_uevent_work
kobject_uevent_env() allocates with GFP_KERNEL between its checks and
the path walk, so the worker can sleep there and lose the race even
when it has started in time.
Take a kobject reference when the event is queued and drop it when the
worker is done. ext4 and XFS wait for the release of their registered
kobject before freeing the filesystem data (s_kobj_unregister,
xfs_sysfs_del), so the superblock stays valid for as long as a
reference is held. A kobject in zeroed memory, or one whose last
reference is gone, refuses the reference and the event is skipped.
That covers the failed mount paths too, where events used to be queued
for a superblock about to be destroyed.
The reference is taken before the one-shot ERROR and ABORT flags are
tested, so a sender that cannot take it does not consume them. An ext4
error raised during mount, before the kobject is registered, used to
burn the flag on an event that kobject_uevent_env() rejected for lack
of a kset; the first error after the mount is now reported.
An ERROR raised after ext4_unregister_sysfs() finds the kobject still
alive but already removed from sysfs. Its DEVPATH would be a bare
"/<name>", so the worker drops the event instead of sending it. The
check is best effort: it can still race with kobject_del(). ERROR and
ABORT raised while ext4 unmounts are therefore not delivered.
https://virtuozzo.atlassian.net/browse/VSTOR-157864
Feature: fs: udev events support
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
fs/super.c | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/fs/super.c b/fs/super.c
index c0c067eb2d8e..99f1dcce409b 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -2326,10 +2326,8 @@ static void fs_send_uevent_work(struct work_struct *w)
int ret;
env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL);
- if (!env){
- kfree(e);
- return;
- }
+ if (!env)
+ goto out_put;
ret = add_uevent_var(env, "FS_TYPE=%s", sb->s_type->name);
if (ret)
goto out;
@@ -2372,13 +2370,24 @@ static void fs_send_uevent_work(struct work_struct *w)
}
if (ret)
goto out;
+ /* best effort: a removed kobject has no valid DEVPATH */
+ if (!e->kobject->state_in_sysfs)
+ goto out;
ret = kobject_uevent_env(e->kobject, kaction, env->envp);
out:
kfree(env);
+out_put:
+ kobject_put(e->kobject);
kfree(e);
}
-/* fs_send_uevent - prepare and schedule event submission */
+/*
+ * fs_send_uevent - prepare and schedule event submission
+ *
+ * The kobject must sit in zeroed memory until it is initialised, so that
+ * an unregistered one has no reference to take, and the filesystem must
+ * wait for its release before it frees sb.
+ */
void fs_send_uevent(struct super_block *sb, struct kobject *kobj,
enum fs_event_type action)
{
@@ -2386,21 +2395,25 @@ void fs_send_uevent(struct super_block *sb, struct kobject *kobj,
if (!fs_events_wq)
return;
- if (action == FS_UA_ERROR && xchg(&sb->s_err_event_sent, 1))
+ if (!kobject_get_unless_zero(kobj))
return;
+ if (action == FS_UA_ERROR && xchg(&sb->s_err_event_sent, 1))
+ goto out_put;
if (action == FS_UA_ABORT && xchg(&sb->s_abrt_event_sent, 1))
- return;
+ goto out_put;
e = kzalloc(sizeof(*e), GFP_NOIO);
if (!e)
- return;
+ goto out_put;
- /* Do not forget to flush fs_events_wq before you kill sb */
e->sb = sb;
e->action = action;
e->kobject = kobj;
INIT_WORK(&e->work, fs_send_uevent_work);
queue_work(fs_events_wq, &e->work);
+ return;
+out_put:
+ kobject_put(kobj);
}
EXPORT_SYMBOL(fs_send_uevent);
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next reply other threads:[~2026-11-30 13:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 13:19 Denis V. Lunev [this message]
2026-11-30 13:52 ` Konstantin Khorenko
2026-11-30 13:52 ` Konstantin Khorenko
2026-11-30 14:03 ` Konstantin Khorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130131952.2329425-1-den@openvz.org \
--to=den@openvz.org \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.com \
--cc=ptikhomirov@virtuozzo.com \
--cc=vasileios.almpanis@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.