Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4209200iog; Tue, 21 Jun 2022 14:35:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1urci6cKybFvk/o1EcwaIepLipirwhH5BnTyFJDAXVWp89rAg3OfgUeazP3kURmrZG/oy9c X-Received: by 2002:a17:907:6e03:b0:718:f3ee:9e34 with SMTP id sd3-20020a1709076e0300b00718f3ee9e34mr131204ejc.300.1655847324796; Tue, 21 Jun 2022 14:35:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655847324; cv=none; d=google.com; s=arc-20160816; b=EyxE64GcFT8IPPKAWhaAgPqMAlh9f/TfT4frFW0gv7ep1kN1BUeNNGx09lWVQ+q1co sI3ak5S3s0zlKEEW9G4xbQ+JSfDXYRmkXz9Oc/RHpe75hzOAe4zE51mJtAPEqKgx1TlY MGl4m1iZ+QVr6SLeeQYbK7akaphYUctxDRYyuA088EsSP/F47TD3+52J+gFjBuqXP+o7 riUSpoUr3qh1vWWS9qrRh5/+v01bOJ+4KH7GeGj0JXq8pdRoWJD9dTtp0EhcGnHHI5Bv m603gqGiq5xbye58qpfnykb+nFXlMZzLzAKQ4Jf2m0ZxDB5mgCKnH3qgXqxTr79j2mwv asNA== 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=6XAbXMFMFH4Tv6U1GznN+irO7drYXo/BmmIlSYPW63w=; b=p9yIMePdVj0rb8krgTm8V3IgYRFoA8PE+eovogcyO2X0sKFMPjuPILvcKEvsYGJJ03 4LQlT3KyOA7s9qoWCoRbE0Eu6KNokT+3zg1dGgl2AM3njB1Wyx2gA7qtSTXHpsefuzzO 98TJQnayzdUDEsRfP9HebAthNHgdHN0xwsg+dyyBJVz5p/zywMTHD8WhohgGRUcmPxxc z2CgyR1yhBOSckoqHtTS0+lsIcudDlOmLxdFRwHswYncMOhlVj18DXkcygXWTpK6+wZf C1HBggR1TuHizW4gQmWwiq1v4IvDioxjcqH9hlLrzSYwGR/jKmPhJWQH4Zm7wxcnzkkI ZP5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mutex.one header.s=default header.b=inJWNUVE; 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 dk22-20020a0564021d9600b004358059d8f1si7301129edb.43.2022.06.21.14.34.59; Tue, 21 Jun 2022 14:35:24 -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=inJWNUVE; 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 S1356308AbiFUVZF (ORCPT + 99 others); Tue, 21 Jun 2022 17:25:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356268AbiFUVYp (ORCPT ); Tue, 21 Jun 2022 17:24:45 -0400 Received: from mail.mutex.one (mail.mutex.one [62.77.152.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B923B18E0E; Tue, 21 Jun 2022 14:18:28 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.mutex.one (Postfix) with ESMTP id E5E4C16C007C; Wed, 22 Jun 2022 00:18:26 +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 zQoGK-iPBWcY; Wed, 22 Jun 2022 00:18:26 +0300 (EEST) From: Marian Postevca DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mutex.one; s=default; t=1655846306; bh=SZv4GmVYSWyJ0KWMqNxRyKQ/A9DysKbi7PuZ+/S+Bqg=; h=From:To:Cc:Subject:Date:From; b=inJWNUVE4J5xReNj+7doC1XjK65aw9Z9horZfbUslh+5HPZBByaDldsMkKS+iuaC3 3R5Qs2RMEBQQsfody48Raw6eNQP94opuiJ3ZGvSRKg77QXj6tVolLcr1L3e77Q/X4h kuEzzVTdT0Sx7I5bhKWvDQf3hypwDAv4FMKbudHU= 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 4.19] usb: gadget: u_ether: fix regression in setting fixed MAC address Date: Wed, 22 Jun 2022 00:18:00 +0300 Message-Id: <20220621211800.18457-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 1b3e674e6330d..2fe91f120bb1d 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