From: sashiko-bot@kernel.org
To: "Alexander Egorenkov" <egorenar@linux.ibm.com>
Cc: "Christian Borntraeger" <borntraeger@linux.ibm.com>,
linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v5 2/4] s390/sclp_tty: Make use of sclp_gds_for_each()
Date: Thu, 17 Sep 2026 07:12:07 +0000 [thread overview]
Message-ID: <20260917071207.E23701F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260917065824.2858737-3-egorenar@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] s390/sclp: out-of-bounds read in sclp_gds_for_each() due to integer promotion
--
commit b02b1435e7ea0c6d35613a83d6a0bafa8d59fb95
Author: Alexander Egorenkov <egorenar@linux.ibm.com>
s390/sclp_tty: Make use of sclp_gds_for_each()
This commit replaces manual iterations over gds subvector entries with the
sclp_gds_for_each() macro. The stated goal is to handle erroneous entries
in gds vectors and subvectors more safely.
> diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
> index 0a92d08830e7c..4353890bbf8af 100644
> --- a/drivers/s390/char/sclp_tty.c
> +++ b/drivers/s390/char/sclp_tty.c
> @@ -418,38 +418,38 @@ static void sclp_get_input(struct gds_subvector *sv)
>
> static inline void sclp_eval_selfdeftextmsg(struct gds_subvector *sv)
> {
> - void *end;
> -
> - end = (void *) sv + sv->length;
> - for (sv = sv + 1; (void *) sv < end; sv = (void *) sv + sv->length)
> + void *start = sv + 1;
> + void *end = (void *) sv + sv->length;
> + int n;
> + sclp_gds_for_each(sv, n, start, end) {
[Severity: High]
Does this code introduce an out-of-bounds read regression if the hardware
provides a malformed sccb buffer with a length smaller than the header size?
If sv->length is smaller than sizeof(*sv), start will be greater than end.
In the sclp_gds_for_each() macro defined in drivers/s390/char/sclp.h, n is
defined as an int and evaluated as n = (end) - (start), which becomes a
negative value:
drivers/s390/char/sclp.h:
#define sclp_gds_for_each(v, n, start, end) \
for ((n) = (end) - (start), (v) = (start); \
(n) >= sizeof(*(v)) && (v)->length >= sizeof(*(v)) && (v)->length <= (n); \
(n) -= (v)->length, (v) = (void*)(v) + (v)->length)
Because sizeof returns an unsigned size_t, standard C integer promotion
rules convert the negative int n to a very large positive size_t value
when evaluating (n) >= sizeof(*(v)). This incorrectly bypasses the initial
bounds check.
The condition then proceeds to evaluate (v)->length >= sizeof(*(v)),
dereferencing v. Since v points to start which is beyond end, this results
in an out-of-bounds memory read (1 or 2 bytes), which could cause a kernel
panic due to a page fault on unmapped memory or trigger kasan.
This regression is exposed here in sclp_eval_selfdeftextmsg(), but also
directly in sclp_tty_receiver() when parsing untrusted sclp event buffers
from the hardware or hypervisor, where an evbuf->length smaller than
sizeof(*evbuf) causes start > end:
drivers/s390/char/sclp_tty.c:sclp_tty_receiver() {
...
v = sclp_find_gds_vector(evbuf + 1, (void *) evbuf + evbuf->length,
GDS_ID_MDSMU);
...
}
> if (sv->key == 0x30)
> sclp_get_input(sv);
> + }
> }
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260917065824.2858737-1-egorenar@linux.ibm.com?part=2
next prev parent reply other threads:[~2026-09-17 7:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 6:58 [PATCH v5 0/4] s390/sclp: Misc fixes Alexander Egorenkov
2026-09-17 6:58 ` [PATCH v5 1/4] s390/sclp: Introduce macro sclp_gds_for_each() Alexander Egorenkov
2026-09-17 7:08 ` sashiko-bot
2026-09-17 9:49 ` Alexander Egorenkov
2026-09-17 12:32 ` Peter Oberparleiter
2026-09-17 13:21 ` Alexander Egorenkov
2026-09-17 6:58 ` [PATCH v5 2/4] s390/sclp_tty: Make use of sclp_gds_for_each() Alexander Egorenkov
2026-09-17 7:12 ` sashiko-bot [this message]
2026-09-17 6:58 ` [PATCH v5 3/4] s390/sclp_ocf: Fix computation of length of GDS values Alexander Egorenkov
2026-09-17 7:09 ` sashiko-bot
2026-09-17 12:50 ` Peter Oberparleiter
2026-09-17 6:58 ` [PATCH v5 4/4] s390/sclp: Ensure no callback gets called after sclp_unregister() returns Alexander Egorenkov
2026-09-17 7:07 ` sashiko-bot
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=20260917071207.E23701F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=egorenar@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