From: "yu kuai" <yukuai@fygo.io>
To: "zjamg" <ndaugoing@gmail.com>, "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>
Subject: Re: [PATCH 2/2] md: add defensive bounds check for bio in md_write_metadata()
Date: Wed, 23 Sep 2026 19:22:48 +0800 [thread overview]
Message-ID: <763fbafc-8cf2-42dc-8a60-ab3ce2895342@fygo.io> (raw)
In-Reply-To: <20260917083820.57091-3-ndaugoing@gmail.com>
Hi,
在 2026/9/17 16:38, zjamg 写道:
> 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;
This is not a proper checking, as there is no error handler here. A better solution should
either make the rdev faulty or retry the metadata. But I don't think this is necessary, as
there isn't any path to trigger this error other than raw disk metadata inject.
> +
> bio = bio_alloc_bioset(rdev->meta_bdev ? rdev->meta_bdev : rdev->bdev,
> 1,
> REQ_OP_WRITE | REQ_SYNC | REQ_IDLE | REQ_META
--
Thanks,
Kuai
prev parent reply other threads:[~2026-09-23 11:23 UTC|newest]
Thread overview: 8+ 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-20 11:50 ` yu kuai
2026-09-22 4:45 ` Yuchao Zhang
2026-09-22 4:46 ` [PATCH v2] md: validate bblog_size when loading v1.x badblocks metadata Yuchao Zhang
2026-09-23 11:16 ` yu kuai
2026-09-17 8:38 ` [PATCH 2/2] md: add defensive bounds check for bio in md_write_metadata() zjamg
2026-09-23 11:22 ` yu kuai [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=763fbafc-8cf2-42dc-8a60-ab3ce2895342@fygo.io \
--to=yukuai@fygo.io \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=magiclinan@didiglobal.com \
--cc=ndaugoing@gmail.com \
--cc=neil@brown.name \
--cc=song@kernel.org \
--cc=xiao@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
all inboxes | Powered by JetHome®