Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Kyle Zeng <kylebot@openai.com>
To: stable@vger.kernel.org
Cc: outbounddisclosures@openai.com, Kyle Zeng <kylebot@openai.com>
Subject: [PATCH 6.12.y] bcachefs: validate disk group parent chains
Date: Thu, 11 Jun 2026 15:38:35 -0700	[thread overview]
Message-ID: <20260611223835.73757-1-kylebot@openai.com> (raw)

Disk-group parent IDs are imported from the superblock and later
followed by bch2_sb_disk_groups_to_cpu() while it propagates live
devices to their parent groups. The superblock validator currently
checks member group IDs and duplicate labels, but it does not validate
the parent field of each non-deleted group.

Reject parent IDs outside the disk-group table, parents that reference
deleted groups, and cyclic parent chains before the groups are imported.
This prevents crafted superblocks from making the CPU conversion walk
past cpu_g->entries.

Assisted-by: Codex:gpt-5.5
Signed-off-by: Kyle Zeng <kylebot@openai.com>
---
 fs/bcachefs/disk_groups.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/fs/bcachefs/disk_groups.c b/fs/bcachefs/disk_groups.c
index cde842a..52a0f44 100644
--- a/fs/bcachefs/disk_groups.c
+++ b/fs/bcachefs/disk_groups.c
@@ -26,6 +26,7 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb, struct bch_sb_field *
 	struct bch_disk_group *g, *sorted = NULL;
 	unsigned nr_groups = disk_groups_nr(groups);
 	unsigned i, len;
+	unsigned int parent, depth;
 	int ret = 0;
 
 	for (i = 0; i < sb->nr_devices; i++) {
@@ -63,6 +64,34 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb, struct bch_sb_field *
 			prt_printf(err, "label %u empty", i);
 			return -BCH_ERR_invalid_sb_disk_groups;
 		}
+
+		for (parent = BCH_GROUP_PARENT(g), depth = 0;
+		     parent;
+		     depth++) {
+			unsigned int parent_id = parent - 1;
+			struct bch_disk_group *parent_g;
+
+			if (depth == nr_groups) {
+				prt_printf(err, "label %u has cyclic parent chain", i);
+				return -BCH_ERR_invalid_sb_disk_groups;
+			}
+
+			if (parent_id >= nr_groups) {
+				prt_printf(err,
+					   "label %u has invalid parent %u (have %u)",
+					   i, parent_id, nr_groups);
+				return -BCH_ERR_invalid_sb_disk_groups;
+			}
+
+			parent_g = groups->entries + parent_id;
+			if (BCH_GROUP_DELETED(parent_g)) {
+				prt_printf(err, "label %u has deleted parent %u",
+					   i, parent_id);
+				return -BCH_ERR_invalid_sb_disk_groups;
+			}
+
+			parent = BCH_GROUP_PARENT(parent_g);
+		}
 	}
 
 	sorted = kmalloc_array(nr_groups, sizeof(*sorted), GFP_KERNEL);
-- 
2.54.0


             reply	other threads:[~2026-06-11 22:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11 22:38 Kyle Zeng [this message]
2026-06-12 14:41 ` [PATCH 6.12.y] bcachefs: validate disk group parent chains Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260611223835.73757-1-kylebot@openai.com \
    --to=kylebot@openai.com \
    --cc=outbounddisclosures@openai.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox