* [PATCH v4 1/5] liveupdate: skip serialization for context-preserving kexec
2026-05-17 19:26 [PATCH v4 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
@ 2026-05-17 19:26 ` Pasha Tatashin
2026-05-17 19:26 ` [PATCH v4 2/5] liveupdate: fix TOCTOU race in luo_session_retrieve() Pasha Tatashin
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-17 19:26 UTC (permalink / raw)
To: rppt, sourabhjain, jbouron, akpm, bhe, linux-kernel,
dan.carpenter, liaoyuanhong, pasha.tatashin, rafael.j.wysocki,
piliu, kexec, pratyush, skhawaja, graf, mario.limonciello
A preserve_context kexec returns to the current kernel, which is
unrelated to live update where the state is passed to the next kernel.
Skip liveupdate_reboot() in this case to avoid serialization and prevent
sessions from being left in a frozen state upon return.
Fixes: db8bed8082dc ("kexec: call liveupdate_reboot() before kexec")
Reported-by: Oskar Gerlicz Kowalczuk <oskar@gerlicz.space>
Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/kexec_core.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index a43d2da0fe3e..dc770b9a6d05 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -1146,9 +1146,11 @@ int kernel_kexec(void)
goto Unlock;
}
- error = liveupdate_reboot();
- if (error)
- goto Unlock;
+ if (!kexec_image->preserve_context) {
+ error = liveupdate_reboot();
+ if (error)
+ goto Unlock;
+ }
#ifdef CONFIG_KEXEC_JUMP
if (kexec_image->preserve_context) {
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 2/5] liveupdate: fix TOCTOU race in luo_session_retrieve()
2026-05-17 19:26 [PATCH v4 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
2026-05-17 19:26 ` [PATCH v4 1/5] liveupdate: skip serialization for context-preserving kexec Pasha Tatashin
@ 2026-05-17 19:26 ` Pasha Tatashin
2026-05-17 19:26 ` [PATCH v4 3/5] liveupdate: block session mutations during reboot Pasha Tatashin
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-17 19:26 UTC (permalink / raw)
To: rppt, sourabhjain, jbouron, akpm, bhe, linux-kernel,
dan.carpenter, liaoyuanhong, pasha.tatashin, rafael.j.wysocki,
piliu, kexec, pratyush, skhawaja, graf, mario.limonciello
Extend the scope of the rwsem_read lock in luo_session_retrieve() to
overlap with the acquisition of the session mutex. This prevents a
concurrent thread from releasing and freeing the session between the
lookup and the mutex lock.
Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/liveupdate/luo_session.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index a3327a28fc1f..59b37d17db6b 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -415,12 +415,11 @@ int luo_session_retrieve(const char *name, struct file **filep)
struct luo_session *it;
int err;
- scoped_guard(rwsem_read, &sh->rwsem) {
- list_for_each_entry(it, &sh->list, list) {
- if (!strncmp(it->name, name, sizeof(it->name))) {
- session = it;
- break;
- }
+ guard(rwsem_read)(&sh->rwsem);
+ list_for_each_entry(it, &sh->list, list) {
+ if (!strncmp(it->name, name, sizeof(it->name))) {
+ session = it;
+ break;
}
}
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 3/5] liveupdate: block session mutations during reboot
2026-05-17 19:26 [PATCH v4 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
2026-05-17 19:26 ` [PATCH v4 1/5] liveupdate: skip serialization for context-preserving kexec Pasha Tatashin
2026-05-17 19:26 ` [PATCH v4 2/5] liveupdate: fix TOCTOU race in luo_session_retrieve() Pasha Tatashin
@ 2026-05-17 19:26 ` Pasha Tatashin
2026-05-18 8:40 ` Mike Rapoport
2026-05-17 19:26 ` [PATCH v4 4/5] liveupdate: fix u-a-f in luo_file_unpreserve_files() and luo_file_finish() Pasha Tatashin
` (2 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-17 19:26 UTC (permalink / raw)
To: rppt, sourabhjain, jbouron, akpm, bhe, linux-kernel,
dan.carpenter, liaoyuanhong, pasha.tatashin, rafael.j.wysocki,
piliu, kexec, pratyush, skhawaja, graf, mario.limonciello
During the reboot() syscall, user processes may still be running
concurrently and attempting to mutate sessions (e.g., creating,
retrieving, or releasing sessions). To prevent this, introduce
luo_session_serialize_rwsem to synchronize mutations with the
serialization process.
All session mutation operations (create, retrieve, release, ioctl) take
the read lock. The serialization process (luo_session_serialize) takes
the write lock and holds it indefinitely on success. This effectively
freezes the LUO session subsystem during the transition to the new
kernel. If serialization fails, the lock is released to allow recovery.
Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
Reported-by: Oskar Gerlicz Kowalczuk <oskar@gerlicz.space>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/liveupdate/luo_session.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index 59b37d17db6b..6099213275d8 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -75,6 +75,13 @@
sizeof(struct luo_session_header_ser)) / \
sizeof(struct luo_session_ser))
+/*
+ * Protects session mutations during serialization. All session mutation
+ * operations must hold the read lock. The serialization process holds the write
+ * lock indefinitely on success to block all concurrent and future mutations.
+ */
+static DECLARE_RWSEM(luo_session_serialize_rwsem);
+
/**
* struct luo_session_header - Header struct for managing LUO sessions.
* @count: The number of sessions currently tracked in the @list.
@@ -205,6 +212,7 @@ static int luo_session_release(struct inode *inodep, struct file *filep)
struct luo_session *session = filep->private_data;
struct luo_session_header *sh;
+ guard(rwsem_read)(&luo_session_serialize_rwsem);
/* If retrieved is set, it means this session is from incoming list */
if (session->retrieved) {
int err = luo_session_finish_one(session);
@@ -354,6 +362,7 @@ static long luo_session_ioctl(struct file *filep, unsigned int cmd,
if (ret)
return ret;
+ guard(rwsem_read)(&luo_session_serialize_rwsem);
return op->execute(session, &ucmd);
}
@@ -385,9 +394,12 @@ int luo_session_create(const char *name, struct file **filep)
struct luo_session *session;
int err;
+ down_read(&luo_session_serialize_rwsem);
session = luo_session_alloc(name);
- if (IS_ERR(session))
- return PTR_ERR(session);
+ if (IS_ERR(session)) {
+ err = PTR_ERR(session);
+ goto err_unlock;
+ }
err = luo_session_insert(&luo_session_global.outgoing, session);
if (err)
@@ -398,12 +410,16 @@ int luo_session_create(const char *name, struct file **filep)
if (err)
goto err_remove;
+ up_read(&luo_session_serialize_rwsem);
+
return 0;
err_remove:
luo_session_remove(&luo_session_global.outgoing, session);
err_free:
luo_session_free(session);
+err_unlock:
+ up_read(&luo_session_serialize_rwsem);
return err;
}
@@ -415,6 +431,7 @@ int luo_session_retrieve(const char *name, struct file **filep)
struct luo_session *it;
int err;
+ guard(rwsem_read)(&luo_session_serialize_rwsem);
guard(rwsem_read)(&sh->rwsem);
list_for_each_entry(it, &sh->list, list) {
if (!strncmp(it->name, name, sizeof(it->name))) {
@@ -582,7 +599,8 @@ int luo_session_serialize(void)
int i = 0;
int err;
- guard(rwsem_write)(&sh->rwsem);
+ down_write(&luo_session_serialize_rwsem);
+ down_write(&sh->rwsem);
list_for_each_entry(session, &sh->list, list) {
err = luo_session_freeze_one(session, &sh->ser[i]);
if (err)
@@ -593,6 +611,7 @@ int luo_session_serialize(void)
i++;
}
sh->header_ser->count = sh->count;
+ up_write(&sh->rwsem);
return 0;
@@ -602,6 +621,8 @@ int luo_session_serialize(void)
luo_session_unfreeze_one(session, &sh->ser[i]);
memset(sh->ser[i].name, 0, sizeof(sh->ser[i].name));
}
+ up_write(&sh->rwsem);
+ up_write(&luo_session_serialize_rwsem);
return err;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v4 3/5] liveupdate: block session mutations during reboot
2026-05-17 19:26 ` [PATCH v4 3/5] liveupdate: block session mutations during reboot Pasha Tatashin
@ 2026-05-18 8:40 ` Mike Rapoport
2026-05-18 12:40 ` Pasha Tatashin
0 siblings, 1 reply; 9+ messages in thread
From: Mike Rapoport @ 2026-05-18 8:40 UTC (permalink / raw)
To: Pasha Tatashin
Cc: sourabhjain, jbouron, akpm, bhe, linux-kernel, dan.carpenter,
liaoyuanhong, rafael.j.wysocki, piliu, kexec, pratyush, skhawaja,
graf, mario.limonciello
On Sun, May 17, 2026 at 07:26:48PM +0000, Pasha Tatashin wrote:
> During the reboot() syscall, user processes may still be running
> concurrently and attempting to mutate sessions (e.g., creating,
> retrieving, or releasing sessions). To prevent this, introduce
> luo_session_serialize_rwsem to synchronize mutations with the
> serialization process.
>
> All session mutation operations (create, retrieve, release, ioctl) take
> the read lock. The serialization process (luo_session_serialize) takes
> the write lock and holds it indefinitely on success. This effectively
> freezes the LUO session subsystem during the transition to the new
> kernel. If serialization fails, the lock is released to allow recovery.
>
> Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
> Reported-by: Oskar Gerlicz Kowalczuk <oskar@gerlicz.space>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> ---
> kernel/liveupdate/luo_session.c | 27 ++++++++++++++++++++++++---
> 1 file changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
> index 59b37d17db6b..6099213275d8 100644
> --- a/kernel/liveupdate/luo_session.c
> +++ b/kernel/liveupdate/luo_session.c
> @@ -385,9 +394,12 @@ int luo_session_create(const char *name, struct file **filep)
> struct luo_session *session;
> int err;
>
> + down_read(&luo_session_serialize_rwsem);
> session = luo_session_alloc(name);
We can alloc outside the lock, will make error handling simpler.
sashiko complains about mixing down_read() with scoped_guard(), for this
function it would make sense to use plain mutex_{lock,unlock} around
luo_session_getfile()
> - if (IS_ERR(session))
> - return PTR_ERR(session);
> + if (IS_ERR(session)) {
> + err = PTR_ERR(session);
> + goto err_unlock;
> + }
>
> err = luo_session_insert(&luo_session_global.outgoing, session);
> if (err)
> @@ -398,12 +410,16 @@ int luo_session_create(const char *name, struct file **filep)
> if (err)
> goto err_remove;
>
> + up_read(&luo_session_serialize_rwsem);
> +
> return 0;
>
> err_remove:
> luo_session_remove(&luo_session_global.outgoing, session);
> err_free:
> luo_session_free(session);
> +err_unlock:
> + up_read(&luo_session_serialize_rwsem);
>
> return err;
> }
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v4 3/5] liveupdate: block session mutations during reboot
2026-05-18 8:40 ` Mike Rapoport
@ 2026-05-18 12:40 ` Pasha Tatashin
0 siblings, 0 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-18 12:40 UTC (permalink / raw)
To: Mike Rapoport
Cc: Pasha Tatashin, sourabhjain, jbouron, akpm, bhe, linux-kernel,
dan.carpenter, liaoyuanhong, rafael.j.wysocki, piliu, kexec,
pratyush, skhawaja, graf, mario.limonciello
On 05-18 11:40, Mike Rapoport wrote:
> On Sun, May 17, 2026 at 07:26:48PM +0000, Pasha Tatashin wrote:
> > During the reboot() syscall, user processes may still be running
> > concurrently and attempting to mutate sessions (e.g., creating,
> > retrieving, or releasing sessions). To prevent this, introduce
> > luo_session_serialize_rwsem to synchronize mutations with the
> > serialization process.
> >
> > All session mutation operations (create, retrieve, release, ioctl) take
> > the read lock. The serialization process (luo_session_serialize) takes
> > the write lock and holds it indefinitely on success. This effectively
> > freezes the LUO session subsystem during the transition to the new
> > kernel. If serialization fails, the lock is released to allow recovery.
> >
> > Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
> > Reported-by: Oskar Gerlicz Kowalczuk <oskar@gerlicz.space>
> > Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> > ---
> > kernel/liveupdate/luo_session.c | 27 ++++++++++++++++++++++++---
> > 1 file changed, 24 insertions(+), 3 deletions(-)
> >
> > diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
> > index 59b37d17db6b..6099213275d8 100644
> > --- a/kernel/liveupdate/luo_session.c
> > +++ b/kernel/liveupdate/luo_session.c
> > @@ -385,9 +394,12 @@ int luo_session_create(const char *name, struct file **filep)
> > struct luo_session *session;
> > int err;
> >
> > + down_read(&luo_session_serialize_rwsem);
> > session = luo_session_alloc(name);
>
> We can alloc outside the lock, will make error handling simpler.
>
> sashiko complains about mixing down_read() with scoped_guard(), for this
> function it would make sense to use plain mutex_{lock,unlock} around
> luo_session_getfile()
Done. Thank you for review.
Pasha
>
> > - if (IS_ERR(session))
> > - return PTR_ERR(session);
> > + if (IS_ERR(session)) {
> > + err = PTR_ERR(session);
> > + goto err_unlock;
> > + }
> >
> > err = luo_session_insert(&luo_session_global.outgoing, session);
> > if (err)
> > @@ -398,12 +410,16 @@ int luo_session_create(const char *name, struct file **filep)
> > if (err)
> > goto err_remove;
> >
> > + up_read(&luo_session_serialize_rwsem);
> > +
> > return 0;
> >
> > err_remove:
> > luo_session_remove(&luo_session_global.outgoing, session);
> > err_free:
> > luo_session_free(session);
> > +err_unlock:
> > + up_read(&luo_session_serialize_rwsem);
> >
> > return err;
> > }
>
> --
> Sincerely yours,
> Mike.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 4/5] liveupdate: fix u-a-f in luo_file_unpreserve_files() and luo_file_finish()
2026-05-17 19:26 [PATCH v4 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
` (2 preceding siblings ...)
2026-05-17 19:26 ` [PATCH v4 3/5] liveupdate: block session mutations during reboot Pasha Tatashin
@ 2026-05-17 19:26 ` Pasha Tatashin
2026-05-17 19:26 ` [PATCH v4 5/5] liveupdate: Remove unused ser field from struct luo_session Pasha Tatashin
2026-05-18 8:42 ` [PATCH v4 0/5] liveupdate: serialization safety and race fixes Mike Rapoport
5 siblings, 0 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-17 19:26 UTC (permalink / raw)
To: rppt, sourabhjain, jbouron, akpm, bhe, linux-kernel,
dan.carpenter, liaoyuanhong, pasha.tatashin, rafael.j.wysocki,
piliu, kexec, pratyush, skhawaja, graf, mario.limonciello
In luo_file_unpreserve_files() and luo_file_finish(), reorder
module_put() and xa_erase() to ensure the file handler module remains
pinned while its operations are being accessed.
Specifically, luo_get_id() dereferences fh->ops->get_id, so the module
reference must be held until after xa_erase() (which calls luo_get_id)
completes.
For luo_file_finish(), this requires moving the module_put() call out of
the luo_file_finish_one() helper and into the main loop of
luo_file_finish() itself.
Fixes: 00d0b372374f ("liveupdate: prevent double management of files")
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/liveupdate/luo_file.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index a0a419085e28..208987502f73 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -385,10 +385,11 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
args.private_data = luo_file->private_data;
luo_file->fh->ops->unpreserve(&args);
luo_flb_file_unpreserve(luo_file->fh);
- module_put(luo_file->fh->ops->owner);
xa_erase(&luo_preserved_files,
luo_get_id(luo_file->fh, luo_file->file));
+ module_put(luo_file->fh->ops->owner);
+
list_del(&luo_file->list);
file_set->count--;
@@ -677,7 +678,6 @@ static void luo_file_finish_one(struct luo_file_set *file_set,
luo_file->fh->ops->finish(&args);
luo_flb_file_finish(luo_file->fh);
- module_put(luo_file->fh->ops->owner);
}
/**
@@ -738,6 +738,7 @@ int luo_file_finish(struct luo_file_set *file_set)
luo_get_id(luo_file->fh, luo_file->file));
fput(luo_file->file);
}
+ module_put(luo_file->fh->ops->owner);
list_del(&luo_file->list);
file_set->count--;
mutex_destroy(&luo_file->mutex);
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 5/5] liveupdate: Remove unused ser field from struct luo_session
2026-05-17 19:26 [PATCH v4 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
` (3 preceding siblings ...)
2026-05-17 19:26 ` [PATCH v4 4/5] liveupdate: fix u-a-f in luo_file_unpreserve_files() and luo_file_finish() Pasha Tatashin
@ 2026-05-17 19:26 ` Pasha Tatashin
2026-05-18 8:42 ` [PATCH v4 0/5] liveupdate: serialization safety and race fixes Mike Rapoport
5 siblings, 0 replies; 9+ messages in thread
From: Pasha Tatashin @ 2026-05-17 19:26 UTC (permalink / raw)
To: rppt, sourabhjain, jbouron, akpm, bhe, linux-kernel,
dan.carpenter, liaoyuanhong, pasha.tatashin, rafael.j.wysocki,
piliu, kexec, pratyush, skhawaja, graf, mario.limonciello
The ser field in struct luo_session was intended to point to the
serialized data for a session, but it was never actually utilized in the
implementation. All serialization and deserialization logic consistently
uses the pointers maintained in struct luo_session_header.
Remove the dead field to clean up the structure.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/liveupdate/luo_internal.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index 875844d7a41d..dd53d4a7277e 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -59,7 +59,6 @@ struct luo_file_set {
* struct luo_session - Represents an active or incoming Live Update session.
* @name: A unique name for this session, used for identification and
* retrieval.
- * @ser: Pointer to the serialized data for this session.
* @list: A list_head member used to link this session into a global list
* of either outgoing (to be preserved) or incoming (restored from
* previous kernel) sessions.
@@ -70,7 +69,6 @@ struct luo_file_set {
*/
struct luo_session {
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
- struct luo_session_ser *ser;
struct list_head list;
bool retrieved;
struct luo_file_set file_set;
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v4 0/5] liveupdate: serialization safety and race fixes
2026-05-17 19:26 [PATCH v4 0/5] liveupdate: serialization safety and race fixes Pasha Tatashin
` (4 preceding siblings ...)
2026-05-17 19:26 ` [PATCH v4 5/5] liveupdate: Remove unused ser field from struct luo_session Pasha Tatashin
@ 2026-05-18 8:42 ` Mike Rapoport
5 siblings, 0 replies; 9+ messages in thread
From: Mike Rapoport @ 2026-05-18 8:42 UTC (permalink / raw)
To: Pasha Tatashin
Cc: sourabhjain, jbouron, akpm, bhe, linux-kernel, dan.carpenter,
liaoyuanhong, rafael.j.wysocki, piliu, kexec, pratyush, skhawaja,
graf, mario.limonciello
On Sun, May 17, 2026 at 07:26:45PM +0000, Pasha Tatashin wrote:
> This series addresses several issues related to the synchronization
> between the reboot process and LUO session management.
>
> Tree: git.kernel.org/pub/scm/linux/kernel/git/tatashin/linux.git Branch:
> luo-reboot-sync/v4
>
> Pasha Tatashin (5):
> liveupdate: skip serialization for context-preserving kexec
> liveupdate: fix TOCTOU race in luo_session_retrieve()
> liveupdate: block session mutations during reboot
> liveupdate: fix u-a-f in luo_file_unpreserve_files() and
> luo_file_finish()
> liveupdate: Remove unused ser field from struct luo_session
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
for the series, with a small comment in patch 3/5
> kernel/kexec_core.c | 8 ++++---
> kernel/liveupdate/luo_file.c | 5 +++--
> kernel/liveupdate/luo_internal.h | 2 --
> kernel/liveupdate/luo_session.c | 38 ++++++++++++++++++++++++--------
> 4 files changed, 37 insertions(+), 16 deletions(-)
>
>
> base-commit: b1378127003b61930ce30064328640503ad3ef6d
> --
> 2.53.0
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 9+ messages in thread