Skip to content

Commit

Permalink
spi_mpc83xx: reject invalid transfer sizes
Browse files Browse the repository at this point in the history
Error out on transfer length != multiple of bytes per word with -EINVAL.
Fixes a buffer overrun crash if length < bytes per word.

Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
Acked-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
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>
  • Loading branch information
Peter Korsgaard authored and Linus Torvalds committed Sep 13, 2008
1 parent 53604db commit aa77d96
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions drivers/spi/spi_mpc83xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,20 @@ static int mpc83xx_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
if (t->bits_per_word)
bits_per_word = t->bits_per_word;
len = t->len;
if (bits_per_word > 8)
if (bits_per_word > 8) {
/* invalid length? */
if (len & 1)
return -EINVAL;
len /= 2;
if (bits_per_word > 16)
}
if (bits_per_word > 16) {
/* invalid length? */
if (len & 1)
return -EINVAL;
len /= 2;
}
mpc83xx_spi->count = len;

INIT_COMPLETION(mpc83xx_spi->done);

/* enable rx ints */
Expand Down

0 comments on commit aa77d96

Please sign in to comment.