From: Johan Hovold Date: Wed, 24 Feb 2016 15:11:49 +0000 (+0100) Subject: greybus: uart: add max-payload sanity check X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~654 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=066f950c65c206c1a1a2f72f2c80134177ea3999;p=karo-tx-linux.git greybus: uart: add max-payload sanity check Let's be well behaved and add a sanity check on the maximum greybus payload size to avoid underflow on the calculated buffer size. Reviewed-by: Rui Miguel Silva Signed-off-by: Johan Hovold Reviewed-by: Bryan O'Donoghue Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c index 52cc9d581ca4..60617cb69a5a 100644 --- a/drivers/staging/greybus/uart.c +++ b/drivers/staging/greybus/uart.c @@ -587,6 +587,7 @@ static void gb_tty_exit(void); static int gb_uart_connection_init(struct gb_connection *connection) { + size_t max_payload; struct gb_tty *gb_tty; struct device *tty_dev; int retval; @@ -607,8 +608,13 @@ static int gb_uart_connection_init(struct gb_connection *connection) goto error_alloc; } - gb_tty->buffer_payload_max = - gb_operation_get_payload_size_max(connection) - + max_payload = gb_operation_get_payload_size_max(connection); + if (max_payload < sizeof(struct gb_uart_send_data_request)) { + retval = -EINVAL; + goto error_payload; + } + + gb_tty->buffer_payload_max = max_payload - sizeof(struct gb_uart_send_data_request); gb_tty->buffer = kzalloc(gb_tty->buffer_payload_max, GFP_KERNEL);