Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2567167yba; Fri, 10 May 2019 14:06:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwu5YeRNBK7XhcZf3c0oPLPLAw75Ea1uBvwYbUalA5Wyp0Y9uklMAc0A69MGCBVQT/mF8P8 X-Received: by 2002:a17:902:7d96:: with SMTP id a22mr15798405plm.338.1557522403761; Fri, 10 May 2019 14:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557522403; cv=none; d=google.com; s=arc-20160816; b=xUkFjf5fqOvOeQv4dG/0Fm/TyMsHFQcxM7sOl8kIO6HyzqAruPXwERn9mdTzKPUvk4 KBwoB2+OTFaDBj3venOKwc2nFIc9PxHM16ZWB7/ofxme+LC62duB/wyripbMIoTp0+g3 s31MPtRAtLnM44ktK7RsCN4/8eTQYpjLo2dwT7pkN23jaZMTFGOUOHJAwjxLQpg9mn9G HMwxnLbaD6bSxiEC6d5Sgzk3R/s7rUsZiZ8x+aI6hv0WThxx32WKf8/xV1ISp3lePAog nH29WwK6hT/v0IUfYbxC780U6w2CyDm08MQUT3TQv0FxGOw8373+DWWWMihGPJWE3QZO MgLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Jf3Pm2zDnOWtkQJIjcun0b5bQQ/YocTgtQI3kHh8yL8=; b=nfuPd7t6MxKyHvWiTgiUhVDJ8NEBX4B0AyuyO30BBV+FewjXBfEqZqW2wMKpNry9sq uZO77BO1jAGHIHpo8jfsfFGinx/9CSujTaotLeTxP/Vr7K2rj06UtGy4fcuYx2+diDsZ ryjGL87fHUEyoKQOEBEOGqAwdmZlwOB05TsxHQKY8qVsHgzcA1/ZmAAeIay+4ZJWE+cd jZKuZauTdnpsE+YpVsRuiMs11Pqb9O3edHljaiSSvrVNMtMDL57SRjktBpfXKRLA4NmA K164MUKBUFzilFG/HREER0KB0Hdzf8T//LDF+op5qxmBfLHBxXAQ48ZI8YszmUYND9Kt x/mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=GhV0V2JA; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m34si8835087pgb.324.2019.05.10.14.06.27; Fri, 10 May 2019 14:06:43 -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=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=GhV0V2JA; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728133AbfEJVEM (ORCPT + 99 others); Fri, 10 May 2019 17:04:12 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:34170 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727677AbfEJVEM (ORCPT ); Fri, 10 May 2019 17:04:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Jf3Pm2zDnOWtkQJIjcun0b5bQQ/YocTgtQI3kHh8yL8=; b=GhV0V2JAEAawViKkY2SVXycQp 58sa/lOsnxvAUOPJJLwRr/I8dd7Ihx7veCwvg8HSVDid0w1bxTWQxO9ld3u9kJ4TeLvjT5STWzKgh JwdJuf6ZyMdgYq3BlFo1cjdTTsaDxzbnEhsX6f4kFkqCb5F2kXmWT+d02TYv8vGzLzn3OuPPvFz05 euU2PhPA1MsdnyG7/1nULM/rmfE6P05SIzOuX7te0snM7apPxN9SeZaN6wsBVbWT4SToHKYlp+Y6y YStPU+T41v/E6t8AtAKkX2b9TZ/RlMoFwsAQ36hnJF5BwGPmpLYsu8p9GXJvKtC7PpQWRPLU7e/y1 uOten5YrA==; Received: from shell.armlinux.org.uk ([2001:4d48:ad52:3201:5054:ff:fe00:4ec]:55748) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hPCgZ-0007uW-EE; Fri, 10 May 2019 22:04:07 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.89) (envelope-from ) id 1hPCgX-0004lU-SF; Fri, 10 May 2019 22:04:05 +0100 Date: Fri, 10 May 2019 22:04:05 +0100 From: Russell King - ARM Linux admin To: Vicente Bergas Cc: Serge Semin , Andrew Lunn , Florian Fainelli , Heiner Kallweit , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: net: phy: realtek: regression, kernel null pointer dereference Message-ID: <20190510210405.tehgan2s5rhimihc@shell.armlinux.org.uk> References: <16f75ff4-e3e3-4d96-b084-e772e3ce1c2b@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <16f75ff4-e3e3-4d96-b084-e772e3ce1c2b@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 10, 2019 at 05:05:13PM +0200, Vicente Bergas wrote: > Hello, > there is a regression on linux v5.1-9573-gb970afcfcabd with a kernel null > pointer dereference. > The issue is the commit f81dadbcf7fd067baf184b63c179fc392bdb226e > net: phy: realtek: Add rtl8211e rx/tx delays config > which uncovered a bug in phy-core when attempting to call > phydev->drv->read_page > which can be null. > The patch to drivers/net/phy/phy-core.c below fixes the kernel null pointer > dereference. After applying the patch, there is still no network. I have > also tested the patch to drivers/net/phy/realtek.c, but no success. The > system hangs forever while initializing eth0. You're not supposed to call these functions unless you provide the page read/write page functions. The fact that this code has crept in shows that the patch adding the call to phy_select_page() in the realtek driver was patently never tested, which, IMHO is bad software engineering practice. No, it's not even engineering practice, it's an untested hack. I don't see any point in adding run-time checks - that will only add additional code, and we lose the backtrace. The resulting oops from trying to use these will give a backtrace and show exactly where the problem is, including which driver is at fault. The answer is... fix the driver to provide the required functions before attempting to use an interface that requires said functions! > > Any suggestions? > > Regards, > Vicen?. > > --- a/drivers/net/phy/phy-core.c > +++ b/drivers/net/phy/phy-core.c > @@ -648,11 +648,17 @@ > > static int __phy_read_page(struct phy_device *phydev) > { > + if (!phydev->drv->read_page) > + return -EOPNOTSUPP; > + > return phydev->drv->read_page(phydev); > } > > static int __phy_write_page(struct phy_device *phydev, int page) > { > + if (!phydev->drv->write_page) > + return -EOPNOTSUPP; > + > return phydev->drv->write_page(phydev, page); > } > --- a/drivers/net/phy/realtek.c > +++ b/drivers/net/phy/realtek.c > @@ -214,8 +214,10 @@ > * for details). > */ > oldpage = phy_select_page(phydev, 0x7); > - if (oldpage < 0) > - goto err_restore_page; > + if (oldpage < 0) { > + dev_warn(&phydev->mdio.dev, "Unable to set rgmii delays\n"); > + return 0; > + } > > ret = phy_write(phydev, RTL821x_EXT_PAGE_SELECT, 0xa4); > if (ret) > > -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up