summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-02-28 03:14:23 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:08:16 +0300
commit8db2acde2fca80954b4db12977182aa44b1e85fe (patch)
tree14813240f2719823a946b6bc62a755ae9ea22c01
parent28062d320bded23eb7d24633e6ab11ea3c03487b (diff)
downloadlinux-8db2acde2fca80954b4db12977182aa44b1e85fe.tar.xz
bcachefs: fix integer underflow in journal code
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/journal.c4
-rw-r--r--fs/bcachefs/journal.h2
2 files changed, 5 insertions, 1 deletions
diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c
index 91d0e5d443ed..3a6040244064 100644
--- a/fs/bcachefs/journal.c
+++ b/fs/bcachefs/journal.c
@@ -256,6 +256,8 @@ static int journal_entry_open(struct journal *j)
do {
old.v = new.v = v;
+ EBUG_ON(journal_state_count(new, new.idx));
+
if (old.cur_entry_offset == JOURNAL_ENTRY_ERROR_VAL)
return -EROFS;
@@ -429,7 +431,7 @@ void bch2_journal_entry_res_resize(struct journal *j,
if (d <= 0)
goto out;
- j->cur_entry_u64s -= d;
+ j->cur_entry_u64s = max_t(int, 0, j->cur_entry_u64s - d);
smp_mb();
state = READ_ONCE(j->reservations);
diff --git a/fs/bcachefs/journal.h b/fs/bcachefs/journal.h
index 4acb0f59396d..77d59fb0b151 100644
--- a/fs/bcachefs/journal.h
+++ b/fs/bcachefs/journal.h
@@ -292,6 +292,8 @@ static inline int journal_res_get_fast(struct journal *j,
if (new.cur_entry_offset + res->u64s > j->cur_entry_u64s)
return 0;
+ EBUG_ON(!journal_state_count(new, new.idx));
+
if (flags & JOURNAL_RES_GET_CHECK)
return 1;