From: Domen Puncer Date: Wed, 23 May 2007 20:57:39 +0000 (-0700) Subject: spi/spidev: check message size before copying X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=da90fa8ff671a0139772ec3b3e82c06077e82122;p=GitHub%2FLineageOS%2Fandroid_kernel_samsung_universal7580.git spi/spidev: check message size before copying Message size needs to be checked before copying, or bad things could happen. Signed-off-by: Domen Puncer Signed-off-by: David Brownell Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index 225d6b2f82d..bcfef04f547 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -168,6 +168,12 @@ static int spidev_message(struct spidev_data *spidev, n--, k_tmp++, u_tmp++) { k_tmp->len = u_tmp->len; + total += k_tmp->len; + if (total > bufsiz) { + status = -EMSGSIZE; + goto done; + } + if (u_tmp->rx_buf) { k_tmp->rx_buf = buf; if (!access_ok(VERIFY_WRITE, u_tmp->rx_buf, u_tmp->len)) @@ -179,12 +185,6 @@ static int spidev_message(struct spidev_data *spidev, u_tmp->len)) goto done; } - - total += k_tmp->len; - if (total > bufsiz) { - status = -EMSGSIZE; - goto done; - } buf += k_tmp->len; k_tmp->cs_change = !!u_tmp->cs_change;