Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5162993iog; Wed, 22 Jun 2022 13:27:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vArA+ubVt0xWMENJ/Ccl4/FwT9u1a1C3Nlb8nxXORp0PeCXZ1BTzEblXJdwzzM0jEXQgTL X-Received: by 2002:a05:6402:518b:b0:435:c1ed:3121 with SMTP id q11-20020a056402518b00b00435c1ed3121mr1590590edd.405.1655929660815; 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=0Bn6GK51segdESwH7CaHNc8T2nWIDsoSzb6wJwgIoJxK9I8K3fSWPK4tlCFs/4f/KI xoQkgxLbqhtak1u3RBUB6ACXw1z5QkJS4pm47uXQM8TR2ed+U6FV4w5gq4drLfksHcD4 iyNa5+fie7iZHGVRIh1GS7jCszCC6vNjtZY4aAHZJsJNlzQjraUu6MauMoLRFIEzOKp7 H5RCNh7uW/UE61GLmNSVjazPlyLvisVAtni1u4N2aQUmVf2DA8m1FXLDpQ8AVHId/l3E mTzTdkB46lCPWNm+HuDFFORI436yhBG+GjuKOX804TnM04sOUkGNhBvQREQ4wXSvv3Nd GayA== 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=+vJpvuyb3QjRHAjV2cv+0v7D06Ozrx8ZkpPesp1LVtg=; b=kqnesfBy3gJRN/ZI+ep3eXSiwvgqevMjS5mXgRg9OQc5w0jNmxvauA3oS5E8HyCJQJ EHbleGnKVZEB/CQda9kPJSAsJVBlzLX2xKVTDdwrqkkc7+AsTSsxAevu2mPT7jH47hET 8eD67nr5EZ51wVL9oC3d1SUwkusJCb/xJS4+ZFvdaIfOaUec4YdfPf2XMa0Eomt8S+C8 5pop8aAnugf2uMNUJbsr0cHzelPwLbwdlu4R8OVlMlORDzphSNsvteiNUJ/rubIcOB9U NHw4IBl6D8EXQOgHI2gikNNrkWPDZg1yvryGtXxL5InOOR7PldymdUSPk3RZDGJPWSXN HuNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mutex.one header.s=default header.b="eY/3xvXN"; 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 d18-20020aa7d5d2000000b0043573352428si13644635eds.507.2022.06.22.13.27.06; 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="eY/3xvXN"; 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 S231166AbiFVURN (ORCPT + 99 others); Wed, 22 Jun 2022 16:17:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbiFVURM (ORCPT ); Wed, 22 Jun 2022 16:17:12 -0400 Received: from mail.mutex.one (mail.mutex.one [62.77.152.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A583234B99; Wed, 22 Jun 2022 13:17:11 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.mutex.one (Postfix) with ESMTP id 9290416C007C; Wed, 22 Jun 2022 23:17:09 +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 tJAFoSIpfZdJ; Wed, 22 Jun 2022 23:17:09 +0300 (EEST) From: Marian Postevca DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mutex.one; s=default; t=1655929029; bh=F39pPOCk5LJbjzxOxaPcJXDJYJADDBnzr5DdpvKy0h0=; h=From:To:Cc:Subject:Date:From; b=eY/3xvXNSThv9jdP4DWrn83uYiVtakefrX5lm8kB38D1nbA+Dw1HGniJq+VSinl40 1rwkiuzoF5md6t6gchvw0YfdURAl8E5qtev7+ZA0q4i+/aWnLH+E836W+oHIFB2jA5 8MBDM+gr3t/HK76PbwE+5e8K8FKxQIe+TccBYwTg= 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.10] usb: gadget: u_ether: fix regression in setting fixed MAC address Date: Wed, 22 Jun 2022 23:16:38 +0300 Message-Id: <20220622201638.1512-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 a40be8b448c24..64ef97ab9274a 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