journal: fix tag ordering check

This commit is contained in:
Lennart Poettering
2012-08-20 15:59:33 +02:00
parent a2e99cdf94
commit f7fab8a5ae
4 changed files with 23 additions and 20 deletions
+4 -3
View 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;
}
+6 -5
View 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);
+1 -1
View 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;
}
+12 -11
View 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...");