All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Egorenkov <egorenar@linux.ibm.com>
To: oberpar@linux.ibm.com
Cc: gor@linux.ibm.com, hca@linux.ibm.com, agordeev@linux.ibm.com,
	borntraeger@linux.ibm.com,
	linux390-list@tuxmaker.boeblingen.de.ibm.com,
	linux-s390@vger.kernel.org
Subject: [PATCH v6 1/5] s390/sclp: Make parsing of received event buffers more robust
Date: Tue, 22 Sep 2026 08:42:59 +0200	[thread overview]
Message-ID: <20260922064303.524293-2-egorenar@linux.ibm.com> (raw)
In-Reply-To: <20260922064303.524293-1-egorenar@linux.ibm.com>

Ensure that
* an event buffer does not cross the end boundary of the SCCB buffer it is
  part of
* the total length of an event buffer is not smaller than the size of
  its header

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
---
 drivers/s390/char/sclp.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/s390/char/sclp.c b/drivers/s390/char/sclp.c
index 98e334724a62..7be4acec9d6e 100644
--- a/drivers/s390/char/sclp.c
+++ b/drivers/s390/char/sclp.c
@@ -532,8 +532,7 @@ EXPORT_SYMBOL(sclp_add_request);
 
 /* Dispatch events found in request buffer to registered listeners. Return 0
  * if all events were dispatched, non-zero otherwise. */
-static int
-sclp_dispatch_evbufs(struct sccb_header *sccb)
+static int sclp_dispatch_evbufs(struct sccb_header *sccb)
 {
 	unsigned long flags;
 	struct evbuf_header *evbuf;
@@ -544,11 +543,13 @@ sclp_dispatch_evbufs(struct sccb_header *sccb)
 
 	spin_lock_irqsave(&sclp_lock, flags);
 	rc = 0;
-	for (offset = sizeof(struct sccb_header); offset < sccb->length;
+	for (offset = sizeof(struct sccb_header);
+	     offset < sccb->length && (sccb->length - offset >= sizeof(struct evbuf_header));
 	     offset += evbuf->length) {
 		evbuf = (struct evbuf_header *) ((addr_t) sccb + offset);
 		/* Check for malformed hardware response */
-		if (evbuf->length == 0)
+		if (evbuf->length < sizeof(*evbuf) ||
+		    offset + evbuf->length > sccb->length)
 			break;
 		/* Search for event handler */
 		reg = NULL;
-- 
2.53.0


  reply	other threads:[~2026-09-22  6:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  6:42 [PATCH v6 0/5] s390/sclp: Misc fixes Alexander Egorenkov
2026-09-22  6:42 ` Alexander Egorenkov [this message]
2026-09-22  6:51   ` [PATCH v6 1/5] s390/sclp: Make parsing of received event buffers more robust sashiko-bot
2026-09-22  6:43 ` [PATCH v6 2/5] s390/sclp: Introduce macro sclp_gds_for_each() Alexander Egorenkov
2026-09-22  6:54   ` sashiko-bot
2026-09-22  6:43 ` [PATCH v6 3/5] s390/sclp_tty: Make use of sclp_gds_for_each() Alexander Egorenkov
2026-09-22  6:52   ` sashiko-bot
2026-09-22  6:43 ` [PATCH v6 4/5] s390/sclp_ocf: Fix computation of length of GDS values Alexander Egorenkov
2026-09-22  6:54   ` sashiko-bot
2026-09-22  6:43 ` [PATCH v6 5/5] s390/sclp: Ensure no callback gets called after sclp_unregister() returns Alexander Egorenkov
2026-09-22  6:52   ` 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=20260922064303.524293-2-egorenar@linux.ibm.com \
    --to=egorenar@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux390-list@tuxmaker.boeblingen.de.ibm.com \
    --cc=oberpar@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.