]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: check .next_entry_array_offset earlier
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 2 May 2023 16:29:08 +0000 (01:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 2 May 2023 21:41:21 +0000 (06:41 +0900)
Then, if it is invalid, refuse to use the entry array object.

Follow-up for a8fbcc0e3c033a43e511550052cace6b0dcf3df7.
Fixes #27489.

src/libsystemd/sd-journal/journal-file.c

index 501e7276b6d34b0f73d336b881be5d7e211a2ad3..8827e9b939b65bbbe6172a402a1fc8341103ef83 100644 (file)
@@ -924,7 +924,7 @@ static int check_object(JournalFile *f, Object *o, uint64_t offset) {
         }
 
         case OBJECT_ENTRY_ARRAY: {
-                uint64_t sz;
+                uint64_t sz, next;
 
                 sz = le64toh(READ_NOW(o->object.size));
                 if (sz < offsetof(Object, entry_array.items) ||
@@ -934,11 +934,12 @@ static int check_object(JournalFile *f, Object *o, uint64_t offset) {
                                                "Invalid object entry array size: %" PRIu64 ": %" PRIu64,
                                                sz,
                                                offset);
-
-                if (!VALID64(le64toh(o->entry_array.next_entry_array_offset)))
+                /* Here, we request that the offset of each entry array object is in strictly increasing order. */
+                next = le64toh(o->entry_array.next_entry_array_offset);
+                if (!VALID64(next) || (next > 0 && next <= offset))
                         return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
-                                               "Invalid object entry array next_entry_array_offset: " OFSfmt ": %" PRIu64,
-                                               le64toh(o->entry_array.next_entry_array_offset),
+                                               "Invalid object entry array next_entry_array_offset: %" PRIu64 ": %" PRIu64,
+                                               next,
                                                offset);
 
                 break;