Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2930869iog; Mon, 20 Jun 2022 07:43:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sBGDyPTwJ7Gcu50G0W7haeZISdk4vACd0/Oi7LLEvqVJlNtCSuOKd6Cqv2e7ld0e8OuDMT X-Received: by 2002:a05:6a00:cd5:b0:525:23da:6a6e with SMTP id b21-20020a056a000cd500b0052523da6a6emr5600580pfv.56.1655736237500; Mon, 20 Jun 2022 07:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736237; cv=none; d=google.com; s=arc-20160816; b=yG052HPZL8lTKzTmD7AZvG/4ZhaDtkKW4qRRIw/LZrFgzprnxwgSAExYC37EnKrkZb S/Hmva226lcKB1vMQxqg7lFd9y2JxjhxIL5QkVKCvj2sOLRagT/iXHBXHhgFpLiPdvZn BrG7lqyaYJb6bqcYYIdoU0/BJafm6IyzME7m+kK5dJeZoY+gKCM+I5GBNOs0zTdMKOwM +4KfoeI8w+abq2ohZ3BFJ11tzCszCoZLkZW7LIqYk8u9gjt3Sb862taEg8hSutnXIrmz sEGOtz2VM6AswYmf2Gg7Vl4zZmf4njExyfpXXFyca8ooCEa5b7ySLhutAC/HORW+YIcQ YdCw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ej9+MnhRH3vY7QCYyAbFrxm+G1Y7z/0yZ+DmrmCVOyE=; b=K4jOQHbdzFWhqI3zeuvbCUjiOxt0jAnxNaZARe8JLlysJT2CzXe9MFZAqqtRgNCKUV KIt9tinAQb/+c9AvIvNqgyyfyw+rY+06j0FbZIuC9W3q8Fzz/KTSv4VdeQcTxfxWhm1K 7YyKY0gFsL40cz+uoP+Afx0LW2BC1PbN95Ypos6a3mQ6esnMkeewfsHNzZ0v0BaeYj8v 2KHWZJ8Cr5CRJkTsC0iIExKh+xx46mb40F4Vmi7zuHYd2ikDvaiuCpe2C8wIitd7QzLX 3+z5JpXYf1u5Oppn/MbZYXuAla/gSD+3Fk9rOCVd6XsilodHak1GDEHc3r9q6apH0dfE EwSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NBIx9Nfp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c18-20020a170902b69200b00163a54d2612si14670547pls.418.2022.06.20.07.43.44; Mon, 20 Jun 2022 07:43:57 -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=@linuxfoundation.org header.s=korg header.b=NBIx9Nfp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244280AbiFTNFV (ORCPT + 99 others); Mon, 20 Jun 2022 09:05:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244564AbiFTNDo (ORCPT ); Mon, 20 Jun 2022 09:03:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A9D413E2C; Mon, 20 Jun 2022 05:58:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9FEC061530; Mon, 20 Jun 2022 12:58:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 920CFC341C4; Mon, 20 Jun 2022 12:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655729902; bh=yGU+yhI3hMhandy34fwrekFo0NESvCC121hxj6+oOhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NBIx9Nfp2T42m08O7JfsRHypudu1+uqBXm+RrK2S14sCLbEiFNFT+0ickjuB3j5Mt X/w7cBMhC1N8ABcB08cnppi0O3a8DDzandypxGLemf/ixz8c9hDwVQ8f3lUat04QL/ LJj8tlhriICQxFHxrMOf6vQHAzExq+w54agXTGX0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marian Postevca Subject: [PATCH 5.18 111/141] usb: gadget: u_ether: fix regression in setting fixed MAC address Date: Mon, 20 Jun 2022 14:50:49 +0200 Message-Id: <20220620124732.822998965@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124729.509745706@linuxfoundation.org> References: <20220620124729.509745706@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Marian Postevca 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. Fixes: 890d5b40908bfd1a ("usb: gadget: u_ether: fix race in setting MAC address in setup phase") Cc: stable@vger.kernel.org Signed-off-by: Marian Postevca Link: https://lore.kernel.org/r/20220603153459.32722-1-posteuca@mutex.one Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/u_ether.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -775,9 +775,13 @@ struct eth_dev *gether_setup_name(struct dev->qmult = qmult; snprintf(net->name, sizeof(net->name), "%s%%d", netname); - if (get_ether_addr(dev_addr, addr)) + if (get_ether_addr(dev_addr, 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; + } eth_hw_addr_set(net, addr); if (get_ether_addr(host_addr, dev->host_mac)) dev_warn(&g->dev, @@ -844,6 +848,10 @@ struct net_device *gether_setup_name_def eth_random_addr(dev->dev_mac); pr_warn("using random %s ethernet address\n", "self"); + + /* by default we always have a random MAC address */ + net->addr_assign_type = NET_ADDR_RANDOM; + eth_random_addr(dev->host_mac); pr_warn("using random %s ethernet address\n", "host"); @@ -871,7 +879,6 @@ int gether_register_netdev(struct net_de 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); @@ -912,6 +919,7 @@ int gether_set_dev_addr(struct net_devic 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);