lkml.org 
[lkml]   [2018]   [Apr]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [v2 1/1] i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr()
From
Date
On 19.04.2018 16:49, Uwe Kleine-König wrote:
> On Thu, Apr 19, 2018 at 03:29:22PM +0300, Alexander Popov wrote:
>> i2cdev_ioctl_rdwr() allocates i2c_msg.buf using memdup_user(), which
>> returns ZERO_SIZE_PTR if i2c_msg.len is zero.
>>
>> Currently i2cdev_ioctl_rdwr() always dereferences the buf pointer in case
>> of I2C_M_RD | I2C_M_RECV_LEN transfer. That causes a kernel oops in
>> case of zero len.
>>
>> Let's check the len against zero before dereferencing buf pointer.
>>
>> This issue was triggered by syzkaller.
>>
>> Signed-off-by: Alexander Popov <alex.popov@linux.com>
>> ---
>> drivers/i2c/i2c-dev.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
>> index 036a03f..5790bc8 100644
>> --- a/drivers/i2c/i2c-dev.c
>> +++ b/drivers/i2c/i2c-dev.c
>> @@ -280,6 +280,7 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,
>> */
>> if (msgs[i].flags & I2C_M_RECV_LEN) {
>> if (!(msgs[i].flags & I2C_M_RD) ||
>> + !msgs[i].len ||
>
> I'd prefer
>
> msgs[i].len > 0

Excuse me, it will be wrong. We stop if len is 0 to avoid the following
ZERO_SIZE_PTR dereference.

> here instead of
>
> !msgs[i].len

I can change it to "msgs[i].len == 0". But is it really important?

I've carefully tested the current version with the original repro. It works correct.

> because I can parse that more easily. Semantically the patch is fine and
> can have my
>
> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>
>> msgs[i].buf[0] < 1 ||
>> msgs[i].len < msgs[i].buf[0] +
>> I2C_SMBUS_BLOCK_MAX) {

Best regards,
Alexander

\
 
 \ /
  Last update: 2018-04-19 19:02    [W:0.063 / U:0.540 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site