From: sashiko-bot@kernel.org
To: "Markus Elfring" <Markus.Elfring@web.de>
Cc: linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v2] block: partitions: Use seq_buf_putc() at 24 places
Date: Mon, 29 Jun 2026 07:35:08 +0000 [thread overview]
Message-ID: <20260629073509.0CB5B1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <7360cab3-7a2f-4903-85f1-0f03387b0d88@web.de>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Out-of-bounds read in sysv68 partition parser leading to a kernel memory leak.
- [Medium] Uninitialized variable 'len' may lead to a NULL pointer dereference or undefined behavior.
--
commit 350b3ea7021ee2238b49cf91963fe54906868307
Author: Markus Elfring <elfring@users.sourceforge.net>
block: partitions: Use seq_buf_putc() at 24 places
Single line breaks should occasionally be put into a sequence buffer.
Thus use the seq_buf_putc() function in these implementations.
The source code was transformed by using the Coccinelle software.
[ ... ]
> diff --git a/block/partitions/of.c b/block/partitions/of.c
> index 53664ea06b654..7803e6f4ecdd9 100644
> --- a/block/partitions/of.c
> +++ b/block/partitions/of.c
> @@ -104,7 +104,7 @@ int of_partition(struct parsed_partitions *state)
> slot++;
> }
>
> - seq_buf_puts(&state->pp_buf, "\n");
> + seq_buf_putc(&state->pp_buf, '\n');
[Severity: Medium]
This is a pre-existing issue, but I noticed a potential uninitialized
variable bug when looking at the partition validation called just before
this in of_partition().
If a device tree partition node is missing the 'reg' property:
block/partitions/of.c:validate_of_partition() {
...
int len;
const __be32 *reg = of_get_property(np, "reg", &len);
int a_cells = of_n_addr_cells(np);
int s_cells = of_n_size_cells(np);
/* Make sure reg len match the expected addr and size cells */
if (len / sizeof(*reg) != a_cells + s_cells)
...
}
of_get_property() returns NULL and leaves len uninitialized. The code then
divides this uninitialized len by 4 and compares it to expected cell counts.
If the uninitialized stack garbage happens to match, could this proceed to
add_of_partition() where it directly passes the NULL reg pointer to
of_read_number(), unconditionally dereferencing it?
block/partitions/of.c:add_of_partition() {
...
int len;
const __be32 *reg = of_get_property(np, "reg", &len);
int a_cells = of_n_addr_cells(np);
int s_cells = of_n_size_cells(np);
/* Convert bytes to sector size */
u64 offset = of_read_number(reg, a_cells) / SECTOR_SIZE;
...
}
[ ... ]
> diff --git a/block/partitions/sysv68.c b/block/partitions/sysv68.c
> index 470e0f9de7be3..31d348ac2dfb3 100644
> --- a/block/partitions/sysv68.c
> +++ b/block/partitions/sysv68.c
> @@ -86,7 +86,7 @@ int sysv68_partition(struct parsed_partitions *state)
> }
> slot++;
> }
> - seq_buf_puts(&state->pp_buf, "\n");
> + seq_buf_putc(&state->pp_buf, '\n');
[Severity: High]
This isn't a bug introduced by this patch, but does the loop immediately
preceding this code have an out-of-bounds read issue?
sysv68_partition() reads the number of slices from the untrusted disk
label without validating it against the 512-byte sector buffer bounds:
block/partitions/sysv68.c:sysv68_partition() {
...
slice = (struct slice *)data;
for (i = 0; i < slices; i++, slice++) {
if (slot == state->limit)
break;
if (be32_to_cpu(slice->nblocks)) {
put_partition(state, slot,
be32_to_cpu(slice->blkoff),
be32_to_cpu(slice->nblocks));
...
}
It then iterates up to state->limit (typically 256) times, advancing the
slice pointer. Reading 256 struct slice entries takes 2048 bytes out of a
guaranteed 512-byte sector buffer.
If the 512-byte sector is located near the end of a mapped page, could
reading beyond 512 bytes cross into adjacent physical kernel memory and
leak it via the partition table?
--
Sashiko AI review · https://sashiko.dev/#/patchset/7360cab3-7a2f-4903-85f1-0f03387b0d88@web.de?part=1
next prev parent reply other threads:[~2026-06-29 7:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <59dfd2ef-2fda-4dd0-a288-52c35613e778@web.de>
[not found] ` <ajzkRM_RFKBpp0i5@ashevche-desk.local>
[not found] ` <7de415a7-457d-4dd2-aebb-8e179fa0bbcd@web.de>
[not found] ` <aj061omzs5WN5ar6@ashevche-desk.local>
2026-06-29 7:16 ` [PATCH v2] block: partitions: Use seq_buf_putc() at 24 places Markus Elfring
2026-06-29 7:35 ` sashiko-bot [this message]
2026-06-29 7:35 ` Andy Shevchenko
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=20260629073509.0CB5B1F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Markus.Elfring@web.de \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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