Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5162995iog; Wed, 22 Jun 2022 13:27:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t6YHnPfChCDULR15vET9wsAOevcLNp43Gy1mQoNS6RK7SuJifebU9ASh7FEZtT6/wNDfTt X-Received: by 2002:a05:6402:2396:b0:435:775b:b136 with SMTP id j22-20020a056402239600b00435775bb136mr6183063eda.299.1655929660826; Wed, 22 Jun 2022 13:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655929660; cv=none; d=google.com; s=arc-20160816; b=DicsQ2I/ct1Z4pqxiE1sA6wklFQmmDgRe7fRhkP7YVOXEdmIImr2uaVP7AKKmCXXnb 9/A+kDh11Vl8VKM4226Fs6tz/rsEML0P39sE4G9dF+N1lsnXoV25MhF83Sjy5fTt5jMZ oOicqdQ9uHauPoKCszrCv5W6muh8N7GbZwM/Wat/zkM4f8VF/yj0BwbhNcW2S+3Dj9Oi GpRcNeVerVG2iz3BWhsvlNDk925JgEuUW22rDppyGqL/N0lfzwC2705UP8Aa1qDAgm4U dTuJWMEbFbYr/HGxYk3oO9D5Z1vMkIWyX7jdVyWWseEnoSp0H9H4jr506jg5h6qHrhyI /z4Q== 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=B+BX5XaLJN9GG7926JvdhK3SsQbrhArTs50WFa50k1g=; b=feSCxddXqlhjKRcefzCwXu5VsLAULhP7x25npgjgql41HRNhwEGbSRrR6lhB4RNAzN igCbq6p+ia+xUlKIloo9MaIzpS8xIvRnY2E9tcivGIg1P07b/y4Btd48mLwMHIyyR60Z rL1aVQN13U0Cro3UlNWLEuTxbYEwI+19vV3xejSCYAAlu/LXL5LnejjSgAVz6fVpJndv rQtfK8B3fN2ft9C8D3O3DdQgsjcXDu6WUmOSN1mlMeReiVpMmqTK1u/OpVIPlMFYw2dR lKCgR8/j72mO28kMkzofIplszM+1GfKTvhwg/NLrlOd9Xxog2euHoSl68SFHkd5wGDEB ubOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mutex.one header.s=default header.b=mdzceMJ+; 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 n14-20020a056402514e00b00435806b796asi2469138edd.433.2022.06.22.13.27.12; Wed, 22 Jun 2022 13:27:40 -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=mdzceMJ+; 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 S231515AbiFVUSR (ORCPT + 99 others); Wed, 22 Jun 2022 16:18:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231239AbiFVUSP (ORCPT ); Wed, 22 Jun 2022 16:18:15 -0400 Received: from mail.mutex.one (mail.mutex.one [62.77.152.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C208E12A91; Wed, 22 Jun 2022 13:18:14 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.mutex.one (Postfix) with ESMTP id 5E13C16C007C; Wed, 22 Jun 2022 23:18:13 +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 7D_hW6evEOEl; Wed, 22 Jun 2022 23:18:13 +0300 (EEST) From: Marian Postevca DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mutex.one; s=default; t=1655929093; bh=xwvGetNLY6Ram85X3IvCg95rBMf6H7m9uiOQq0V+Otg=; h=From:To:Cc:Subject:Date:From; b=mdzceMJ+9vLqkHphFpLbUsH/tmEWbC5/9CTIwhGmXZoE8xiA+JzqmIj/cyiD9/jkX mI2KWpNqOoQfQg7sSITw9+QM4S1Z6GgdFAzuYxCgWisbgVLRmg9Pf6aUdSRNYyMCib 04IUBNHJbGBVoMy6RdmCDLc52ud0oujI9Vrj4Zvs= 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.15] usb: gadget: u_ether: fix regression in setting fixed MAC address Date: Wed, 22 Jun 2022 23:18:04 +0300 Message-Id: <20220622201805.4315-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 d15a54f6c24b9..ef253599dcf96 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -774,9 +774,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"); @@ -833,6 +837,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 */ @@ -869,7 +876,6 @@ int gether_register_netdev(struct net_device *net) dev = netdev_priv(net); g = dev->gadget; - net->addr_assign_type = NET_ADDR_RANDOM; eth_hw_addr_set(net, dev->dev_mac); status = register_netdev(net); @@ -910,6 +916,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