Skip to content

Commit 8949370

Browse files
dtorgregkh
authored andcommitted
Input: leds - fix out of bound access
commit 6bd6ae6 upstream. UI_SET_LEDBIT ioctl() causes the following KASAN splat when used with led > LED_CHARGING: [ 1274.663418] BUG: KASAN: slab-out-of-bounds in input_leds_connect+0x611/0x730 [input_leds] [ 1274.663426] Write of size 8 at addr ffff88003377b2c0 by task ckb-next-daemon/5128 This happens because we were writing to the led structure before making sure that it exists. Reported-by: Tasos Sahanidis <tasos@tasossah.com> Tested-by: Tasos Sahanidis <tasos@tasossah.com> Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2c698f7 commit 8949370

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/input/input-leds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static int input_leds_connect(struct input_handler *handler,
8888
const struct input_device_id *id)
8989
{
9090
struct input_leds *leds;
91+
struct input_led *led;
9192
unsigned int num_leds;
9293
unsigned int led_code;
9394
int led_no;
@@ -119,14 +120,13 @@ static int input_leds_connect(struct input_handler *handler,
119120

120121
led_no = 0;
121122
for_each_set_bit(led_code, dev->ledbit, LED_CNT) {
122-
struct input_led *led = &leds->leds[led_no];
123+
if (!input_led_info[led_code].name)
124+
continue;
123125

126+
led = &leds->leds[led_no];
124127
led->handle = &leds->handle;
125128
led->code = led_code;
126129

127-
if (!input_led_info[led_code].name)
128-
continue;
129-
130130
led->cdev.name = kasprintf(GFP_KERNEL, "%s::%s",
131131
dev_name(&dev->dev),
132132
input_led_info[led_code].name);

0 commit comments

Comments
 (0)