From 75bf2627b09d3006c62d4a24dd596205dbc93319 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 31 Jan 2023 23:00:07 +0100 Subject: [PATCH] journal-file: refuse writing to journal files where the header size is different then expected We keep adding fields to the header, and it's fine reading files with different header sizes, as we check via the size if the fields we need are included. However, let's be stricter when writing journal files than when reading, and insist that the header structure in the file actually matches our expectations. Refuse otherwise, so that a new file is created after rotation that then matches our expectations. This makes sure that mismatch in header size is treated exactly as unknown "compatible" flags, which is our other mechanism to allow extending the journal file format in a non-breaking way. --- src/libsystemd/sd-journal/journal-file.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index eae8d538fd..ca12fc1190 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -483,6 +483,11 @@ static int journal_file_verify_header(JournalFile *f) { if (header_size < HEADER_SIZE_MIN) return -EBADMSG; + /* When open for writing we refuse to open files with a mismatch of the header size, i.e. writing to + * files implementing older or new header structures. */ + if (journal_file_writable(f) && header_size != sizeof(Header)) + return -EPROTONOSUPPORT; + if (JOURNAL_HEADER_SEALED(f->header) && !JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays)) return -EBADMSG;