gpiolib: potential oops on failure path
Subsystems (2)
PATCH 1/1 gpiolib: potential oops on failure path
If anon_inode_getfd() fails then "i" is set to GPIOHANDLES_MAX. It means that we will read beyond the end of the array and dereference an invalid pointer.
drivers/gpio/gpiolib.c +2 -0
@@ -495,6 +495,8 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)return 0 ; out_free_descs: +if (i =GPIOHANDLES_MAX ) + i--;for (; i >=0 ; i--)gpiod_free (lh->descs[i]);kfree (lh->label);
Am 17.06.2016 11:15, schrieb Dan Carpenter:
Quoted 12 lines
If
anon_inode_getfd()fails then "i" is set toGPIOHANDLES_MAX. It means that we will read beyond the end of the array and dereference an invalid pointer.Fixes d7c51b47ac11 ('gpio: userspace ABI for reading/writing GPIO lines')Signed-off-by Dan Carpenter <[email protected]>drivers/gpio/gpiolib.c +0
-0
drivers/gpio/gpiolib.c static int linehandle_create(struct gpio_device *gdev, void __user *ip) · line 502
Quoted 8 lines
drivers/gpio/gpiolib.c +2
-0@@ -495,6 +495,8 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)return 0 ; out_free_descs: +if (i =GPIOHANDLES_MAX ) + i--;for (; i >=0 ; i--)gpiod_free (lh->descs[i]);kfree (lh->label);
Since we have already noticed that programmes are bad at counting backwards is it possible to change the loop into counting up ?
btw: if lh->descs[i] is initialized to NULL it would be more robust just to free everything like:
for(i=0;i< GPIOHANDLES_MAX; i++)
gpiod_free(lh->descs[i]);
just my two cents,
re,
wh
Quoted 11 lines · walter harms
drivers/gpio/gpiolib.c static int linehandle_create(struct gpio_device *gdev, void __user *ip) · line 502
Quoted 6 lines
out_free_descs:drivers/gpio/gpiolib.c +2
-0+if (i =GPIOHANDLES_MAX ) + i--;for (; i >=0 ; i--)gpiod_free (lh->descs[i]);kfree (lh->label);Since we have already noticed that programmes are bad at counting backwards is it possible to change the loop into counting up ?
Quoted 5 lines
btw: if lh->descs[i] is initialized to NULL it would be more robust just to free everything like:
for(i=0;i< GPIOHANDLES_MAX; i++)
gpiod_free(lh->descs[i]);
Depending on the config gpiod_free(NULL) generates a warning. It's possible that it will be generated once with the current code actually but I didn't feel it was worth worrying about that.
Still I wouldn't want to generate 64 warnings.
regards,
dan carpenter
Quoted 13 lines · walter harms
Am 17.06.2016 11:15, schrieb Dan Carpenter:
drivers/gpio/gpiolib.c static int linehandle_create(struct gpio_device *gdev, void __user *ip) · line 502
Quoted 6 lines
out_free_descs:drivers/gpio/gpiolib.c +2
-0+if (i =GPIOHANDLES_MAX ) + i--;for (; i >=0 ; i--)gpiod_free (lh->descs[i]);kfree (lh->label);Since we have already noticed that programmes are bad at counting backwards is it possible to change the loop into counting up ?
Quoted 6 lines
btw: if lh->descs[i] is initialized to NULL it would be more robust just to free everything like:
for(i=0;i< GPIOHANDLES_MAX; i++)
gpiod_free(lh->descs[i]);just my two cents,
The loop looks like that for a reason: i is indexing upwards while grabbing the descriptors, then it rewinds that way to free them if something went wrong during init.
Yours,
Linus Walleij
Quoted 6 lines · Dan Carpenter
If
anon_inode_getfd()fails then "i" is set toGPIOHANDLES_MAX. It means that we will read beyond the end of the array and dereference an invalid pointer.Fixes d7c51b47ac11 ('gpio: userspace ABI for reading/writing GPIO lines')Signed-off-by Dan Carpenter <[email protected]>
Ouch, yeah that happens when you request max number of handles, thanks.
Patch applied.
Yours,
Linus Walleij
Quoted 7 lines · Linus Walleij
Quoted 4 lines · Dan Carpenter
If
anon_inode_getfd()fails then "i" is set toGPIOHANDLES_MAX. It means that we will read beyond the end of the array and dereference an invalid pointer.
Quoted 6 lines
Quoted 2 lines
Fixes d7c51b47ac11 ('gpio: userspace ABI for reading/writing GPIO lines')Signed-off-by Dan Carpenter <[email protected]>Ouch, yeah that happens when you request max number of handles, thanks.
Patch applied.
Ah no, I saw the real problem now. Sending another patch.
Yours,
Linus Walleij