Skip to content

Commit

Permalink
net: phy: phy_led_triggers: Fix a possible null-pointer dereference i…
Browse files Browse the repository at this point in the history
…n phy_led_trigger_change_speed()

In phy_led_trigger_change_speed(), there is an if statement on line 48
to check whether phy->last_triggered is NULL:
    if (!phy->last_triggered)

When phy->last_triggered is NULL, it is used on line 52:
    led_trigger_event(&phy->last_triggered->trigger, LED_OFF);

Thus, a possible null-pointer dereference may occur.

To fix this bug, led_trigger_event(&phy->last_triggered->trigger,
LED_OFF) is called when phy->last_triggered is not NULL.

This bug is found by a static analysis tool STCheck written by
the OSLAB group in Tsinghua University.

Signed-off-by: Jia-Ju Bai <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
XidianGeneral authored and davem330 committed Jul 31, 2019
1 parent e29903c commit 271da13
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/net/phy/phy_led_triggers.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ void phy_led_trigger_change_speed(struct phy_device *phy)
if (!phy->last_triggered)
led_trigger_event(&phy->led_link_trigger->trigger,
LED_FULL);
else
led_trigger_event(&phy->last_triggered->trigger, LED_OFF);

led_trigger_event(&phy->last_triggered->trigger, LED_OFF);
led_trigger_event(&plt->trigger, LED_FULL);
phy->last_triggered = plt;
}
Expand Down

0 comments on commit 271da13

Please sign in to comment.