From: Myoungwon Oh Date: Thu, 31 Aug 2023 02:43:24 +0000 (+0900) Subject: crimson/os/seastore/cbj: fix a potential overflow bug X-Git-Tag: v18.2.1~154^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=cac553aa72da18263437b87ad86945bb1e4cb197;p=ceph-ci.git crimson/os/seastore/cbj: fix a potential overflow bug 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 (cherry picked from commit 36982b66574ff277e04a02d5b9a28e80d0790778) --- diff --git a/src/crimson/os/seastore/journal/circular_journal_space.cc b/src/crimson/os/seastore/journal/circular_journal_space.cc index 7565c281557..4a7ba751886 100644 --- a/src/crimson/os/seastore/journal/circular_journal_space.cc +++ b/src/crimson/os/seastore/journal/circular_journal_space.cc @@ -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(); } diff --git a/src/crimson/os/seastore/seastore_types.h b/src/crimson/os/seastore/seastore_types.h index 55d8eb4a260..d5be001842b 100644 --- a/src/crimson/os/seastore/seastore_types.h +++ b/src/crimson/os/seastore/seastore_types.h @@ -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::max(); static constexpr segment_seq_t NULL_SEG_SEQ = MAX_SEG_SEQ;