diff options
author | Irina Tirdea <irina.tirdea@intel.com> | 2015-04-13 11:40:50 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2015-04-26 14:40:53 -0400 |
commit | 2a4d20322d1c619ae2f07378d5b360e85f562c98 (patch) | |
tree | ef6f854ff2e9e79ad4c9e1c6399fe1e4f6f36db2 /drivers/iio/accel/mma9551_core.c | |
parent | cd62322a9767f9a0bcf855123c478187e38a10f4 (diff) |
iio: accel: mma9551_core: prevent buffer overrun
The mma9551 functions that read/write word arrays from the
device have a limit for the buffer size given by the device
specifications.
Check that the requested buffer length is within required limits
when transferring word arrays. This will prevent buffer overrun
in the mma9551_read/write_*_words functions and also in the
mma9551_transfer call when writing into the MBOX response/request
structure.
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Reported-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/accel/mma9551_core.c')
-rw-r--r-- | drivers/iio/accel/mma9551_core.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/drivers/iio/accel/mma9551_core.c b/drivers/iio/accel/mma9551_core.c index 7f55a6d7cd03..c6d5a3a40b60 100644 --- a/drivers/iio/accel/mma9551_core.c +++ b/drivers/iio/accel/mma9551_core.c | |||
@@ -389,7 +389,12 @@ int mma9551_read_config_words(struct i2c_client *client, u8 app_id, | |||
389 | { | 389 | { |
390 | int ret, i; | 390 | int ret, i; |
391 | int len_words = len / sizeof(u16); | 391 | int len_words = len / sizeof(u16); |
392 | __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS]; | 392 | __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2]; |
393 | |||
394 | if (len_words > ARRAY_SIZE(be_buf)) { | ||
395 | dev_err(&client->dev, "Invalid buffer size %d\n", len); | ||
396 | return -EINVAL; | ||
397 | } | ||
393 | 398 | ||
394 | ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG, | 399 | ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG, |
395 | reg, NULL, 0, (u8 *) be_buf, len); | 400 | reg, NULL, 0, (u8 *) be_buf, len); |
@@ -424,7 +429,12 @@ int mma9551_read_status_words(struct i2c_client *client, u8 app_id, | |||
424 | { | 429 | { |
425 | int ret, i; | 430 | int ret, i; |
426 | int len_words = len / sizeof(u16); | 431 | int len_words = len / sizeof(u16); |
427 | __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS]; | 432 | __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2]; |
433 | |||
434 | if (len_words > ARRAY_SIZE(be_buf)) { | ||
435 | dev_err(&client->dev, "Invalid buffer size %d\n", len); | ||
436 | return -EINVAL; | ||
437 | } | ||
428 | 438 | ||
429 | ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS, | 439 | ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS, |
430 | reg, NULL, 0, (u8 *) be_buf, len); | 440 | reg, NULL, 0, (u8 *) be_buf, len); |
@@ -459,7 +469,12 @@ int mma9551_write_config_words(struct i2c_client *client, u8 app_id, | |||
459 | { | 469 | { |
460 | int i; | 470 | int i; |
461 | int len_words = len / sizeof(u16); | 471 | int len_words = len / sizeof(u16); |
462 | __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS]; | 472 | __be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2]; |
473 | |||
474 | if (len_words > ARRAY_SIZE(be_buf)) { | ||
475 | dev_err(&client->dev, "Invalid buffer size %d\n", len); | ||
476 | return -EINVAL; | ||
477 | } | ||
463 | 478 | ||
464 | for (i = 0; i < len_words; i++) | 479 | for (i = 0; i < len_words; i++) |
465 | be_buf[i] = cpu_to_be16(buf[i]); | 480 | be_buf[i] = cpu_to_be16(buf[i]); |