mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Alejandro Pacheco <ale@alepacheco.dev>,
	Richard Weinberger <richard@nod.at>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] ubi: Check the data size of the last LEB of static volumes
Date: Mon, 26 Oct 2026 12:43:24 +0800	[thread overview]
Message-ID: <22ec08e4-90cc-a45a-e334-c355da430928@huawei.com> (raw)
In-Reply-To: <67a5dbbb-911a-4f24-b862-9dae24f958e0@alepacheco.dev>

在 2026/10/24 20:43, Alejandro Pacheco 写道:
> From: Alejandro Pacheco <ale@alepacheco.dev>
> 
> For a static volume, init_volumes() takes the data size of its last LEB
> from the attach information, av->last_data_size, as vol->last_eb_bytes.
> When the volume is first opened, ubi_check_volume() reads that many
> bytes of the last LEB into a buffer of vol->usable_leb_size bytes.
> 
> Nothing bounds that size by vol->usable_leb_size. When UBI attaches by
> scanning, it is the data_size of the last LEB's VID header, which
> validate_vid_hdr() only checks against ubi->leb_size; that is larger
> than the usable LEB size of a volume with a non-zero data_pad. When UBI
> attaches from a fastmap, it can be the last_eb_bytes of the volume's
> fastmap header, which is not checked at all. A larger size makes
> ubi_check_volume() write past the end of its buffer.
> 
> Before UBI comes up, check_attaching_info() runs check_av() on every
> volume that has attach information, to check it against the volume's
> record in the volume table. Also reject there a static volume whose last
> LEB data size is negative or larger than vol->usable_leb_size. Images
> written by UBI or ubinize are not affected: no LEB of a static volume
> holds more data than its usable LEB size.
> 
> This needs a crafted image (the VID header and the fastmap carry CRCs
> that catch random corruption) on a device that UBI attaches at boot or
> that a user with CAP_SYS_RESOURCE attaches.
> 
> An LLM coding assistant was used to find this bug and to write this
> patch and its changelog.
> 
> Fixes: 801c135ce73d ("UBI: Unsorted Block Images")
> Cc: stable@vger.kernel.org
> Signed-off-by: Alejandro Pacheco <ale@alepacheco.dev>
> ---
>   drivers/mtd/ubi/vtbl.c | 6 ++++++
>   1 file changed, 6 insertions(+)

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> 
> diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
> index 06d87a3013a..f1bd6e1e488 100644
> --- a/drivers/mtd/ubi/vtbl.c
> +++ b/drivers/mtd/ubi/vtbl.c
> @@ -696,6 +696,12 @@ static int check_av(const struct ubi_volume *vol,
>   		err = 5;
>   		goto bad;
>   	}
> +	if (vol->vol_type == UBI_STATIC_VOLUME &&
> +	    (av->last_data_size < 0 ||
> +	     av->last_data_size > vol->usable_leb_size)) {
> +		err = 6;
> +		goto bad;
> +	}
>   	return 0;
>   
>   bad:
> .
> 


      reply	other threads:[~2026-10-26  4:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-24 12:43 [PATCH 0/2] ubi: Check two values read from the media at attach time Alejandro Pacheco
2026-10-24 12:43 ` [PATCH 1/2] ubi: fastmap: Check the PEB numbers in the fastmap lists Alejandro Pacheco
2026-10-26  3:29   ` Zhihao Cheng
2026-10-24 12:43 ` [PATCH 2/2] ubi: Check the data size of the last LEB of static volumes Alejandro Pacheco
2026-10-26  4:43   ` Zhihao Cheng [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=22ec08e4-90cc-a45a-e334-c355da430928@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=ale@alepacheco.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    /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®