Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4200582pxu; Mon, 12 Oct 2020 12:05:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU2rOXEnGur40RlRyWo2mlhovDcKr6fHUOsc+nbHg/79zu7Q7jWH2PGHNiAtpw8Udy0wnb X-Received: by 2002:a17:906:5e49:: with SMTP id b9mr29153706eju.436.1602529510097; Mon, 12 Oct 2020 12:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602529510; cv=none; d=google.com; s=arc-20160816; b=wk9yQo7yqMNfpyVPLlu1nzP0PvkMQknERyMKMV+Kv80/xox5HB8pumJbS1yievxxfJ xLiQsE7mdMC0DqiIep8Lq2hQLqXiMfnZXckrOtiXT3j0YyXC7l89WK80XrFEHsvveeQa j09CmEogGxQ2XMSgl+sJw9UmmNM0BX7UK5RSN7I0gig7JF/SLwy4WZLRWVL2SZz/ay21 tau5BvPCCNQ+TaANVUXKQ5Cdx9G8kFJU0NUi6l9yVVaJtaIS/lXDm7Xfriigt+6jFxJ1 0ig0g5dy8rbP56naK5oXXvAZ4CvBVMsPnRBT6stNv2J4TK8JMclmop8FZja2lVMGP/AI V0Qw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=J8wxJkzSyHtEY3CI5zxDysqHbXdjW6W8dwDMsTiu8nY=; b=zNR2Y8n3S1ImeENJtC96HSkv6Qyi5XCSbcVnEZYD9DioPH4WiY3CVes43F0JAJ7gp0 z77zf4Y72ZizLhWPqeoOgHCBBtvzm5Rnw7bbV/2O9A+pV577PoCQOYqLEaq+4eK6uS2Z ngM21LEwwZgtymjNIIigM7f0ur8uPSHo+RHX/bq6Zr6wj6ZiLooOt/K75jel8J6K9d4h isnQEtNJIbEaUzbPizRR+FLGqUf6lOXNgjlDma06NaU2B8rctu8XgO7VEfdq3TCluxN7 c9HpnKwkVlU/GCj/mS6cAWWCRmHjPavQl+a1SQYfcqpVEyKr60FaD9FFMmza4ALmnFJp tLUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gmu1z8QP; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m23si12551979ejo.333.2020.10.12.12.04.32; Mon, 12 Oct 2020 12:05:10 -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; dkim=pass header.i=@kernel.org header.s=default header.b=gmu1z8QP; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390172AbgJLTDK (ORCPT + 99 others); Mon, 12 Oct 2020 15:03:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:52404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389111AbgJLTDE (ORCPT ); Mon, 12 Oct 2020 15:03:04 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 499DD20BED; Mon, 12 Oct 2020 19:03:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602529383; bh=VoG2Q+uPn83jjMZIAFrjMusN+OEJ9rV2uXrL2GMwtvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gmu1z8QPCXfG/V//yRJ+vxCqlYMLXkFmquYFoQ2t4bSAo9PLxMn1LBzii/XfXvlLu bJYoR+23wEuncmp8sUUO9uxyg0ivfpKd9DE9oAbUsPdlhoc/Jp2A8Jh4rR/VijWRYS ojQIdb9hU2rbOpiNsDxZQBdBusQkXiCr6J9SZFHk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anant Thazhemadam , syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com, Petko Manolov , "David S . Miller" , Sasha Levin , linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.8 18/24] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails Date: Mon, 12 Oct 2020 15:02:33 -0400 Message-Id: <20201012190239.3279198-18-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201012190239.3279198-1-sashal@kernel.org> References: <20201012190239.3279198-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reported-by: syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com Tested-by: syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com Acked-by: Petko Manolov Signed-off-by: Anant Thazhemadam Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/rtl8150.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c index e7c630d375899..63a4da0b2d6dd 100644 --- 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)) { + 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) -- 2.25.1