From: zjamg <ndaugoing@gmail.com>
To: Song Liu <song@kernel.org>, Yu Kuai <yukuai@fygo.io>
Cc: Li Nan <magiclinan@didiglobal.com>, Xiao Ni <xiao@kernel.org>,
NeilBrown <neil@brown.name>,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
zjamg <ndaugoing@gmail.com>
Subject: [PATCH 2/2] md: add defensive bounds check for bio in md_write_metadata()
Date: Thu, 17 Sep 2026 16:38:20 +0800 [thread overview]
Message-ID: <20260917083820.57091-3-ndaugoing@gmail.com> (raw)
In-Reply-To: <20260917083820.57091-1-ndaugoing@gmail.com>
md_write_metadata() allocates a single-bvec bio via bio_alloc_bioset()
with nr_vecs = 1 and attaches a single page 'page' (either rdev->sb_page
or rdev->bb_page) via __bio_add_page(bio, page, size, offset).
Because the bio can only ever represent a single backing page, passing
a non-positive size or a length where offset + size > PAGE_SIZE is invalid
and can lead to out-of-bounds reads during I/O submission.
Add a defensive check in md_write_metadata() so that any oversized or
invalid request triggers WARN_ON_ONCE() and aborts before constructing
the bio.
Signed-off-by: zjamg <ndaugoing@gmail.com>
---
drivers/md/md.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index d2433cf41e65..3fda2965c631 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1142,6 +1142,9 @@ void md_write_metadata(struct mddev *mddev, struct md_rdev *rdev,
if (test_bit(Faulty, &rdev->flags))
return;
+ if (WARN_ON_ONCE(size <= 0 || offset + size > PAGE_SIZE))
+ return;
+
bio = bio_alloc_bioset(rdev->meta_bdev ? rdev->meta_bdev : rdev->bdev,
1,
REQ_OP_WRITE | REQ_SYNC | REQ_IDLE | REQ_META
--
2.53.0
prev parent reply other threads:[~2026-09-17 8:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 8:38 [PATCH 0/2] md: fix bblog_size-driven OOB read " zjamg
2026-09-17 8:38 ` [PATCH 1/2] md: fix bblog_size-driven OOB read in super_1_load() and super_1_sync() zjamg
2026-09-17 8:38 ` zjamg [this message]
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=20260917083820.57091-3-ndaugoing@gmail.com \
--to=ndaugoing@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=magiclinan@didiglobal.com \
--cc=neil@brown.name \
--cc=song@kernel.org \
--cc=xiao@kernel.org \
--cc=yukuai@fygo.io \
/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
all inboxes | Powered by JetHome®