Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial167: fix read buffer overflow

Check whether index is within bounds before grabbing the element.

Also, since NR_PORTS is defined ARRAY_SIZE(cy_port), cy_port[NR_PORTS] is
out of bounds as well.

[akpm@linux-foundation.org: cleanup, remove (long) casts]
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Roel Kluin and committed by
Linus Torvalds
f23fc156 196b3167

+2 -5
+2 -5
drivers/char/serial167.c
··· 220 220 return 1; 221 221 } 222 222 223 - if ((long)info < (long)(&cy_port[0]) 224 - || (long)(&cy_port[NR_PORTS]) < (long)info) { 223 + if (info < &cy_port[0] || info >= &cy_port[NR_PORTS]) { 225 224 printk("Warning: cyclades_port out of range for (%s) in %s\n", 226 225 name, routine); 227 226 return 1; ··· 519 520 panic("TxInt on debug port!!!"); 520 521 } 521 522 #endif 522 - 523 - info = &cy_port[channel]; 524 - 525 523 /* validate the port number (as configured and open) */ 526 524 if ((channel < 0) || (NR_PORTS <= channel)) { 527 525 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy); 528 526 base_addr[CyTEOIR] = CyNOTRANS; 529 527 return IRQ_HANDLED; 530 528 } 529 + info = &cy_port[channel]; 531 530 info->last_active = jiffies; 532 531 if (info->tty == 0) { 533 532 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);