From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FC47C433FE for ; Wed, 5 Jan 2022 13:27:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240363AbiAEN07 (ORCPT ); Wed, 5 Jan 2022 08:26:59 -0500 Received: from marcansoft.com ([212.63.210.85]:43092 "EHLO mail.marcansoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236846AbiAEN04 (ORCPT ); Wed, 5 Jan 2022 08:26:56 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: marcan@marcan.st) by mail.marcansoft.com (Postfix) with ESMTPSA id CAEB441F4A; Wed, 5 Jan 2022 13:26:46 +0000 (UTC) Subject: Re: [PATCH v2 10/35] brcmfmac: firmware: Allow platform to override macaddr To: Andy Shevchenko Cc: Kalle Valo , "David S. Miller" , Jakub Kicinski , Rob Herring , "Rafael J. Wysocki" , Len Brown , Arend van Spriel , Franky Lin , Hante Meuleman , Chi-hsien Lin , Wright Feng , Dmitry Osipenko , Sven Peter , Alyssa Rosenzweig , Mark Kettenis , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , Pieter-Paul Giesberts , Linus Walleij , Hans de Goede , "John W. Linville" , "brian m. carlson" , "open list:TI WILINK WIRELES..." , netdev , devicetree , Linux Kernel Mailing List , ACPI Devel Maling List , "open list:BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER" , SHA-cyfmac-dev-list@infineon.com References: <20220104072658.69756-1-marcan@marcan.st> <20220104072658.69756-11-marcan@marcan.st> From: Hector Martin Message-ID: Date: Wed, 5 Jan 2022 22:26:44 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: es-ES Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On 04/01/2022 23.23, Andy Shevchenko wrote: > On Tue, Jan 4, 2022 at 9:29 AM Hector Martin wrote: >> >> On Device Tree platforms, it is customary to be able to set the MAC >> address via the Device Tree, as it is often stored in system firmware. >> This is particularly relevant for Apple ARM64 platforms, where this >> information comes from system configuration and passed through by the >> bootloader into the DT. >> >> Implement support for this by fetching the platform MAC address and >> adding or replacing the macaddr= property in nvram. This becomes the >> dongle's default MAC address. >> >> On platforms with an SROM MAC address, this overrides it. On platforms >> without one, such as Apple ARM64 devices, this is required for the >> firmware to boot (it will fail if it does not have a valid MAC at all). > > ... > >> +#define BRCMF_FW_MACADDR_FMT "macaddr=%pM" >> +#define BRCMF_FW_MACADDR_LEN (7 + ETH_ALEN * 3) > > ... > >> if (strncmp(&nvp->data[nvp->entry], "boardrev", 8) == 0) >> nvp->boardrev_found = true; >> + /* strip macaddr if platform MAC overrides */ >> + if (nvp->strip_mac && >> + strncmp(&nvp->data[nvp->entry], "macaddr", 7) == 0) > > If it has no side effects, I would rather swap the operands of && so > you match string first (it will be in align with above code at least, > although I haven't checked bigger context). I usually check for trivial flags before calling more expensive functions because it's more efficient in the common case. Obviously here performance doesn't matter though. > > .... > >> +static void brcmf_fw_add_macaddr(struct nvram_parser *nvp, u8 *mac) >> +{ >> + snprintf(&nvp->nvram[nvp->nvram_len], BRCMF_FW_MACADDR_LEN + 1, >> + BRCMF_FW_MACADDR_FMT, mac); > > Please, avoid using implict format string, it's dangerous from security p.o.v. What do you mean by implicit format string? The format string is at the top of the file and its length is right next to it, which makes it harder for them to accidentally fall out of sync. +#define BRCMF_FW_MACADDR_FMT "macaddr=%pM" +#define BRCMF_FW_MACADDR_LEN (7 + ETH_ALEN * 3) > >> + nvp->nvram_len += BRCMF_FW_MACADDR_LEN + 1; > > Also, with temporary variable the code can be better to read > > size_t mac_len = ...; > Sure. -- Hector Martin (marcan@marcan.st) Public Key: https://mrcn.st/pub