Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4768627ybi; Tue, 30 Jul 2019 07:50:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxyUPq6RV5VUT5XAbbqHJZlhVaNphpYyFkA0Oriuk4HXttcVli2Vjcor5l1IledCfdSMlt5 X-Received: by 2002:a63:fe17:: with SMTP id p23mr11172753pgh.103.1564498233503; Tue, 30 Jul 2019 07:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564498233; cv=none; d=google.com; s=arc-20160816; b=VMZ+T6HwHmOYz2iEcNUJmxkSq7fErzQHBGfbVMd22ECC212cOX/pfjPSCkxmSgrfxB 8fyQpWJ8FOfwfEjmk5EQHZnmB9me5O9IZAfN0Ovky8qAfONj2GwY19v0dL7GxHWwbqR7 pA5BI6a8JUAjkQxnZz+BTrHyLCFYZ8S/kjW/WWopaFTwZQ5almU7t/nwBCAIoQ1xt9bw XdL+thPv1Z5cMywagGLjzRCi2cwcoC1vgMfVELiJzc8SQPWgWND3MOPRpzycnze0BCqB Te11tPZwhpZObtOS8r0cpAiRYKrJ4wK+tDOCA9ndGvgD5B7h8z6zZ9tD5JBSSPKeuP8C Q3+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=C634oO1Vvg8gLOtxb4yBVodzYW9QR1/y80u/tow7L2k=; b=F47l/qYvBUOPhAq8xk1wh+0jyr1GTKzrscSubgUF8ILr8u6/7X8nuI+u/rLBFGf7gx XnJjFdghUq0CTqq/DoEuk3sFomMAIgLX/WQNe2rRPEL5USOW2RHpF0+vJoC7n/RZNVQt +fs56M8RuMlR25481HvMREvLk8SYIoDFtjPziVDNGGBU5Qgq9bJ4M9RrZOfVdHvBRBg/ qL6o0a+XWUGxlBcMmehARUDGcx1AXLurFDw/KGmY/lC8fGkdlXZaFQSNbGaPbH1y0pq7 dLzO6smo4+ok66F89RpIrsHGIE81Di9LY6+/oAvCDWHtD3Ye+knGSdBLFtQWWqYiNGR4 T7Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=b0yfxoot; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m5si26138587plt.167.2019.07.30.07.50.18; Tue, 30 Jul 2019 07:50:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=b0yfxoot; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730852AbfG3IIa (ORCPT + 99 others); Tue, 30 Jul 2019 04:08:30 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44404 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730839AbfG3II3 (ORCPT ); Tue, 30 Jul 2019 04:08:29 -0400 Received: by mail-pg1-f195.google.com with SMTP id i18so29639168pgl.11; Tue, 30 Jul 2019 01:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=C634oO1Vvg8gLOtxb4yBVodzYW9QR1/y80u/tow7L2k=; b=b0yfxootDJhcs8CuJf+eEBmeq1XhR6C/6+5PDI6ssvqskLe8vuVMIBeOawiBL6fZxM 8lpStI2oTnwv+ygzfO7bamEMEOIt8wjKPXXBGzDvTDCuCoI/eGI1oZl+xucyt+iHQHpg 01wxQcZznUzy88gdJN6yu+7mt3dPa6UYdBpq7Zw8VbxKXk3wt2+Tl+1mo4MMrJPiSbEM Kvzf6SOg6c2O8icIX6emc9XGtCyT6widBEKdtNzMjgJ7PC6Q+BhLBNX43lYNzS+ERZ3n T6QRhxlvxavNldq0zemUoBxVOdiC6hEcJUGJRkg7RrhRDZ+AwDTvHOGHx7WGG35SbocC EpDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=C634oO1Vvg8gLOtxb4yBVodzYW9QR1/y80u/tow7L2k=; b=VLc9fRMPiUtkDRcsMayL2KlpQdbRj0kPoWjQOIDbvQwOw5y9njuDoH/LxPcySqLS6N gM6Ge+k+mOUZMQtVFsGHouLquxOIcsLmGr/RCtP2rsvFf5wBFi6+vxKwSbOhnmk6JtHG wj6xq5vxlj2aX4KfO0EDwRa9J32VANQk/Q7C5z5hR1tiydrWvkpz106WFZ1zJxiplFjm bUNAVhXv13FP1BPGTodQkdtq7YRfLJkuPfhaeyy9c1rbH2sUke6EgYDQ5hBIlufQAnej s3QPaxQ9HpEEOlfDXvHO+2L2LqdOvtKG89YHy7DfjcMZ8oeT7bPBblnrj+m/hwwUIWAi isXw== X-Gm-Message-State: APjAAAXF0NhFBbeZMcmty9TqDOmZnWJwd+G9ArK+di1ZyJifY+e/7wyi nvOPQe2VWshlItBM6xX3f+0= X-Received: by 2002:a62:e901:: with SMTP id j1mr41448608pfh.189.1564474108960; Tue, 30 Jul 2019 01:08:28 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id q198sm67159888pfq.155.2019.07.30.01.08.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jul 2019 01:08:28 -0700 (PDT) From: Jia-Ju Bai To: andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com, davem@davemloft.net Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH v2] net: phy: phy_led_triggers: Fix a possible null-pointer dereference in phy_led_trigger_change_speed() Date: Tue, 30 Jul 2019 16:08:13 +0800 Message-Id: <20190730080813.15363-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v2: * Add the organization of the tool's authors. Thank David and Andrew for helpful advice. --- drivers/net/phy/phy_led_triggers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phy_led_triggers.c b/drivers/net/phy/phy_led_triggers.c index b86a4b2116f8..59a94e07e7c5 100644 --- a/drivers/net/phy/phy_led_triggers.c +++ b/drivers/net/phy/phy_led_triggers.c @@ -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; } -- 2.17.0