Skip to contentSkip to conversation

systemd: replace a bunch of assert() with friendlier checks

PATCH Superseded Suresh H A 3 participants 4 messages Sep 2 – Oct 5 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Suresh H A

author
#0 lore raw

PATCH 1/1 systemd: replace a bunch of assert() with friendlier checks

From: Suresh H A <[email protected]>

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

---
 ...a-bunch-of-assert-with-friendlier-ch.patch | 108 ++++++++++++++++++
 meta/recipes-core/systemd/systemd_255.21.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
meta/recipes-core/systemd/systemd/0023-journal-replace-a-bunch-of-assert-with-friendlier-ch.patch new file +108 -0
new file mode 100644
index 0000000000..aa78f4d797
@@ -0,0 +1,108 @@
+From 5ee8b3edb385b216eb4f3316323ae1287824971a Mon Sep 17 00:00:00 2001
+From: Lennart Poettering <[email protected]>
+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 <[email protected]>
+---
+ 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
+
meta/recipes-core/systemd/systemd_255.21.bb +1 -0
index 9c5f8af240..f9d0719d5e 100644
@@ -33,6 +33,7 @@ SRC_URI += " \
            file://CVE-2026-40225-02.patch \
            file://CVE-2026-40226-01.patch \
            file://CVE-2026-40226-02.patch \
+           file://0023-journal-replace-a-bunch-of-assert-with-friendlier-ch.patch \
            "
 
 # patches needed by musl
Signature · 1 line
2.43.0
#1 lore raw
Quoted 11 lines · Suresh H A via lists.openembedded.org

From: Suresh H A <[email protected]>

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

---
 ...a-bunch-of-assert-with-friendlier-ch.patch | 108 ++++++++++++++++++
 meta/recipes-core/systemd/systemd_255.21.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

Hello,

What problem is this trying to fix? Did you triggered those assert() in a project?

In itself, the patch looks fine but I have to make sure there is a real reason for merging it. Can you send a v2 with a little more information about that?

Thanks!

Signature · 2 lines
Yoann Congal
Smile ECS
#2 lore raw

Hi @Yoann Congal<mailto:[email protected]>,

Yes, we hit this on our scarthgap platform (systemd 255.21). dlt-system aborted inside 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.

The crash is the assert in generic_array_bisect_for_data(). The function received a data object 'd' whose object.type was not OBJECT_DATA, so the on-disk journal contents were not what the reader expected. The assert aborted the whole process.

The patch replaces the assert with:

if (d->object.type != OBJECT_DATA)

        return -EBADMSG;

A corrupted or changed object is then reported as an error to the caller, and dlt-system is not aborted. The other hunks make the same change in bump_entry_array() and the journal_file_move_to_entry_*_for_data() functions.

The fix is upstream commit 5ee8b3edb385 (v258-rc1) and applies cleanly to 255.21. I'll send a v2 with this explanation added to the commit message.

Thanks,
Suresh H A
________________________________
From: Yoann Congal <[email protected]>
Sent: 02 October 2026 15:17
To: Suresh H A - UpStream <[email protected]>; [email protected] <[email protected]>; Suresh H A <[email protected]>
Cc: Suresh H A <[email protected]>
Subject: Re: [OE-core] [poky][scarthgap][PATCH] systemd: replace a bunch of assert() with friendlier checks

Caution: "External email, be cautious especially with link(s), attachment(s) or QR code(s)".

Quoted 11 lines · Suresh H A via lists.openembedded.org

From: Suresh H A <[email protected]>

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

---
 ...a-bunch-of-assert-with-friendlier-ch.patch | 108 ++++++++++++++++++
 meta/recipes-core/systemd/systemd_255.21.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

Hello,

What problem is this trying to fix? Did you triggered those assert() in a project?

In itself, the patch looks fine but I have to make sure there is a real reason for merging it. Can you send a v2 with a little more information about that?

Thanks!
--
Yoann Congal
Smile ECS

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hello @Yoann Congal<mailto:[email protected]>,

I've sent v2 with additional context on the issue we observed in the platform and the rationale for the backport.
Patchwork link: [email protected] | [poky][scarthgap][PATCH v2] systemd: replace a bunch of assert() with friendlier checks<https://lists.openembedded.org/g/openembedded-core/topic/poky_scarthgap_patch_v2/121588045> The updated commit message now includes the observed failure where dlt-system-journal reported Bad message and subsequently hit the assertion in generic_array_bisect_for_data(), which is addressed by this upstream fix. Thanks,
Suresh H A
________________________________
From: [email protected] <[email protected]> on behalf of Suresh H A via lists.openembedded.org <[email protected]>
Sent: 04 October 2026 12:32
To: Yoann Congal <[email protected]>; Suresh H A - UpStream <[email protected]>; [email protected] <[email protected]>
Subject: Re: [OE-core] [poky][scarthgap][PATCH] systemd: replace a bunch of assert() with friendlier checks

Caution: "External email, be cautious especially with link(s), attachment(s) or QR code(s)". Hi @Yoann Congal<mailto:[email protected]>,

Yes, we hit this on our scarthgap platform (systemd 255.21). dlt-system aborted inside 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.

The crash is the assert in generic_array_bisect_for_data(). The function received a data object 'd' whose object.type was not OBJECT_DATA, so the on-disk journal contents were not what the reader expected. The assert aborted the whole process.

The patch replaces the assert with:

if (d->object.type != OBJECT_DATA)

        return -EBADMSG;

A corrupted or changed object is then reported as an error to the caller, and dlt-system is not aborted. The other hunks make the same change in bump_entry_array() and the journal_file_move_to_entry_*_for_data() functions.

The fix is upstream commit 5ee8b3edb385 (v258-rc1) and applies cleanly to 255.21. I'll send a v2 with this explanation added to the commit message.

Thanks,
Suresh H A
________________________________
From: Yoann Congal <[email protected]>
Sent: 02 October 2026 15:17
To: Suresh H A - UpStream <[email protected]>; [email protected] <[email protected]>; Suresh H A <[email protected]>
Cc: Suresh H A <[email protected]>
Subject: Re: [OE-core] [poky][scarthgap][PATCH] systemd: replace a bunch of assert() with friendlier checks

Caution: "External email, be cautious especially with link(s), attachment(s) or QR code(s)".

Quoted 11 lines · Suresh H A via lists.openembedded.org

From: Suresh H A <[email protected]>

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

---
 ...a-bunch-of-assert-with-friendlier-ch.patch | 108 ++++++++++++++++++
 meta/recipes-core/systemd/systemd_255.21.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

Hello,

What problem is this trying to fix? Did you triggered those assert() in a project?

In itself, the patch looks fine but I have to make sure there is a real reason for merging it. Can you send a v2 with a little more information about that?

Thanks!
--
Yoann Congal
Smile ECS