From cac553aa72da18263437b87ad86945bb1e4cb197 Mon Sep 17 00:00:00 2001 From: Myoungwon Oh Date: Thu, 31 Aug 2023 11:43:24 +0900 Subject: [PATCH] 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) --- src/crimson/os/seastore/journal/circular_journal_space.cc | 4 +++- src/crimson/os/seastore/seastore_types.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) 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; -- 2.39.5