]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/os/seastore/cbj: fix a potential overflow bug
authorMyoungwon Oh <myoungwon.oh@samsung.com>
Thu, 31 Aug 2023 02:43:24 +0000 (11:43 +0900)
committerMatan Breizman <mbreizma@redhat.com>
Wed, 11 Oct 2023 11:54:43 +0000 (11:54 +0000)
CircularBoundedJournal is similar to circular queue, so segment_seq
increases after rolling. However, current implementation always
increases segment_seq_t when rolling occurs, resulting in
the overflow if segment_seq_t hits MAX_SEG_SEQ.

To mitigate this, this commit changes the type of the segment_seq_t
to uint64_t.

Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
(cherry picked from commit 36982b66574ff277e04a02d5b9a28e80d0790778)

src/crimson/os/seastore/journal/circular_journal_space.cc
src/crimson/os/seastore/seastore_types.h

index 7565c281557635c4e91896f6f4f2564a7db52b77..4a7ba751886029008b4acef3cd6c4d70a4286e16 100644 (file)
@@ -41,8 +41,10 @@ CircularJournalSpace::roll_ertr::future<> CircularJournalSpace::roll() {
     get_records_start(),
     get_device_id());
   auto seq = get_written_to();
+  seq.segment_seq++;
+  assert(seq.segment_seq < MAX_SEG_SEQ);
   set_written_to(
-    journal_seq_t{++seq.segment_seq, paddr});
+    journal_seq_t{seq.segment_seq, paddr});
   return roll_ertr::now();
 }
 
index 55d8eb4a260ac2bb079cc2aabbe362241bb9e17a..d5be001842b4aa40557ef33f0234065bee02a308 100644 (file)
@@ -210,7 +210,7 @@ constexpr segment_id_t NULL_SEG_ID = MAX_SEG_ID;
 
 /* Monotonically increasing segment seq, uniquely identifies
  * the incarnation of a segment */
-using segment_seq_t = uint32_t;
+using segment_seq_t = uint64_t;
 static constexpr segment_seq_t MAX_SEG_SEQ =
   std::numeric_limits<segment_seq_t>::max();
 static constexpr segment_seq_t NULL_SEG_SEQ = MAX_SEG_SEQ;