i2c: at91: add bound checking on SMBus block length bytes
authorMarek Roszko <mark.roszko@gmail.com>
Thu, 21 Aug 2014 01:39:41 +0000 (21:39 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 5 Oct 2014 21:52:11 +0000 (14:52 -0700)
commit383e2104c699ea08738da2770c9383bdfaee58ac
treed4841db3c49b1ad53fb7ac8e35f7c3fc592502f7
parent0724c59589da36ee80b8983305106fdcc6a0e6a2
i2c: at91: add bound checking on SMBus block length bytes

commit 75b81f339c6af43f6f4a1b3eabe0603321dade65 upstream.

The driver was not bound checking the received length byte to ensure it was within the
the buffer size that is allocated for SMBus blocks. This resulted in buffer overflows
whenever an invalid length byte was received.
It also failed to ensure the length byte was not zero. If it received zero, it would end up
in an infinite loop as the at91_twi_read_next_byte function returned immediately without
allowing RHR to be read to clear the RXRDY interrupt.

Tested agaisnt a SMBus compliant battery.

Signed-off-by: Marek Roszko <mark.roszko@gmail.com>
Acked-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/i2c/busses/i2c-at91.c