Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da90fa8f authored by Domen Puncer's avatar Domen Puncer Committed by Linus Torvalds
Browse files

spi/spidev: check message size before copying



Message size needs to be checked before copying, or bad things could
happen.

Signed-off-by: default avatarDomen Puncer <domen.puncer@telargo.com>
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b7add02d
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -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;