Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4236777iog; Tue, 21 Jun 2022 15:16:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s7g62kzNsCG2TBRBuU9DrbpziAzzsI6MRyRfhSfS7nI5MH1mBLyk1DYgdjjP3hp5Qmz5DH X-Received: by 2002:a17:90a:6b0d:b0:1ec:93e5:c61b with SMTP id v13-20020a17090a6b0d00b001ec93e5c61bmr114924pjj.189.1655849796230; Tue, 21 Jun 2022 15:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655849796; cv=none; d=google.com; s=arc-20160816; b=Wj07CX1x3ZOKvEe/pf4IBPm7KDvxDAWZcqgpoAVPxk1NebNHPtze9ro45v4i+82njh U6K7sJMUBNif/mI6lGYPeOGCFXw6M0oIiDqIDeIeFxRr9T8x0y/O+/mtKgamiXW6R0y0 yt6K0OTvxwfv8RYFcNXyT0hDM1YLHiPUV3lPh87akuSaf4+o4bbS8yNw6jnxlbSz6Y4R B/bVSDQUh+Yogdk/JVTd30DAP1zX4cmJYJlZnH3FrNVIhpb5myS7cbszrAaDkGKjp/DA 0YKXNPURpt0TF2BLfIv8HpXWzyGzhZd5ci7p3Uwpe4aJ83l/xBkje0uqjAliCfJ86t+c YlaQ== 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 :message-id:date:subject:cc:to:dkim-signature:from; bh=wJdtworD2sUsK43Thow1y4cWUzZUUrEGz+3SoqI1Ydw=; b=faN9VJOvo8OnYyfCKUrdnXYlN1oMZ0OWKgEtfF6a3KackEJlG3RjlZso6g2my5C68y 6h42XVsnOXY7KmKvDkBEJPdJjp4LsPNkBmy7L2h1rgVaPMaWlkYJxkxJz4BuYvu8QWPN 098x0CUCOf/h2ts4izEkD+Jm66/E7N2TuonoSIpFqciRFrQSkxch9hLGX/r/Ge9TPq36 gOwbUP4yoSgmMBZAWY1fmKcX9VuDuaghFvoyOnMFnYDvOhuTp1zhEOyinWJF/ZjhUS7B oHAlAWm2PEvSIs5drLqjJI8I5WGGMcqmDrFrMvZgjNOfFGaR7e1rUs9jLrH6czsDV7mR utzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mutex.one header.s=default header.b=KKhS+TmX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a64-20020a639043000000b0040cf2e6f0e7si4250579pge.497.2022.06.21.15.16.24; Tue, 21 Jun 2022 15:16:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mutex.one header.s=default header.b=KKhS+TmX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354837AbiFUVsr (ORCPT + 99 others); Tue, 21 Jun 2022 17:48:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356625AbiFUVsb (ORCPT ); Tue, 21 Jun 2022 17:48:31 -0400 Received: from mail.mutex.one (mail.mutex.one [62.77.152.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1427213D23; Tue, 21 Jun 2022 14:48:29 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.mutex.one (Postfix) with ESMTP id 9D2CD16C007C; Wed, 22 Jun 2022 00:48:27 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at mail.mutex.one Received: from mail.mutex.one ([127.0.0.1]) by localhost (mail.mutex.one [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CfYR0rrq5XjV; Wed, 22 Jun 2022 00:48:27 +0300 (EEST) From: Marian Postevca DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mutex.one; s=default; t=1655848107; bh=fp7Z7WX6CY4w4rd8Kqz3s9RH04oII+EqtX0RxQIS/ow=; h=From:To:Cc:Subject:Date:From; b=KKhS+TmXZ8xtY0mMdR4ApcpUu3yWcGhHtPJ5CKc5ljUmdp3S86H/SrjbAJYIOI7jf +eR4V9rtUHFGCBNKgkThVvxmxvI4EGo8vekWGHS2noCn0MCNpws9nbCB+rxzFWHv8C TIZgOBrxisbzzNMj1QtqNvPj5neM29WvStsbHNTw= To: Felipe Balbi , Greg Kroah-Hartman Cc: Marian Postevca , Maximilian Senftleben , stable@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5.4] usb: gadget: u_ether: fix regression in setting fixed MAC address Date: Wed, 22 Jun 2022 00:47:49 +0300 Message-Id: <20220621214749.3059-1-posteuca@mutex.one> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit b337af3a4d6147000b7ca6b3438bf5c820849b37 upstream. In systemd systems setting a fixed MAC address through the "dev_addr" module argument fails systematically. When checking the MAC address after the interface is created it always has the same but different MAC address to the one supplied as argument. This is partially caused by systemd which by default will set an internally generated permanent MAC address for interfaces that are marked as having a randomly generated address. Commit 890d5b40908bfd1a ("usb: gadget: u_ether: fix race in setting MAC address in setup phase") didn't take into account the fact that the interface must be marked as having a set MAC address when it's set as module argument. Fixed by marking the interface with NET_ADDR_SET when the "dev_addr" module argument is supplied. Reported-by: Maximilian Senftleben Cc: stable@vger.kernel.org Fixes: 890d5b40908bfd1a ("usb: gadget: u_ether: fix race in setting MAC address in setup phase") Signed-off-by: Marian Postevca --- drivers/usb/gadget/function/u_ether.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 271bd08f4a255..3f053b11e2cee 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -772,9 +772,13 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g, dev->qmult = qmult; snprintf(net->name, sizeof(net->name), "%s%%d", netname); - if (get_ether_addr(dev_addr, net->dev_addr)) + if (get_ether_addr(dev_addr, net->dev_addr)) { + net->addr_assign_type = NET_ADDR_RANDOM; dev_warn(&g->dev, "using random %s ethernet address\n", "self"); + } else { + net->addr_assign_type = NET_ADDR_SET; + } if (get_ether_addr(host_addr, dev->host_mac)) dev_warn(&g->dev, "using random %s ethernet address\n", "host"); @@ -831,6 +835,9 @@ struct net_device *gether_setup_name_default(const char *netname) INIT_LIST_HEAD(&dev->tx_reqs); INIT_LIST_HEAD(&dev->rx_reqs); + /* by default we always have a random MAC address */ + net->addr_assign_type = NET_ADDR_RANDOM; + skb_queue_head_init(&dev->rx_frames); /* network device setup */ @@ -868,7 +875,6 @@ int gether_register_netdev(struct net_device *net) g = dev->gadget; memcpy(net->dev_addr, dev->dev_mac, ETH_ALEN); - net->addr_assign_type = NET_ADDR_RANDOM; status = register_netdev(net); if (status < 0) { @@ -908,6 +914,7 @@ int gether_set_dev_addr(struct net_device *net, const char *dev_addr) if (get_ether_addr(dev_addr, new_addr)) return -EINVAL; memcpy(dev->dev_mac, new_addr, ETH_ALEN); + net->addr_assign_type = NET_ADDR_SET; return 0; } EXPORT_SYMBOL_GPL(gether_set_dev_addr); -- 2.35.1