diff options
| author | Peter Korsgaard <jacmet@sunsite.dk> | 2008-09-13 05:33:15 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-09-13 17:41:51 -0400 |
| commit | aa77d96ba94326db4f50d2aa36602824dd03286a (patch) | |
| tree | 4c2daacecb7f707d0ecf8569faf14f01d17a5e1e | |
| parent | 53604dbe1371c3c4458c2d741adbd8cfd8fe8e79 (diff) | |
spi_mpc83xx: reject invalid transfer sizes
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>
| -rw-r--r-- | drivers/spi/spi_mpc83xx.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c index ab7ee445d8b2..ac0e3e4b3c54 100644 --- a/drivers/spi/spi_mpc83xx.c +++ b/drivers/spi/spi_mpc83xx.c | |||
| @@ -312,11 +312,20 @@ static int mpc83xx_spi_bufs(struct spi_device *spi, struct spi_transfer *t) | |||
| 312 | if (t->bits_per_word) | 312 | if (t->bits_per_word) |
| 313 | bits_per_word = t->bits_per_word; | 313 | bits_per_word = t->bits_per_word; |
| 314 | len = t->len; | 314 | len = t->len; |
| 315 | if (bits_per_word > 8) | 315 | if (bits_per_word > 8) { |
| 316 | /* invalid length? */ | ||
| 317 | if (len & 1) | ||
| 318 | return -EINVAL; | ||
| 316 | len /= 2; | 319 | len /= 2; |
| 317 | if (bits_per_word > 16) | 320 | } |
| 321 | if (bits_per_word > 16) { | ||
| 322 | /* invalid length? */ | ||
| 323 | if (len & 1) | ||
| 324 | return -EINVAL; | ||
| 318 | len /= 2; | 325 | len /= 2; |
| 326 | } | ||
| 319 | mpc83xx_spi->count = len; | 327 | mpc83xx_spi->count = len; |
| 328 | |||
| 320 | INIT_COMPLETION(mpc83xx_spi->done); | 329 | INIT_COMPLETION(mpc83xx_spi->done); |
| 321 | 330 | ||
| 322 | /* enable rx ints */ | 331 | /* enable rx ints */ |
