]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: Stop comparing hash values from entry items against data objects
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 1 Nov 2021 14:33:08 +0000 (14:33 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 26 Jan 2022 20:16:00 +0000 (20:16 +0000)
These checks don't achieve anything of value. Assuming they were added to
check for corruption, they don't actually achieve this goal since other parts
of the data object can still get corrupted and we wouldn't notice unless we'd
recalculate the hash every time.

In theory, we could use the entry item hash to avoid a random access lookup
for the data object hash in the journal file in the future to speed up searching,
but for finding all entry objects containing a specific data objects, we already
have entry arrays per data object to get fast access to this information.

This means that duplicating the hashes in the entry item doesn't result in any
added value. In this commit, we remove the checks so that in future commits we
can remove the hashes from the journal file format in the new compact mode.

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

index 36141e34f06ba87d46cbd37237adb87123870c0f..dc866b89052fa6d70ac83e1831608b71607e871c 100644 (file)
@@ -3565,21 +3565,16 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
 
         for (uint64_t i = 0; i < n; i++) {
                 uint64_t l, h;
-                le64_t le_hash;
                 size_t t;
                 void *data;
                 Object *u;
 
                 q = le64toh(o->entry.items[i].object_offset);
-                le_hash = o->entry.items[i].hash;
 
                 r = journal_file_move_to_object(from, OBJECT_DATA, q, &o);
                 if (r < 0)
                         return r;
 
-                if (le_hash != o->data.hash)
-                        return -EBADMSG;
-
                 l = le64toh(READ_NOW(o->object.size));
                 if (l < offsetof(Object, data.payload))
                         return -EBADMSG;
index 64e732cb95bfa806a85f272599ca6a11963bc565..56eaecb1014049fad55ff33c6d985b6b3e3fbe82 100644 (file)
@@ -645,11 +645,10 @@ static int verify_entry(
 
         n = journal_file_entry_n_items(o);
         for (i = 0; i < n; i++) {
-                uint64_t q, h;
+                uint64_t q;
                 Object *u;
 
                 q = le64toh(o->entry.items[i].object_offset);
-                h = le64toh(o->entry.items[i].hash);
 
                 if (!contains_uint64(cache_data_fd, n_data, q)) {
                         error(p, "Invalid data object of entry");
@@ -660,12 +659,7 @@ static int verify_entry(
                 if (r < 0)
                         return r;
 
-                if (le64toh(u->data.hash) != h) {
-                        error(p, "Hash mismatch for data object of entry");
-                        return -EBADMSG;
-                }
-
-                r = data_object_in_hash_table(f, h, q);
+                r = data_object_in_hash_table(f, le64toh(u->data.hash), q);
                 if (r < 0)
                         return r;
                 if (r == 0) {
index 50db7f991038524a3edef9faf55846ec9b93c4ef..644b9957b0e01d638014457f7c8d8b894a94054e 100644 (file)
@@ -2303,12 +2303,10 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
         for (i = 0; i < n; i++) {
                 Object *d;
                 uint64_t p, l;
-                le64_t le_hash;
                 size_t t;
                 int compression;
 
                 p = le64toh(o->entry.items[i].object_offset);
-                le_hash = o->entry.items[i].hash;
                 r = journal_file_move_to_object(f, OBJECT_DATA, p, &d);
                 if (IN_SET(r, -EADDRNOTAVAIL, -EBADMSG)) {
                         log_debug_errno(r, "Entry item %"PRIu64" data object is bad, skipping over it: %m", i);
@@ -2317,11 +2315,6 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
                 if (r < 0)
                         return r;
 
-                if (le_hash != d->data.hash) {
-                        log_debug("Entry item %"PRIu64" hash is bad, skipping over it.", i);
-                        continue;
-                }
-
                 l = le64toh(d->object.size) - offsetof(Object, data.payload);
 
                 compression = d->object.flags & OBJECT_COMPRESSION_MASK;
@@ -2450,10 +2443,8 @@ _public_ int sd_journal_enumerate_data(sd_journal *j, const void **data, size_t
 
         for (uint64_t n = journal_file_entry_n_items(o); j->current_field < n; j->current_field++) {
                 uint64_t p;
-                le64_t le_hash;
 
                 p = le64toh(o->entry.items[j->current_field].object_offset);
-                le_hash = o->entry.items[j->current_field].hash;
                 r = journal_file_move_to_object(f, OBJECT_DATA, p, &o);
                 if (IN_SET(r, -EADDRNOTAVAIL, -EBADMSG)) {
                         log_debug_errno(r, "Entry item %"PRIu64" data object is bad, skipping over it: %m", j->current_field);
@@ -2462,11 +2453,6 @@ _public_ int sd_journal_enumerate_data(sd_journal *j, const void **data, size_t
                 if (r < 0)
                         return r;
 
-                if (le_hash != o->data.hash) {
-                        log_debug("Entry item %"PRIu64" hash is bad, skipping over it.", j->current_field);
-                        continue;
-                }
-
                 r = return_data(j, f, o, data, size);
                 if (r == -EBADMSG) {
                         log_debug("Entry item %"PRIu64" data payload is bad, skipping over it.", j->current_field);