gentoo-overlay/sys-kernel/hardened-kernel/files/linux-6.12/0103-bcachefs-check-for-bac...

54 lines
2.0 KiB
Diff

From 3f2e467845296b24eb0e0d026e1f551ef73f0896 Mon Sep 17 00:00:00 2001
From: Kent Overstreet <kent.overstreet@linux.dev>
Date: Mon, 18 Nov 2024 00:16:52 -0500
Subject: [PATCH 103/233] bcachefs: check for backpointers to invalid device
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Alexander Miroshnichenko <alex@millerson.name>
---
fs/bcachefs/backpointers.c | 4 ++++
fs/bcachefs/sb-errors_format.h | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/bcachefs/backpointers.c b/fs/bcachefs/backpointers.c
index a9ffbea277bd..1c7ddaed6c1c 100644
--- a/fs/bcachefs/backpointers.c
+++ b/fs/bcachefs/backpointers.c
@@ -59,6 +59,10 @@ int bch2_backpointer_validate(struct bch_fs *c, struct bkey_s_c k,
"backpointer level bad: %u >= %u",
bp.v->level, BTREE_MAX_DEPTH);
+ bkey_fsck_err_on(bp.k->p.inode == BCH_SB_MEMBER_INVALID,
+ c, backpointer_dev_bad,
+ "backpointer for BCH_SB_MEMBER_INVALID");
+
rcu_read_lock();
struct bch_dev *ca = bch2_dev_rcu_noerror(c, bp.k->p.inode);
if (!ca) {
diff --git a/fs/bcachefs/sb-errors_format.h b/fs/bcachefs/sb-errors_format.h
index d5b18ff1645c..9e3425f533bc 100644
--- a/fs/bcachefs/sb-errors_format.h
+++ b/fs/bcachefs/sb-errors_format.h
@@ -138,6 +138,7 @@ enum bch_fsck_flags {
x(discarding_bucket_not_in_need_discard_btree, 291, 0) \
x(backpointer_bucket_offset_wrong, 125, 0) \
x(backpointer_level_bad, 294, 0) \
+ x(backpointer_dev_bad, 297, 0) \
x(backpointer_to_missing_device, 126, 0) \
x(backpointer_to_missing_alloc, 127, 0) \
x(backpointer_to_missing_ptr, 128, 0) \
@@ -307,7 +308,7 @@ enum bch_fsck_flags {
x(logged_op_but_clean, 283, FSCK_AUTOFIX) \
x(compression_opt_not_marked_in_sb, 295, FSCK_AUTOFIX) \
x(compression_type_not_marked_in_sb, 296, FSCK_AUTOFIX) \
- x(MAX, 297, 0)
+ x(MAX, 298, 0)
enum bch_sb_error_id {
#define x(t, n, ...) BCH_FSCK_ERR_##t = n,
--
2.45.2