]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tty: hvc_iucv: fix off-by-one in number of supported devices
authorRandy Dunlap <rdunlap@infradead.org>
Fri, 30 Jan 2026 07:29:37 +0000 (23:29 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Mar 2026 14:05:32 +0000 (15:05 +0100)
MAX_HVC_IUCV_LINES == HVC_ALLOC_TTY_ADAPTERS == 8.
This is the number of entries in:
  static struct hvc_iucv_private *hvc_iucv_table[MAX_HVC_IUCV_LINES];

Sometimes hvc_iucv_table[] is limited by:
(a) if (num > hvc_iucv_devices) // for error detection
or
(b) for (i = 0; i < hvc_iucv_devices; i++) // in 2 places
(so these 2 don't agree; second one appears to be correct to me.)

hvc_iucv_devices can be 0..8. This is a counter.
(c) if (hvc_iucv_devices > MAX_HVC_IUCV_LINES)

If hvc_iucv_devices == 8, (a) allows the code to access hvc_iucv_table[8].
Oops.

Fixes: 44a01d5ba8a4 ("[S390] s390/hvc_console: z/VM IUCV hypervisor console support")
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Link: https://patch.msgid.link/20260130072939.1535869-1-rdunlap@infradead.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/hvc/hvc_iucv.c

index 1dcdb9e99bd8a6c28528d00a4b811ed133386298..37db8a3e5158e6a57404d0af3d359c94b12d8db1 100644 (file)
@@ -130,7 +130,7 @@ static struct iucv_handler hvc_iucv_handler = {
  */
 static struct hvc_iucv_private *hvc_iucv_get_private(uint32_t num)
 {
-       if (num > hvc_iucv_devices)
+       if (num >= hvc_iucv_devices)
                return NULL;
        return hvc_iucv_table[num];
 }