chiark / gitweb /
journal: validate timestamps as well
authorLennart Poettering <lennart@poettering.net>
Sun, 19 Aug 2012 13:15:59 +0000 (15:15 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 19 Aug 2012 13:16:11 +0000 (15:16 +0200)
src/journal/fsprg.c
src/journal/journal-file.h
src/journal/journal-verify.c

index 34ce3be96b707bca7844f38d7746f98de8ded31b..2190b7c796857d1645a99ae85165e711b03f72d7 100644 (file)
@@ -160,7 +160,7 @@ static gcry_mpi_t twopowmodphi(uint64_t m, const gcry_mpi_t p) {
         gcry_mpi_sub_ui(phi, p, 1);
 
         /* count number of used bits in m */
         gcry_mpi_sub_ui(phi, p, 1);
 
         /* count number of used bits in m */
-        for (n = 0; ((uint64_t)1 << n) <= m; n++)
+        for (n = 0; (1ULL << n) <= m; n++)
                 ;
 
         r = gcry_mpi_new(0);
                 ;
 
         r = gcry_mpi_new(0);
index e2ef03347ce64fcdcc9a1fb98f043633daf180f5..7358173e7a912d3efd13924490b584fe3a121fd0 100644 (file)
@@ -119,6 +119,21 @@ int journal_file_open_reliably(
 #define ALIGN64(x) (((x) + 7ULL) & ~7ULL)
 #define VALID64(x) (((x) & 7ULL) == 0ULL)
 
 #define ALIGN64(x) (((x) + 7ULL) & ~7ULL)
 #define VALID64(x) (((x) & 7ULL) == 0ULL)
 
+static inline bool VALID_REALTIME(uint64_t u) {
+        /* This considers timestamps until the year 3112 valid. That should be plenty room... */
+        return u > 0 && u < (1ULL << 55);
+}
+
+static inline bool VALID_MONOTONIC(uint64_t u) {
+        /* This considers timestamps until 1142 years of runtime valid. */
+        return u < (1ULL << 55);
+}
+
+static inline bool VALID_EPOCH(uint64_t u) {
+        /* This allows changing the key for 1142 years, every usec. */
+        return u < (1ULL << 55);
+}
+
 #define JOURNAL_HEADER_CONTAINS(h, field) \
         (le64toh((h)->header_size) >= offsetof(Header, field) + sizeof((h)->field))
 
 #define JOURNAL_HEADER_CONTAINS(h, field) \
         (le64toh((h)->header_size) >= offsetof(Header, field) + sizeof((h)->field))
 
index a31817671b30e17926ee4de76fbd0f15d8f1cca8..535b2727acb947e1889469e2264cce7553b40524 100644 (file)
@@ -35,8 +35,8 @@
 
 /* FIXME:
  *
 
 /* FIXME:
  *
- * - write bit mucking test
  * - evolve key even if nothing happened in regular intervals
  * - evolve key even if nothing happened in regular intervals
+ * - add macro for accessing flags
  *
  * - Allow building without libgcrypt
  * - check with sparse
  *
  * - Allow building without libgcrypt
  * - check with sparse
@@ -115,7 +115,8 @@ static int journal_file_object_verify(JournalFile *f, Object *o) {
                         return -EBADMSG;
 
                 if (le64toh(o->entry.seqnum) <= 0 ||
                         return -EBADMSG;
 
                 if (le64toh(o->entry.seqnum) <= 0 ||
-                    le64toh(o->entry.realtime) <= 0)
+                    !VALID_REALTIME(le64toh(o->entry.realtime)) ||
+                    !VALID_MONOTONIC(le64toh(o->entry.monotonic)))
                         return -EBADMSG;
 
                 for (i = 0; i < journal_file_entry_n_items(o); i++) {
                         return -EBADMSG;
 
                 for (i = 0; i < journal_file_entry_n_items(o); i++) {
@@ -169,6 +170,10 @@ static int journal_file_object_verify(JournalFile *f, Object *o) {
         case OBJECT_TAG:
                 if (le64toh(o->object.size) != sizeof(TagObject))
                         return -EBADMSG;
         case OBJECT_TAG:
                 if (le64toh(o->object.size) != sizeof(TagObject))
                         return -EBADMSG;
+
+                if (!VALID_EPOCH(o->tag.epoch))
+                        return -EBADMSG;
+
                 break;
         }
 
                 break;
         }