Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <domen.puncer@telargo.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Domen Puncer and committed by
Linus Torvalds
da90fa8f b7add02d

+6 -6
+6 -6
drivers/spi/spidev.c
··· 168 168 n--, k_tmp++, u_tmp++) { 169 169 k_tmp->len = u_tmp->len; 170 170 171 + total += k_tmp->len; 172 + if (total > bufsiz) { 173 + status = -EMSGSIZE; 174 + goto done; 175 + } 176 + 171 177 if (u_tmp->rx_buf) { 172 178 k_tmp->rx_buf = buf; 173 179 if (!access_ok(VERIFY_WRITE, u_tmp->rx_buf, u_tmp->len)) ··· 184 178 if (copy_from_user(buf, (const u8 __user *)u_tmp->tx_buf, 185 179 u_tmp->len)) 186 180 goto done; 187 - } 188 - 189 - total += k_tmp->len; 190 - if (total > bufsiz) { 191 - status = -EMSGSIZE; 192 - goto done; 193 181 } 194 182 buf += k_tmp->len; 195 183