Skip to content

Commit 7127d24

Browse files
Jiri Slabygregkh
authored andcommitted
tty: rocket, avoid OOB access
init_r_port can access pc104 array out of bounds. pc104 is a 2D array defined to have 4 members. Each member has 8 submembers. * we can have more than 4 (PCI) boards, i.e. [board] can be OOB * line is not modulo-ed by anything, so the first line on the second board can be 4, on the 3rd 12 or alike (depending on previously registered boards). It's zero only on the first line of the first board. So even [line] can be OOB, quite soon (with the 2nd registered board already). This code is broken for ages, so just avoid the OOB accesses and don't try to fix it as we would need to find out the correct line number. Use the default: RS232, if we are out. Generally, if anyone needs to set the interface types, a module parameter is past the last thing that should be used for this purpose. The parameters' description says it's for ISA cards anyway. Signed-off-by: Jiri Slaby <[email protected]> Cc: stable <[email protected]> Fixes: 1da177e ("Linux-2.6.12-rc2") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 580d952 commit 7127d24

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

drivers/tty/rocket.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -632,18 +632,21 @@ init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
632632
tty_port_init(&info->port);
633633
info->port.ops = &rocket_port_ops;
634634
info->flags &= ~ROCKET_MODE_MASK;
635-
switch (pc104[board][line]) {
636-
case 422:
637-
info->flags |= ROCKET_MODE_RS422;
638-
break;
639-
case 485:
640-
info->flags |= ROCKET_MODE_RS485;
641-
break;
642-
case 232:
643-
default:
635+
if (board < ARRAY_SIZE(pc104) && line < ARRAY_SIZE(pc104_1))
636+
switch (pc104[board][line]) {
637+
case 422:
638+
info->flags |= ROCKET_MODE_RS422;
639+
break;
640+
case 485:
641+
info->flags |= ROCKET_MODE_RS485;
642+
break;
643+
case 232:
644+
default:
645+
info->flags |= ROCKET_MODE_RS232;
646+
break;
647+
}
648+
else
644649
info->flags |= ROCKET_MODE_RS232;
645-
break;
646-
}
647650

648651
info->intmask = RXF_TRIG | TXFIFO_MT | SRC_INT | DELTA_CD | DELTA_CTS | DELTA_DSR;
649652
if (sInitChan(ctlp, &info->channel, aiop, chan) == 0) {

0 commit comments

Comments
 (0)