Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2874961pxu; Sat, 19 Dec 2020 05:02:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUFiKa+d1+KtUcEfcVJvIP4ZVV3FjyNEn6O2sYnPMQ0nWT+x9DR01TVoOh+XTWTe6/42EG X-Received: by 2002:a17:906:4a4f:: with SMTP id a15mr8371790ejv.541.1608382925594; Sat, 19 Dec 2020 05:02:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608382925; cv=none; d=google.com; s=arc-20160816; b=KduICuLcUVAMQhCJx1tzgsXvJbKdOHgS5/YAY6DGvSy56w2Vh/AsFlkinYV2T9FGUE zwhjyq1hYlYefWxRu/9syB6cQbP+ga8RcaRxtGp159nXpdIMqZyiNWSGPZ9uFmV6pvmm qHjEpmQK9QdojOpB5S97G6jWAG7YfpHvivfyMD7Z0Jx6wg4vhrQAaZTglGlD2z1NzLRa NRUz/1YQWKFs5XIWNp9PPmCpmA3AejIZiEntBEDJr6FPrFFIXYVrJhLzSejVqFtJ/a87 SGkwBrWtn2W2UaK9UHW0gVst30Ed9OJ+9HoESOxTz4Q4rlBC6cyHMhQRUCVKNo3rvYUg Ktaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=iBUEMHy35YmirAIOR/9ZcqffhaPj6zr1+U+37Xda5/A=; b=epvnUmwteFqqM0vKU0iBhT4vvGtba13rPcp1TfE5joBxKujv4XO4XZMr1RH8rl0Hzv XhyRSQeULqlIQIddU/qYwvRx59tKpFmhRCL4aSYLHwBJDat4DjWKADiBinCklEUu0Xa8 F/mTJWKG6ETpEWguABBj8641vplwO660Cb+877pC6F4DvfRl3P0xsug1wV/bsRWYOn9W 9t7+Lod6uIAWMmdWzSFe+OG/EuYxoscI3uXmfqdhOMo4DBq7Hx606jTAfL4i3Tb5uBV1 bg+QdoGs9s740l1njTXztQVXObXC1YFtyqLdzPZA/tDpv/2RvhBLNCxNjc1+OIVFAw7z NfGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f19si5828813eja.89.2020.12.19.05.01.42; Sat, 19 Dec 2020 05:02:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726713AbgLSM7y (ORCPT + 99 others); Sat, 19 Dec 2020 07:59:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:46080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728164AbgLSM72 (ORCPT ); Sat, 19 Dec 2020 07:59:28 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergej Bauer , Jakub Kicinski Subject: [PATCH 5.9 30/49] lan743x: fix for potential NULL pointer dereference with bare card Date: Sat, 19 Dec 2020 13:58:34 +0100 Message-Id: <20201219125346.153511072@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201219125344.671832095@linuxfoundation.org> References: <20201219125344.671832095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergej Bauer [ Upstream commit e9e13b6adc338be1eb88db87bcb392696144bd02 ] This is the 3rd revision of the patch fix for potential null pointer dereference with lan743x card. The simpliest way to reproduce: boot with bare lan743x and issue "ethtool ethN" commant where ethN is the interface with lan743x card. Example: $ sudo ethtool eth7 dmesg: [ 103.510336] BUG: kernel NULL pointer dereference, address: 0000000000000340 ... [ 103.510836] RIP: 0010:phy_ethtool_get_wol+0x5/0x30 [libphy] ... [ 103.511629] Call Trace: [ 103.511666] lan743x_ethtool_get_wol+0x21/0x40 [lan743x] [ 103.511724] dev_ethtool+0x1507/0x29d0 [ 103.511769] ? avc_has_extended_perms+0x17f/0x440 [ 103.511820] ? tomoyo_init_request_info+0x84/0x90 [ 103.511870] ? tomoyo_path_number_perm+0x68/0x1e0 [ 103.511919] ? tty_insert_flip_string_fixed_flag+0x82/0xe0 [ 103.511973] ? inet_ioctl+0x187/0x1d0 [ 103.512016] dev_ioctl+0xb5/0x560 [ 103.512055] sock_do_ioctl+0xa0/0x140 [ 103.512098] sock_ioctl+0x2cb/0x3c0 [ 103.512139] __x64_sys_ioctl+0x84/0xc0 [ 103.512183] do_syscall_64+0x33/0x80 [ 103.512224] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 103.512274] RIP: 0033:0x7f54a9cba427 ... Previous versions can be found at: v1: initial version https://lkml.org/lkml/2020/10/28/921 v2: do not return from lan743x_ethtool_set_wol if netdev->phydev == NULL, just skip the call of phy_ethtool_set_wol() instead. https://lkml.org/lkml/2020/10/31/380 v3: in function lan743x_ethtool_set_wol: use ternary operator instead of if-else sentence (review by Markus Elfring) return -ENETDOWN insted of -EIO (review by Andrew Lunn) Signed-off-by: Sergej Bauer Link: https://lore.kernel.org/r/20201101223556.16116-1-sbauer@blackbox.su Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/microchip/lan743x_ethtool.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/drivers/net/ethernet/microchip/lan743x_ethtool.c +++ b/drivers/net/ethernet/microchip/lan743x_ethtool.c @@ -780,7 +780,9 @@ static void lan743x_ethtool_get_wol(stru wol->supported = 0; wol->wolopts = 0; - phy_ethtool_get_wol(netdev->phydev, wol); + + if (netdev->phydev) + phy_ethtool_get_wol(netdev->phydev, wol); wol->supported |= WAKE_BCAST | WAKE_UCAST | WAKE_MCAST | WAKE_MAGIC | WAKE_PHY | WAKE_ARP; @@ -809,9 +811,8 @@ static int lan743x_ethtool_set_wol(struc device_set_wakeup_enable(&adapter->pdev->dev, (bool)wol->wolopts); - phy_ethtool_set_wol(netdev->phydev, wol); - - return 0; + return netdev->phydev ? phy_ethtool_set_wol(netdev->phydev, wol) + : -ENETDOWN; } #endif /* CONFIG_PM */