2011-05-16 14:19:12

by Axel Lin

[permalink] [raw]
Subject: [PATCH RESEND] mfd: Fix off-by-one value range checking for tps65910_i2c_write

If bytes == (TPS65910_MAX_REGISTER + 1), we have a buffer overflow when
doing memcpy(&msg[1], src, bytes).

Signed-off-by: Axel Lin <[email protected]>
Acked-by: Samuel Ortiz <[email protected]>
---
drivers/mfd/tps65910.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index bf649cf..e318248 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -71,7 +71,7 @@ static int tps65910_i2c_write(struct tps65910 *tps65910, u8 reg,
u8 msg[TPS65910_MAX_REGISTER + 1];
int ret;

- if (bytes > (TPS65910_MAX_REGISTER + 1))
+ if (bytes > TPS65910_MAX_REGISTER)
return -EINVAL;

msg[0] = reg;
--
1.7.1



2011-05-16 20:19:15

by Liam Girdwood

[permalink] [raw]
Subject: Re: [PATCH RESEND] mfd: Fix off-by-one value range checking for tps65910_i2c_write

On Mon, 2011-05-16 at 22:19 +0800, Axel Lin wrote:
> If bytes == (TPS65910_MAX_REGISTER + 1), we have a buffer overflow when
> doing memcpy(&msg[1], src, bytes).
>
> Signed-off-by: Axel Lin <[email protected]>
> Acked-by: Samuel Ortiz <[email protected]>
> ---
> drivers/mfd/tps65910.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
> index bf649cf..e318248 100644
> --- a/drivers/mfd/tps65910.c
> +++ b/drivers/mfd/tps65910.c
> @@ -71,7 +71,7 @@ static int tps65910_i2c_write(struct tps65910 *tps65910, u8 reg,
> u8 msg[TPS65910_MAX_REGISTER + 1];
> int ret;
>
> - if (bytes > (TPS65910_MAX_REGISTER + 1))
> + if (bytes > TPS65910_MAX_REGISTER)
> return -EINVAL;
>
> msg[0] = reg;

Applied.