Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Michał Kępień" <kernel@kempniu.pl>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH v3 4/4] mtdchar: finish OOB transfers after the data runs out
Date: Fri, 04 Dec 2026 23:23:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-250800@kernel.org> (raw)
In-Reply-To: <20261204-submit-mtdchar-page-chunking-v1-v3-4-2f36958a6e8d@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] mtdchar: missing upfront OOB bounds check causes partial
  flash I/O
- [Medium] mtdchar: per-page OOB write clamp silently drops OOB pages on
  docg3
- [Low] mtdchar: mtdchar_read_ioctl() returns page-rounded req.start to
  user
--

commit f16856695cba2d4a1b532796427c369789dbf8de
Author: James Hilliard <james.hilliard1@gmail.com>

mtdchar: finish OOB transfers after the data runs out

This commit keeps the MEMWRITE and MEMREAD ioctl loops running until
both data and OOB transfers complete, clamping OOB-only writes to one
page and advancing req.start past pages touched by either stream.

> diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
> index 454ec3ec0c982..575fea4a62300 100644
> --- a/drivers/mtd/mtdchar.c
> +++ b/drivers/mtd/mtdchar.c

[ ... ]

> @@ -684,6 +698,10 @@ mtdchar_write_ioctl(struct mtd_info *mtd, struct mtd_write_req __user *argp)
>  		if (ret)
>  			break;
>  
> +		/* Raw NAND accepts only one page per OOB-only write. */
> +		if (!ops.len)
> +			ops.ooblen = min_t(size_t, ops.ooblen, mtd_oobavail(mtd, &ops));

[Severity: Medium]
Can clamping ops.ooblen here cause out-of-bounds MEMWRITE requests to
partially program flash before failing with -EINVAL?

mtdchar_write_ioctl() only validates req.start + req.len against
mtd->size upfront.  Previously, a single-chunk OOB-only write whose
req.ooblen exceeded the remaining device OOB capacity was rejected
immediately by mtd_check_oob_ops().  With the per-page clamp, each
iteration passes mtd_check_oob_ops() and irreversibly programs flash
pages up to mtd->size before finally returning -EINVAL.

The same regression occurs in mtdchar_read_ioctl() now that
adjust_oob_length() is called unconditionally: a single-chunk combined
read with an out-of-bounds req.ooblen now reads valid pages, overwrites
user buffers, and updates req.ecc_stats and returned lengths before
failing on the next iteration.  Validating total req.ooblen against the
remaining OOB capacity upfront (matching mtd_check_oob_ops()) would
preserve atomic -EINVAL rejection for both ioctls.

[Severity: Medium]
Does splitting multi-page OOB-only writes into per-page calls silently
drop OOB pages on docg3?

In drivers/mtd/devices/docg3.c, doc_write_oob() delegates OOB-only
writes to doc_backup_oob(), which requires ooblen == DOC_LAYOUT_OOB_SIZE
and stages a single page into docg3->oob_write_buf for a later data
write instead of programming flash.  Previously, a multi-page OOB-only
MEMWRITE failed with -EINVAL; now, in MTD_OPS_PLACE_OOB or MTD_OPS_RAW
mode, each iteration passes one page, overwriting docg3->oob_write_buf
and returning 0 while discarding all earlier OOB pages.

[ ... ]

> @@ -826,11 +839,7 @@ mtdchar_read_ioctl(struct mtd_info *mtd, struct mtd_read_req __user *argp)
>  			break;
>  		}
>  
> -		if (usr_data)
> -			req.start += ops.retlen;
> -		else
> -			req.start += (u64)(ops.oobretlen / mtd_oobavail(mtd, &ops)) *
> -				     mtd->writesize;
> +		req.start = mtdchar_next_offset(mtd, req.start, &ops);

[Severity: Low]
Should mtdchar_read_ioctl() avoid returning a page-rounded req.start to
userspace?

Because req is copied back to userspace at the end of
mtdchar_read_ioctl(), updating req.start in place via
mtdchar_next_offset() now returns the next page boundary on partial-page
combined reads instead of start + retlen.  Tracking the loop offset in a
local variable would avoid leaking this internal page-rounding into the
returned structure.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-submit-mtdchar-page-chunking-v1-v3-0-2f36958a6e8d@gmail.com?part=4

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

      reply	other threads:[~2026-12-04 23:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 23:01 [PATCH v3 0/4] mtdchar: keep data and OOB aligned across ioctl chunks James Hilliard
2026-12-04 23:01 ` [PATCH v3 1/4] mtdchar: calculate OOB capacity from the starting column James Hilliard
2026-12-04 23:01 ` [PATCH v3 2/4] mtdchar: bound OOB reads to the data in intermediate chunks James Hilliard
2026-12-04 23:23   ` sashiko-bot
2026-12-04 23:02 ` [PATCH v3 3/4] mtdchar: keep OOB chunks aligned with their data pages James Hilliard
2026-12-04 23:20   ` sashiko-bot
2026-12-04 23:02 ` [PATCH v3 4/4] mtdchar: finish OOB transfers after the data runs out James Hilliard
2026-12-04 23:23   ` 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=sashiko-outbox-250800@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=kernel@kempniu.pl \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --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