diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-08-20 15:59:33 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-08-20 15:59:33 +0200 |
commit | f7fab8a5ae7a3b378040203821383f5a8fc91126 (patch) | |
tree | 27cff2a90b66f0e2ff4300c01de981233c8e8598 | |
parent | a2e99cdf94a8a0350ff13b241de07f34c015b1fc (diff) |
journal: fix tag ordering check
-rw-r--r-- | src/journal/journal-file.c | 7 | ||||
-rw-r--r-- | src/journal/journal-verify.c | 11 | ||||
-rw-r--r-- | src/journal/journalctl.c | 2 | ||||
-rw-r--r-- | src/journal/test-journal-verify.c | 23 |
4 files changed, 23 insertions, 20 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index c6b25ce54b..f419cf6b65 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -1855,7 +1855,7 @@ void journal_file_dump(JournalFile *f) { break; case OBJECT_ENTRY: - printf("Type: OBJECT_ENTRY %llu %llu %llu\n", + printf("Type: OBJECT_ENTRY seqnum=%llu monotonic=%llu realtime=%llu\n", (unsigned long long) le64toh(o->entry.seqnum), (unsigned long long) le64toh(o->entry.monotonic), (unsigned long long) le64toh(o->entry.realtime)); @@ -1874,8 +1874,9 @@ void journal_file_dump(JournalFile *f) { break; case OBJECT_TAG: - printf("Type: OBJECT_TAG %llu\n", - (unsigned long long) le64toh(o->tag.seqnum)); + printf("Type: OBJECT_TAG seqnum=%llu epoch=%llu\n", + (unsigned long long) le64toh(o->tag.seqnum), + (unsigned long long) le64toh(o->tag.epoch)); break; } diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index e3c3ccdb20..08f3e16aa9 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -709,7 +709,7 @@ int journal_file_verify( bool show_progress) { int r; Object *o; - uint64_t p = 0, last_tag = 0, last_epoch = 0, last_tag_realtime = 0; + uint64_t p = 0, last_tag = 0, last_epoch = 0, last_tag_realtime = 0, last_sealed_realtime = 0; uint64_t entry_seqnum = 0, entry_monotonic = 0, entry_realtime = 0; sd_id128_t entry_boot_id; bool entry_seqnum_set = false, entry_monotonic_set = false, entry_realtime_set = false, found_main_entry_array = false; @@ -838,7 +838,7 @@ int journal_file_verify( if (r < 0) goto fail; - if (last_tag_realtime > le64toh(o->entry.realtime)) { + if (le64toh(o->entry.realtime) < last_tag_realtime) { log_error("Older entry after newer tag at %llu", (unsigned long long) p); r = -EBADMSG; goto fail; @@ -962,8 +962,8 @@ int journal_file_verify( if (f->seal) { log_debug("Checking tag %llu..", (unsigned long long) le64toh(o->tag.seqnum)); - rt = (o->tag.epoch + 1) * f->fss_interval_usec + f->fss_start_usec; - if (entry_realtime_set && entry_realtime >= rt) { + rt = f->fss_start_usec + o->tag.epoch * f->fss_interval_usec; + if (entry_realtime_set && entry_realtime >= rt + f->fss_interval_usec) { log_error("Tag/entry realtime timestamp out of synchronization at %llu", (unsigned long long) p); r = -EBADMSG; goto fail; @@ -1014,6 +1014,7 @@ int journal_file_verify( f->hmac_running = false; last_tag_realtime = rt; + last_sealed_realtime = entry_realtime; } last_tag = p + ALIGN64(le64toh(o->object.size)); @@ -1158,7 +1159,7 @@ int journal_file_verify( if (first_validated) *first_validated = last_tag_realtime ? le64toh(f->header->head_entry_realtime) : 0; if (last_validated) - *last_validated = last_tag_realtime; + *last_validated = last_sealed_realtime; if (last_contained) *last_contained = le64toh(f->header->tail_entry_realtime); diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index ba678a289f..e61ddf6d92 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -478,7 +478,7 @@ static int setup_keys(void) { return log_oom(); if (access(p, F_OK) >= 0) { - log_error("Evolving key file %s exists already.", p); + log_error("Sealing key file %s exists already.", p); r = -EEXIST; goto finish; } diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c index 4e6c119b6d..ed6e21dc0c 100644 --- a/src/journal/test-journal-verify.c +++ b/src/journal/test-journal-verify.c @@ -108,7 +108,8 @@ int main(int argc, char *argv[]) { log_info("Verifying..."); assert_se(journal_file_open("test.journal", O_RDONLY, 0666, true, true, NULL, NULL, NULL, &f) == 0); - journal_file_print_header(f); + /* journal_file_print_header(f); */ + journal_file_dump(f); assert_se(journal_file_verify(f, verification_key, &from, &to, &total, true) >= 0); @@ -120,21 +121,21 @@ int main(int argc, char *argv[]) { } journal_file_close(f); - log_info("Toggling bits..."); + if (verification_key) { + log_info("Toggling bits..."); - assert_se(stat("test.journal", &st) >= 0); + assert_se(stat("test.journal", &st) >= 0); - for (p = 240*8; p < ((uint64_t) st.st_size * 8); p ++) { - bit_toggle("test.journal", p); + for (p = 38448*8+0; p < ((uint64_t) st.st_size * 8); p ++) { + bit_toggle("test.journal", p); - log_info("[ %llu+%llu]", (unsigned long long) p / 8, (unsigned long long) p % 8); + log_info("[ %llu+%llu]", (unsigned long long) p / 8, (unsigned long long) p % 8); - if (raw_verify("test.journal", verification_key) >= 0) { - log_notice(ANSI_HIGHLIGHT_RED_ON ">>>> %llu (bit %llu) can be toggled without detection." ANSI_HIGHLIGHT_OFF, (unsigned long long) p / 8, (unsigned long long) p % 8); - sleep(1); - } + if (raw_verify("test.journal", verification_key) >= 0) + log_notice(ANSI_HIGHLIGHT_RED_ON ">>>> %llu (bit %llu) can be toggled without detection." ANSI_HIGHLIGHT_OFF, (unsigned long long) p / 8, (unsigned long long) p % 8); - bit_toggle("test.journal", p); + bit_toggle("test.journal", p); + } } log_info("Exiting..."); |