diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2015-03-09 14:05:00 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-03-26 17:21:08 -0400 |
commit | 509cb7dc07cc03c28c7995a9213a605c04675a58 (patch) | |
tree | ed7b191357a6f1424d84a2daf1f0429db63b9c62 /drivers/tty/serial | |
parent | 72a33aad476f9d4b1210dbf434f53eeea84909ab (diff) |
serial: 8250: Validate reg addr for Au1x00/RT288x i/o accessors
Au1x00/RT2800+ hardware has an alternate register layout which is
remapped with lookup tables by the au_serial_in()/out() i/o accessors.
However, the h/w does not support the complete 8250 register set, and
accesses to unmapped registers cause out-of-bounds lookups. Further,
because the lookup tables are defined by designated initializers, the
tables may contain unmapped entries (although the current tables do not).
Declare fixed-size lookup tables with contiguous initialization for
the complete 8250 register map; unmapped registers are initialized to -1.
Validate the register index (ie., 'offset') is in the range [0, table size).
Return fixed value for unmapped register reads and ignore unmapped register
writes.
Reported-by: Mason <slash.tmp@free.fr>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Tested-by: Mans Rullgard <mans@mansr.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/serial')
-rw-r--r-- | drivers/tty/serial/8250/8250_core.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index b9f452fcb1a5..0a8f11b69e68 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c | |||
@@ -358,34 +358,46 @@ static void default_serial_dl_write(struct uart_8250_port *up, int value) | |||
358 | #if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X) | 358 | #if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X) |
359 | 359 | ||
360 | /* Au1x00/RT288x UART hardware has a weird register layout */ | 360 | /* Au1x00/RT288x UART hardware has a weird register layout */ |
361 | static const u8 au_io_in_map[] = { | 361 | static const s8 au_io_in_map[8] = { |
362 | [UART_RX] = 0, | 362 | 0, /* UART_RX */ |
363 | [UART_IER] = 2, | 363 | 2, /* UART_IER */ |
364 | [UART_IIR] = 3, | 364 | 3, /* UART_IIR */ |
365 | [UART_LCR] = 5, | 365 | 5, /* UART_LCR */ |
366 | [UART_MCR] = 6, | 366 | 6, /* UART_MCR */ |
367 | [UART_LSR] = 7, | 367 | 7, /* UART_LSR */ |
368 | [UART_MSR] = 8, | 368 | 8, /* UART_MSR */ |
369 | -1, /* UART_SCR (unmapped) */ | ||
369 | }; | 370 | }; |
370 | 371 | ||
371 | static const u8 au_io_out_map[] = { | 372 | static const s8 au_io_out_map[8] = { |
372 | [UART_TX] = 1, | 373 | 1, /* UART_TX */ |
373 | [UART_IER] = 2, | 374 | 2, /* UART_IER */ |
374 | [UART_FCR] = 4, | 375 | 4, /* UART_FCR */ |
375 | [UART_LCR] = 5, | 376 | 5, /* UART_LCR */ |
376 | [UART_MCR] = 6, | 377 | 6, /* UART_MCR */ |
378 | -1, /* UART_LSR (unmapped) */ | ||
379 | -1, /* UART_MSR (unmapped) */ | ||
380 | -1, /* UART_SCR (unmapped) */ | ||
377 | }; | 381 | }; |
378 | 382 | ||
379 | static unsigned int au_serial_in(struct uart_port *p, int offset) | 383 | static unsigned int au_serial_in(struct uart_port *p, int offset) |
380 | { | 384 | { |
381 | offset = au_io_in_map[offset] << p->regshift; | 385 | if (offset >= ARRAY_SIZE(au_io_in_map)) |
382 | return __raw_readl(p->membase + offset); | 386 | return UINT_MAX; |
387 | offset = au_io_in_map[offset]; | ||
388 | if (offset < 0) | ||
389 | return UINT_MAX; | ||
390 | return __raw_readl(p->membase + (offset << p->regshift)); | ||
383 | } | 391 | } |
384 | 392 | ||
385 | static void au_serial_out(struct uart_port *p, int offset, int value) | 393 | static void au_serial_out(struct uart_port *p, int offset, int value) |
386 | { | 394 | { |
387 | offset = au_io_out_map[offset] << p->regshift; | 395 | if (offset >= ARRAY_SIZE(au_io_out_map)) |
388 | __raw_writel(value, p->membase + offset); | 396 | return; |
397 | offset = au_io_out_map[offset]; | ||
398 | if (offset < 0) | ||
399 | return; | ||
400 | __raw_writel(value, p->membase + (offset << p->regshift)); | ||
389 | } | 401 | } |
390 | 402 | ||
391 | /* Au1x00 haven't got a standard divisor latch */ | 403 | /* Au1x00 haven't got a standard divisor latch */ |