diff mbox series

[poky,scarthgap,v2] systemd: replace a bunch of assert() with friendlier checks

Message ID 20261005082207.3387895-1-UpStream_IP-SH@bmwtechworks.in
State New
Headers show
Series [poky,scarthgap,v2] systemd: replace a bunch of assert() with friendlier checks | expand

Commit Message

Suresh H A Oct. 5, 2026, 8:22 a.m. UTC
From: Suresh H A <Suresh.HA@bmwtechworks.in>

Backport a patch that replaces a bunch of assert() with friendlier checks
Fix is already available since systemd v258-rc1.

Journal file contents can change or be inconsistent on disk, so they
must not be checked with assert(). We hit this on systemd 255.21, where
dlt-system aborted in sd-journal:

  dlt-system[1284]: Assertion 'd->object.type == OBJECT_DATA' failed at
  src/libsystemd/sd-journal/journal-file.c:3237,
  function generic_array_bisect_for_data(). Aborting.

generic_array_bisect_for_data() received a data object whose object.type
was not OBJECT_DATA, and the assert aborted the whole process.

The patch replaces these asserts with
"if (type != expected) return -EBADMSG;" in bump_entry_array(),
generic_array_bisect_for_data() and the journal_file_move_to_entry_*_for_data()
functions. A bad object is then reported as an error to the caller instead of
aborting it.

Signed-off-by: Suresh H A <Suresh.HA@bmwtechworks.in>
---
 ...a-bunch-of-assert-with-friendlier-ch.patch | 108 ++++++++++++++++++
 meta/recipes-core/systemd/systemd_255.22.bb   |   1 +
 2 files changed, 109 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/0023-journal-replace-a-bunch-of-assert-with-friendlier-ch.patch
diff mbox series

Patch

diff --git a/meta/recipes-core/systemd/systemd/0023-journal-replace-a-bunch-of-assert-with-friendlier-ch.patch b/meta/recipes-core/systemd/systemd/0023-journal-replace-a-bunch-of-assert-with-friendlier-ch.patch
new file mode 100644
index 0000000000..aa78f4d797
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0023-journal-replace-a-bunch-of-assert-with-friendlier-ch.patch
@@ -0,0 +1,108 @@ 
+From 5ee8b3edb385b216eb4f3316323ae1287824971a Mon Sep 17 00:00:00 2001
+From: Lennart Poettering <lennart@poettering.net>
+Date: Thu, 5 Jun 2025 22:26:03 +0200
+Subject: [PATCH] journal: replace a bunch of assert() with friendlier checks
+
+We should not rely that data stored in the journal files remains
+entirely untouched at all times. Because we unallocate files, data might
+go away any time. Hence, never assert() on any expectations on what the
+file contains. Instead, handle it more gracefully as a corruption issue,
+and return EBADMSG.
+
+Fixes: #35229 #32436
+
+Upstream-Status: Backport [https://github.com/systemd/systemd/pull/37757/commits/5ee8b3edb385b216eb4f3316323ae1287824971a]
+
+Signed-off-by: Suresh H A <Suresh.HA@bmwtechworks.in>
+---
+ src/libsystemd/sd-journal/journal-file.c | 28 ++++++++++++++++++------
+ 1 file changed, 21 insertions(+), 7 deletions(-)
+
+diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c
+index fecddb932f..acceea7770 100644
+--- a/src/libsystemd/sd-journal/journal-file.c
++++ b/src/libsystemd/sd-journal/journal-file.c
+@@ -2740,7 +2740,9 @@ static int bump_entry_array(
+ 
+         if (direction == DIRECTION_DOWN) {
+                 assert(o);
+-                assert(o->object.type == OBJECT_ENTRY_ARRAY);
++
++                if (o->object.type != OBJECT_ENTRY_ARRAY)
++                        return -EBADMSG;
+ 
+                 *ret = le64toh(o->entry_array.next_entry_array_offset);
+         } else {
+@@ -3241,9 +3243,11 @@ static int generic_array_bisect_for_data(
+ 
+         assert(f);
+         assert(d);
+-        assert(d->object.type == OBJECT_DATA);
+         assert(test_object);
+ 
++        if (d->object.type != OBJECT_DATA)
++                return -EBADMSG;
++
+         n = le64toh(d->data.n_entries);
+         if (n <= 0)
+                 return 0;
+@@ -3609,9 +3613,11 @@ int journal_file_move_to_entry_for_data(
+ 
+         assert(f);
+         assert(d);
+-        assert(d->object.type == OBJECT_DATA);
+         assert(IN_SET(direction, DIRECTION_DOWN, DIRECTION_UP));
+ 
++        if (d->object.type != OBJECT_DATA)
++                return -EBADMSG;
++
+         /* FIXME: fix return value assignment. */
+ 
+         /* This returns the first (when the direction is down, otherwise the last) entry linked to the
+@@ -3671,7 +3677,9 @@ int journal_file_move_to_entry_by_offset_for_data(
+ 
+         assert(f);
+         assert(d);
+-        assert(d->object.type == OBJECT_DATA);
++
++        if (d->object.type != OBJECT_DATA)
++                return -EBADMSG;
+ 
+         return generic_array_bisect_for_data(
+                         f,
+@@ -3697,7 +3705,9 @@ int journal_file_move_to_entry_by_monotonic_for_data(
+ 
+         assert(f);
+         assert(d);
+-        assert(d->object.type == OBJECT_DATA);
++
++        if (d->object.type != OBJECT_DATA)
++                return -EBADMSG;
+ 
+         /* First, pin the given data object, before reading the _BOOT_ID= data object below. */
+         r = journal_file_pin_object(f, d);
+@@ -3763,7 +3773,9 @@ int journal_file_move_to_entry_by_seqnum_for_data(
+ 
+         assert(f);
+         assert(d);
+-        assert(d->object.type == OBJECT_DATA);
++
++        if (d->object.type != OBJECT_DATA)
++                return -EBADMSG;
+ 
+         return generic_array_bisect_for_data(
+                         f,
+@@ -3783,7 +3795,9 @@ int journal_file_move_to_entry_by_realtime_for_data(
+ 
+         assert(f);
+         assert(d);
+-        assert(d->object.type == OBJECT_DATA);
++
++        if (d->object.type != OBJECT_DATA)
++                return -EBADMSG;
+ 
+         return generic_array_bisect_for_data(
+                         f,
+-- 
+2.43.0
+
diff --git a/meta/recipes-core/systemd/systemd_255.22.bb b/meta/recipes-core/systemd/systemd_255.22.bb
index e5a0fd9170..342d078067 100644
--- a/meta/recipes-core/systemd/systemd_255.22.bb
+++ b/meta/recipes-core/systemd/systemd_255.22.bb
@@ -37,6 +37,7 @@  SRC_URI += " \
            file://CVE-2026-29111-02.patch \
            file://CVE-2026-29111-03.patch \
            file://CVE-2026-29111-04.patch \
+           file://0023-journal-replace-a-bunch-of-assert-with-friendlier-ch.patch \
            "
 
 # patches needed by musl