public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Jenny Guanni Qu <qguanni@gmail.com>, <richard@nod.at>
Cc: <linux-mtd@lists.infradead.org>, <klaudia@vidocsecurity.com>,
	<dawid@vidocsecurity.com>
Subject: Re: [PATCH] ubifs: fix out-of-bounds write in LPT commit padding
Date: Sat, 14 Mar 2026 10:15:46 +0800	[thread overview]
Message-ID: <3fa4d791-4520-0e6d-d657-89d6fc4ba5cb@huawei.com> (raw)
In-Reply-To: <20260313222213.2181408-1-qguanni@gmail.com>

在 2026/3/14 6:22, Jenny Guanni Qu 写道:
> In write_cnodes(), when writing LPT data to a LEB, the code pads the
> write buffer to min_io_size alignment using:
> 
>      memset(buf + offs, 0xff, alen - wlen)
> 
> where wlen = offs - from and alen = ALIGN(wlen, min_io_size). The
> buffer (c->lpt_buf) is allocated with size c->leb_size. When offs is
> near leb_size and from is non-zero, the alignment padding can push
> the memset past the end of the buffer.
> 
> For example, with leb_size=4096, offs=4000, from=3584, min_io_size=1024:
>    wlen=416, alen=1024, padding=608 bytes at offset 4000
>    writes to offsets 4000..4607, 512 bytes past the 4096-byte buffer
Hi, Guanni
How does 'from' become '3584'(which is not aligned with min_io_size[1024])?
As far as I know, the 'from' comes from 'c->nhead_offs', which is always 
aligned with min_io_size.
> 
> Clamp the padding size to not exceed the buffer boundary in all 4
> instances of this pattern.
> 
> The OOB write was confirmed with KASAN using a test module that
> reproduces the arithmetic with matching buffer and alignment values.
> 
> Fixes: 1e51764a3c2a ("UBIFS: add new flash file system")
> Reported-by: Klaudia Kloc <klaudia@vidocsecurity.com>
> Reported-by: Dawid Moczadło <dawid@vidocsecurity.com>
> Tested-by: Jenny Guanni Qu <qguanni@gmail.com>
> Signed-off-by: Jenny Guanni Qu <qguanni@gmail.com>
> ---
>   fs/ubifs/lpt_commit.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c
> index 07351fdce722..77a7a2cd418f 100644
> --- a/fs/ubifs/lpt_commit.c
> +++ b/fs/ubifs/lpt_commit.c
> @@ -402,7 +402,7 @@ static int write_cnodes(struct ubifs_info *c)
>   			wlen = offs - from;
>   			if (wlen) {
>   				alen = ALIGN(wlen, c->min_io_size);
> -				memset(buf + offs, 0xff, alen - wlen);
> +				memset(buf + offs, 0xff, min_t(int, alen - wlen, c->leb_size - offs));
>   				err = ubifs_leb_write(c, lnum, buf + from, from,
>   						       alen);
>   				if (err)
> @@ -461,7 +461,7 @@ static int write_cnodes(struct ubifs_info *c)
>   		if (offs + c->lsave_sz > c->leb_size) {
>   			wlen = offs - from;
>   			alen = ALIGN(wlen, c->min_io_size);
> -			memset(buf + offs, 0xff, alen - wlen);
> +			memset(buf + offs, 0xff, min_t(int, alen - wlen, c->leb_size - offs));
>   			err = ubifs_leb_write(c, lnum, buf + from, from, alen);
>   			if (err)
>   				return err;
> @@ -487,7 +487,7 @@ static int write_cnodes(struct ubifs_info *c)
>   		if (offs + c->ltab_sz > c->leb_size) {
>   			wlen = offs - from;
>   			alen = ALIGN(wlen, c->min_io_size);
> -			memset(buf + offs, 0xff, alen - wlen);
> +			memset(buf + offs, 0xff, min_t(int, alen - wlen, c->leb_size - offs));
>   			err = ubifs_leb_write(c, lnum, buf + from, from, alen);
>   			if (err)
>   				return err;
> @@ -510,7 +510,7 @@ static int write_cnodes(struct ubifs_info *c)
>   	/* Write remaining data in buffer */
>   	wlen = offs - from;
>   	alen = ALIGN(wlen, c->min_io_size);
> -	memset(buf + offs, 0xff, alen - wlen);
> +	memset(buf + offs, 0xff, min_t(int, alen - wlen, c->leb_size - offs));
>   	err = ubifs_leb_write(c, lnum, buf + from, from, alen);
>   	if (err)
>   		return err;
> 


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2026-03-14  2:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-13 22:22 [PATCH] ubifs: fix out-of-bounds write in LPT commit padding Jenny Guanni Qu
2026-03-14  2:15 ` Zhihao Cheng [this message]
2026-03-14 22:33   ` Guanni Qu

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=3fa4d791-4520-0e6d-d657-89d6fc4ba5cb@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=dawid@vidocsecurity.com \
    --cc=klaudia@vidocsecurity.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=qguanni@gmail.com \
    --cc=richard@nod.at \
    /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