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: v19.0.0~463^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=36982b66574ff277e04a02d5b9a28e80d0790778;p=ceph.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 --- diff --git a/src/crimson/os/seastore/journal/circular_journal_space.cc b/src/crimson/os/seastore/journal/circular_journal_space.cc index c36064acb12..123bb91353c 100644 --- a/src/crimson/os/seastore/journal/circular_journal_space.cc +++ b/src/crimson/os/seastore/journal/circular_journal_space.cc @@ -42,8 +42,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 26c5017aadb..0b4ad853687 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;