Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4206643pxu; Mon, 12 Oct 2020 12:15:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp65+L42ApLw7sLQVejjibzMg9M+ry11ZseHFsT1kSKlZ3JuM7bB3wrYyZhCaR32Sto6mm X-Received: by 2002:a05:6402:395:: with SMTP id o21mr15821727edv.2.1602530115664; Mon, 12 Oct 2020 12:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602530115; cv=none; d=google.com; s=arc-20160816; b=PpFmqfo4+9XgmtyufDUQDyig9vxS/tgZh+TVFVoVlSPmiEynG8M8f7ZbJnrjAZ2lEp xw854PQwhMg8qEIpuFnFqMxxfI3UG1tNl+W/jpAdD8CuOa2wY2MjljIpc2ZUU+Ep6p8g 2WqUWUanFgPdjW3tCEi2JH+czp4zBpr56BMGzRKcJa2IzblhE0oTGCCvjU3BDjOriMOM vZN9KXDx9C35FWPKd/1LodCHRxF3l9FJkQ8G/DCeBmwNMYjlriyO9XFnH4k/ZjNNrdGS axvpu//Xb77jNZeRucyshTdUwOJfN1M7dVVD4mKlJbLAE3uMbINkJkM00tKwDLvVefwq 82lQ== 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:date:cc:to:from:subject :message-id; bh=dRW2s4+6hlVMKF9G1/7N4uOFAfTE1GCZzhNX8eofSio=; b=UTrzddy8v/F//Lnp1BJ7swCkAMp7k/3lNqJa2akZXGekTueawvinhGk+XWbrG2hWDb mzy28/I/os8v3VLxn/Sl2SAfsVfJvLMBHMrgiUGhEHmlaOhVjawLVKCnVuOuvrYt140w YgwZ6cDrQFsBhGUTtQeCfth0mL75QVP+LhqEcOFrDCkRyOsTIYGawwWoJM3eDweMgRh3 ZeuHJRxPWWznjYZoKZ2TSJtwEcVAAiIc90xuaJMUCKL5kyUpUdCw4nLjqKArkRyzpyVI 6lmpTe5lI9tGz0+CIdk2hazpWgoD5NT+1J081a3ICF9YNzdUPVehgSJzbGlwl19K2QmH Mwbg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c21si12975234edw.472.2020.10.12.12.14.52; Mon, 12 Oct 2020 12:15:15 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391134AbgJLTLX (ORCPT + 99 others); Mon, 12 Oct 2020 15:11:23 -0400 Received: from smtprelay0133.hostedemail.com ([216.40.44.133]:37514 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388013AbgJLTLX (ORCPT ); Mon, 12 Oct 2020 15:11:23 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay01.hostedemail.com (Postfix) with ESMTP id E3DE9100E7B44; Mon, 12 Oct 2020 19:11:20 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:355:379:599:800:960:967:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2525:2560:2563:2682:2685:2828:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4605:5007:7514:7576:7903:9025:9165:10004:10400:10471:10481:10848:11026:11232:11658:11914:12043:12296:12297:12438:12555:12740:12760:12895:13069:13255:13311:13357:13439:13972:14181:14659:14721:19900:21080:21451:21611:21627:21788:21939:21990:30003:30012:30054:30070:30079:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: lamp55_0c0ae3f271fc X-Filterd-Recvd-Size: 2942 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf03.hostedemail.com (Postfix) with ESMTPA; Mon, 12 Oct 2020 19:11:19 +0000 (UTC) Message-ID: Subject: Re: [PATCH AUTOSEL 5.8 18/24] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails From: Joe Perches To: Sasha Levin , linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anant Thazhemadam , syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com, Petko Manolov , "David S . Miller" , linux-usb@vger.kernel.org, netdev@vger.kernel.org Date: Mon, 12 Oct 2020 12:11:18 -0700 In-Reply-To: <20201012190239.3279198-18-sashal@kernel.org> References: <20201012190239.3279198-1-sashal@kernel.org> <20201012190239.3279198-18-sashal@kernel.org> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.4-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2020-10-12 at 15:02 -0400, Sasha Levin wrote: > From: Anant Thazhemadam > > [ Upstream commit f45a4248ea4cc13ed50618ff066849f9587226b2 ] > > When get_registers() fails in set_ethernet_addr(),the uninitialized > value of node_id gets copied over as the address. > So, check the return value of get_registers(). > > If get_registers() executed successfully (i.e., it returns > sizeof(node_id)), copy over the MAC address using ether_addr_copy() > (instead of using memcpy()). > > Else, if get_registers() failed instead, a randomly generated MAC > address is set as the MAC address instead. This autosel is premature. This patch always sets a random MAC. See the follow on patch: https://lkml.org/lkml/2020/10/11/131 To my knowledge, this follow-ob has yet to be applied: > diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c [] > @@ -274,12 +274,20 @@ static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg) > return 1; > } > > -static inline void set_ethernet_addr(rtl8150_t * dev) > +static void set_ethernet_addr(rtl8150_t *dev) > { > - u8 node_id[6]; > + u8 node_id[ETH_ALEN]; > + int ret; > + > + ret = get_registers(dev, IDR, sizeof(node_id), node_id); > > - get_registers(dev, IDR, sizeof(node_id), node_id); > - memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id)); > + if (ret == sizeof(node_id)) { So this needs to use if (!ret) { or if (ret < 0) and reversed code blocks > + ether_addr_copy(dev->netdev->dev_addr, node_id); > + } else { > + eth_hw_addr_random(dev->netdev); > + netdev_notice(dev->netdev, "Assigned a random MAC address: %pM\n", > + dev->netdev->dev_addr); > + } > } > > static int rtl8150_set_mac_address(struct net_device *netdev, void *p)