All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Martin Wilck" <martin.wilck@suse.com>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH v2] md/raid5: validate payload size before calculating payload_len
Date: Wed, 02 Sep 2026 17:08:37 +0000	[thread overview]
Message-ID: <20260902170837.C64161F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902165753.255675-1-mwilck@suse.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Out-of-bounds read of `payload->header.type` across page boundary
--

commit cf3844b320a187a8abab97af97eaad5cf6134ae8
Author: Martin Wilck <martin.wilck@suse.com>
md/raid5: validate payload size before calculating payload_len

This commit introduces a bounds check to verify that a payload fits into the
current metadata block. It ensures that the payload size and checksum fields
can be safely accessed without reading past the end of the metadata block.

> diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c
> index 7b7546bfa21fb..4a97846e9030b 100644
> --- a/drivers/md/raid5-cache.c
> +++ b/drivers/md/raid5-cache.c
> @@ -2002,26 +2002,35 @@ r5l_recovery_verify_data_checksum_for_mb(struct r5l_log *log,
>  		return -ENOMEM;
>  
>  	while (mb_offset < le32_to_cpu(mb->meta_size)) {
> +		uint32_t payload_size;
>  		sector_t payload_len;
>  
>  		payload = (void *)mb + mb_offset;
>  		payload_flush = (void *)mb + mb_offset;
>  
>  		if (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_DATA) {

[Severity: High]
This isn't a bug introduced by this patch, but could this read of
payload->header.type cause an out-of-bounds access across a page boundary?

In r5l_recovery_verify_data_checksum_for_mb(), if a corrupted or maliciously
crafted RAID journal log configures a payload size such that mb_offset
evaluates exactly to mb->meta_size - 1 (e.g. 4095), the loop condition
mb_offset < le32_to_cpu(mb->meta_size) will evaluate to true.

The subsequent read of le16_to_cpu(payload->header.type) will try to access
2 bytes starting at offset 4095. Does this mean it would attempt to read
offset 4096, which is out-of-bounds of the meta_page?

> +			if (mb_offset + sizeof(struct r5l_payload_data_parity)
> +			    > le32_to_cpu(mb->meta_size))
> +				goto mismatch;

[ ... ]

> @@ -2106,6 +2118,9 @@ r5c_recovery_analyze_meta_block(struct r5l_log *log,
>  		if (le16_to_cpu(payload->header.type) == R5LOG_PAYLOAD_FLUSH) {

[Severity: High]
This is also a pre-existing issue, but does the same out-of-bounds read flaw
exist here in r5c_recovery_analyze_meta_block() when analyzing payloads?

If mb_offset is just 1 byte shy of mb->meta_size, would reading the 2-byte
payload->header.type field read past the end of the metadata page before the
newly added bounds checks are reached?

>  			int i, count;
>  
> +			if (mb_offset + sizeof(struct r5l_payload_flush) >
> +			    le32_to_cpu(mb->meta_size))
> +				return -EINVAL;
>  			payload_len = sizeof(struct r5l_payload_flush) +
>  				(sector_t)le32_to_cpu(payload_flush->size);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902165753.255675-1-mwilck@suse.com?part=1

      reply	other threads:[~2026-09-02 17:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 16:57 [PATCH v2] md/raid5: validate payload size before calculating payload_len Martin Wilck
2026-09-02 17:08 ` sashiko-bot [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=20260902170837.C64161F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=martin.wilck@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.