]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: fix tag ordering check
authorLennart Poettering <lennart@poettering.net>
Mon, 20 Aug 2012 13:59:33 +0000 (15:59 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 20 Aug 2012 13:59:33 +0000 (15:59 +0200)
src/journal/journal-file.c
src/journal/journal-verify.c
src/journal/journalctl.c
src/journal/test-journal-verify.c

index c6b25ce54b29ba47b0060045570aacad4e84b36a..f419cf6b65ffdc0df54d2b6ef6091295abf203b6 100644 (file)
@@ -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;
                 }
 
index e3c3ccdb20ba667f683671225136dc199872ab5a..08f3e16aa98c30d5dc74c1ef80afe3507da6b096 100644 (file)
@@ -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);
 
index ba678a289fb7269277c49155ed54b63a7ec28a9a..e61ddf6d9244a957f1d0191556180d6b4cfdb29f 100644 (file)
@@ -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;
         }
index 4e6c119b6d0ce062556419cf00afb8b003d2b807..ed6e21dc0c53b02cc7e1768fa97d247db3a84a75 100644 (file)
@@ -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...");