mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>, <stable@vger.kernel.org>
Subject: Re: [PATCH 1/2] md: fix bblog_size-driven OOB read in super_1_load() and super_1_sync()
Date: Sun, 20 Sep 2026 19:50:56 +0800	[thread overview]
Message-ID: <fad92649-e362-443a-93ea-205b11247e6d@fygo.io> (raw)
In-Reply-To: <20260917083820.57091-2-ndaugoing@gmail.com>

Hi,

在 2026/9/17 16:38, zjamg 写道:
> In super_1_load(), when the on-disk feature_map does not have the
> MD_FEATURE_BAD_BLOCKS flag set, but sb->bblog_offset is non-zero,
> rdev->badblocks.shift is initialized to 0 while completely bypassing
> the sectors > (PAGE_SIZE / 512) validation check on sb->bblog_size.

How can this happen? If this is just raw disk metadata inject failure,
just add a checking in super_1_load() is enough.

>
> Subsequently, when badblocks are updated, super_1_sync() enables the
> MD_FEATURE_BAD_BLOCKS feature flag and assigns bb->size directly from
> sb->bblog_size without validating that bb->size fits within the single
> allocated rdev->bb_page (which is PAGE_SIZE, or PAGE_SIZE / 512 sectors).
>
> When md_update_sb() later writes metadata via md_write_metadata(), an
> unvalidated bb->size (e.g. 0xFFFF) results in a bio whose length exceeds
> the backing page, causing out-of-bounds reads into kernel memory during
> block I/O and leaking kernel slab/page contents to disk.
>
> Fix this by:
> 1. Validating sb->bblog_size in the 'else if (sb->bblog_offset != 0)'
>     branch of super_1_load(), returning -EINVAL on oversized values.
> 2. Clamping bb->size in super_1_sync() to PAGE_SIZE / 512 to ensure it
>     never exceeds the backing rdev->bb_page capacity.
>
> Fixes: 2699b67223ac ("md: load/store badblock list from v1.x metadata")
> Cc: stable@vger.kernel.org
> Signed-off-by: zjamg <ndaugoing@gmail.com>
> ---
>   drivers/md/md.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 680b34a63cb3..d2433cf41e65 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1934,8 +1934,11 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
>   			if (!badblocks_set(&rdev->badblocks, sector, count, 1))
>   				return -EINVAL;
>   		}
> -	} else if (sb->bblog_offset != 0)
> +	} else if (sb->bblog_offset != 0) {
> +		if (le16_to_cpu(sb->bblog_size) > (PAGE_SIZE / 512))
> +			return -EINVAL;
>   		rdev->badblocks.shift = 0;
> +	}
>   
>   	if ((le32_to_cpu(sb->feature_map) &
>   	    (MD_FEATURE_PPL | MD_FEATURE_MULTIPLE_PPLS))) {
> @@ -2313,7 +2316,8 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
>   
>   			bb->sector = (rdev->sb_start +
>   				      (int)le32_to_cpu(sb->bblog_offset));
> -			bb->size = le16_to_cpu(sb->bblog_size);
> +			bb->size = min_t(sector_t, le16_to_cpu(sb->bblog_size),
> +					 PAGE_SIZE / 512);
>   		}
>   	}
>   

-- 
Thanks,
Kuai

  reply	other threads:[~2026-09-20 11:51 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 in md_write_metadata() 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 [this message]
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

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=fad92649-e362-443a-93ea-205b11247e6d@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=stable@vger.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®