Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3342027imu; Wed, 7 Nov 2018 08:51:39 -0800 (PST) X-Google-Smtp-Source: AJdET5cBaUGD4dtTEKYhDFujycNIS6K7SQsOhxKKLbEbD+NtM+ybR4q1XF0tdonzU1THI8La8hap X-Received: by 2002:a62:1f13:: with SMTP id f19-v6mr960164pff.168.1541609499330; Wed, 07 Nov 2018 08:51:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541609499; cv=none; d=google.com; s=arc-20160816; b=uLZZBxuUYei/kPBqgtTmk72/01CPfZENq8SYBRlg/IPWwdjNvXgEWmUnX7iPsTiEyv 2GIeKhrJ6W5mPlbOhf/XfBn09KNdnNW9MI+wMkXvKjQhe0aZjKMxlnFVfC0F5zT1xX00 0JtNezjggFG6ORIGKg/mut7WPUWrCpFlX8jWoEPQKcVSCTmKPHDJUrwB3bpZNuDaguqK GIluLnZ7gaqSTrMhGdwCC8htHRUeXz04ywA3Wlm+148kIVwMfBKmBs8RByV3fQAjdifX JZb7Rk0nvV4U28QD+51uhHlCqHk78/5bjNJQMN0hf5ML3gzjF2a/BXtImDe21VsG1P6U 3gwg== 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=FH1CRg9zKXdmOnTWJLsZTHhhSYiFD57sq5PuBYc7CFk=; b=SA2wZ3wFqWf5e54UK8RXBtbQVeUe7kECTc8FLrJ+YFjHICjduCn6gNOP2COaamo7MC gPKNwDnt1smr/RJ4PWFwyuliPkycpaDvQPYartZQkLDRZ/e2jKQXCKUgmsuB2XiZTAkn oZLfZM4E6QQr0SqauWT84ecrsOR0mFZUkiqsdqhwhC7VSHKwpoYkPir01uNb9IlESjkK WCnRExX1QR17Yd5dn6j53i+t5RNJ8s2sQuojiGGTYs1ZraejoQYxsouiRWpwG3S18Od2 G1Ku58iDVNWden/IpUxBSHMf3bC17PTNF6lW6jfi1zScCKFZMXc3GsVb3plE1YB1ut2f 2Yfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UzsSTBwG; 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 p3-v6si1101292pff.272.2018.11.07.08.51.24; Wed, 07 Nov 2018 08:51:39 -0800 (PST) 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=UzsSTBwG; 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 S1728100AbeKHCWL (ORCPT + 99 others); Wed, 7 Nov 2018 21:22:11 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:34590 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727699AbeKHCWL (ORCPT ); Wed, 7 Nov 2018 21:22:11 -0500 Received: by mail-wm1-f67.google.com with SMTP id f1-v6so11740073wmg.1; Wed, 07 Nov 2018 08:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=FH1CRg9zKXdmOnTWJLsZTHhhSYiFD57sq5PuBYc7CFk=; b=UzsSTBwGZrTJUGDxk1awqN5vfVAiIoBgsRRDaIPBLgEtasDu6fhWBDvoZV+L2m7vOv JRi+/N40C5hwRy1wiIvciufvciS8Hqrw3WdJM4YfjPLOARbr0H51nsKYsDttuUuBeu/K HrQViT2pZmi6cVv8UpodzL7xMXuBH0dTk0aqb3xEHhcdlixcD3i+ssZ5TaQ+xvVpwpTQ 1owcd38Y3dTzSKGu/DxA+jTUi19W20vAeYNTr7hKHM0pCSWm0kShgs3JCPGCk2jq8xVo x2iHU0PWCmXioAjjLHvonfobQiuyelgBlEObd73TFoVwf6oeGCxrMT6QgXODXnyNbl2l rXmA== 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=FH1CRg9zKXdmOnTWJLsZTHhhSYiFD57sq5PuBYc7CFk=; b=hbtFumg9dwfUczZgebiLvj/wKHKgGG8IzI5dw+ymBOT4kqcuajQ69GYTUyflL9Jw/A 1U+i0dV7YxPOKvdJJqAadavWg5yFZnFXeI50NIoYsQMQUQu/2bQ3YbRvZGb5Cc+b445G vUMwR/vqe5d8vS7/n/ZUU+cCVEd39172KD7YEHZGI1UmgxWDVuHf4gSJbto6dwjlFDl1 EVjh7k66WtTO/eaGFmtajyci+wfVysQXmQDN5mWelVb2QS27LWCS5N7808WK1c+V/thk pgvaF/0aa/W5zq2/Z7vEvBTJsSza4s+I000OECIqBTi50KWjre5Pb2kWCrA9lrtOk5ch P1jw== X-Gm-Message-State: AGRZ1gJO4iaFF17SSd6VGTsm8GWYTnOvOwRgdZ+dD9kVOd1hevGABRqz e5vayIV4B69o2nd+EbiBPig= X-Received: by 2002:a1c:ee89:: with SMTP id j9-v6mr830950wmi.58.1541609458572; Wed, 07 Nov 2018 08:50:58 -0800 (PST) Received: from gmail.com (net-2-42-72-229.cust.vodafonedsl.it. [2.42.72.229]) by smtp.gmail.com with ESMTPSA id y9-v6sm613127wru.70.2018.11.07.08.50.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 08:50:57 -0800 (PST) From: Paolo Pisati To: Woojung Huh , Microchip Linux Driver Support , netdev@vger.kernel.org, stable@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [stable, netdev 4.4+] lan78xx: make sure RX_ADDRL & RX_ADDRH regs are always up to date Date: Wed, 7 Nov 2018 17:50:57 +0100 Message-Id: <1541609457-28725-1-git-send-email-p.pisati@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [partial backport upstream 760db29bdc97b73ff60b091315ad787b1deb5cf5] Upon invocation, lan78xx_init_mac_address() checks that the mac address present in the RX_ADDRL & RX_ADDRH registers is a valid address, if not, it first tries to read a new address from an external eeprom or the otp area, and in case both read fail (or the address read back is invalid), it randomly generates a new one. Unfortunately, due to the way the above logic is laid out, if both read_eeprom() and read_otp() fail, a new mac address is correctly generated but is never written back to RX_ADDRL & RX_ADDRH, leaving the chip in an incosistent state and with an invalid mac address (e.g. the nic appears to be completely dead, and doesn't receive any packet, etc): lan78xx_init_mac_address() ... if (lan78xx_read_eeprom(addr ...) || lan78xx_read_otp(addr ...)) { if (is_valid_ether_addr(addr) { // nop... } else { random_ether_addr(addr); } // correctly writes back the new address lan78xx_write_reg(RX_ADDRL, addr ...); lan78xx_write_reg(RX_ADDRH, addr ...); } else { // XXX if both eeprom and otp read fail, we land here and skip // XXX the RX_ADDRL & RX_ADDRH update completely random_ether_addr(addr); } This bug went unnoticed because lan78xx_read_otp() was buggy itself and would never fail, up until 4bfc338 "lan78xx: Correctly indicate invalid OTP" fixed it and as a side effect uncovered this bug. 4.18+ is fine, since the bug was implicitly fixed in 760db29 "lan78xx: Read MAC address from DT if present" when the address change logic was reorganized, but it's still present in all stable trees below that: linux-4.4.y, linux-4.9.y, linux-4.14.y, etc up to linux-4.18.y (not included). Signed-off-by: Paolo Pisati --- drivers/net/usb/lan78xx.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 50e2e10a..114dc55 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -1660,13 +1660,6 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev) netif_dbg(dev, ifup, dev->net, "MAC address set to random addr"); } - - addr_lo = addr[0] | (addr[1] << 8) | - (addr[2] << 16) | (addr[3] << 24); - addr_hi = addr[4] | (addr[5] << 8); - - ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo); - ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi); } else { /* generate random MAC */ random_ether_addr(addr); @@ -1674,6 +1667,11 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev) "MAC address set to random addr"); } } + addr_lo = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); + addr_hi = addr[4] | (addr[5] << 8); + + ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo); + ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi); ret = lan78xx_write_reg(dev, MAF_LO(0), addr_lo); ret = lan78xx_write_reg(dev, MAF_HI(0), addr_hi | MAF_HI_VALID_); -- 2.7.4