All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] s390/monwriter: Reject buffer reuse with different data length
@ 2026-06-23 17:44 Gerald Schaefer
  2026-06-23 17:55 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Gerald Schaefer @ 2026-06-23 17:44 UTC (permalink / raw)
  To: linux-s390; +Cc: Heiko Carstens, Christian Borntraeger, Alexander Gordeev

When data buffers are reused, e.g. for interval sample records, the
first record determines the data length, and the size of the buffer for
user copy. Current monwriter code does not check if the data length was
changed for subsequent records, which also would never happen for valid
user programs.

However, a malicious user could change the data length, resulting in out
of bounds user copy to the kernel buffer, and memory corruption. By
default, the monwriter misc device is created with root-only permissions,
so practical impact is typically low.

Fix this by checking for changed data length and rejecting such records.

Cc: stable@vger.kernel.org
Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
---
 drivers/s390/char/monwriter.c | 3 +++
 1 file changed, 3 insertions(+)

---
Changes in v2:
- Move check into "else if", to avoid NULL pointer dereference after
  MONWRITE_STOP_INTERVAL.

diff --git a/drivers/s390/char/monwriter.c b/drivers/s390/char/monwriter.c
index eaeb4a6384d1..ecf121a87f88 100644
--- a/drivers/s390/char/monwriter.c
+++ b/drivers/s390/char/monwriter.c
@@ -122,6 +122,9 @@ static int monwrite_new_hdr(struct mon_private *monpriv)
 			kfree(monbuf->data);
 			kfree(monbuf);
 			monbuf = NULL;
+		} else if (monbuf->hdr.datalen != monhdr->datalen) {
+			/* Data with buffer reuse must not change its length */
+			return -EINVAL;
 		}
 	} else if (monhdr->mon_function != MONWRITE_STOP_INTERVAL) {
 		if (mon_buf_count >= mon_max_bufs)

base-commit: f31c00c377ccf07c85442712f7c940a855cb3371
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-23 17:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-23 17:44 [PATCH v2] s390/monwriter: Reject buffer reuse with different data length Gerald Schaefer
2026-06-23 17:55 ` sashiko-bot

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.