lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221128065923.1180-2-zajec5@gmail.com>
Date:   Mon, 28 Nov 2022 07:59:23 +0100
From:   Rafał Miłecki <zajec5@...il.com>
To:     Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
Cc:     Michael Walle <michael@...le.cc>,
        Miquel Raynal <miquel.raynal@...tlin.com>,
        Richard Weinberger <richard@....at>,
        Vignesh Raghavendra <vigneshr@...com>,
        Rob Herring <robh+dt@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        Shawn Guo <shawnguo@...nel.org>, linux-mtd@...ts.infradead.org,
        devicetree@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
        linux-kernel@...r.kernel.org, u-boot@...ts.denx.de,
        Rafał Miłecki <rafal@...ecki.pl>
Subject: [PATCH V2 2/2] nvmem: u-boot-env: reformat MAC in "ethaddr" cell when reading

From: Rafał Miłecki <rafal@...ecki.pl>

NVMEM consumers expect MAC in a byte-based format (see e.g.
nvmem_get_mac_address()). U-Boot environment data stores all values in
ASCII form.

Add post processing callback detecting "ethaddr" reads and reformat data
as expected. This fixes Ethernet drivers reading MAC from NVMEM devices.

Signed-off-by: Rafał Miłecki <rafal@...ecki.pl>
---
V2: select GENERIC_NET_UTILS & drop unused "priv" variable
---
 drivers/nvmem/Kconfig      |  1 +
 drivers/nvmem/u-boot-env.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 755f551426b5..34fb0ba36b80 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -326,6 +326,7 @@ config NVMEM_U_BOOT_ENV
 	tristate "U-Boot environment variables support"
 	depends on OF && MTD
 	select CRC32
+	select GENERIC_NET_UTILS
 	help
 	  U-Boot stores its setup as environment variables. This driver adds
 	  support for verifying & exporting such data. It also exposes variables
diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c
index 2a87dda45188..e30ce4f7ea20 100644
--- a/drivers/nvmem/u-boot-env.c
+++ b/drivers/nvmem/u-boot-env.c
@@ -4,6 +4,8 @@
  */
 
 #include <linux/crc32.h>
+#include <linux/etherdevice.h>
+#include <linux/if_ether.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/mtd/mtd.h>
@@ -70,6 +72,22 @@ static int u_boot_env_read(void *context, unsigned int offset, void *val,
 	return 0;
 }
 
+static int u_boot_env_cell_post_process(void *context, struct nvmem_cell_entry *cell,
+					const char *id, void *buf, size_t *len)
+{
+	if (!strcmp(cell->name, "ethaddr")) {
+		u8 mac[ETH_ALEN];
+
+		if (mac_pton(buf, mac)) {
+			ether_addr_copy(buf, mac);
+			if (len)
+				*len = ETH_ALEN;
+		}
+	}
+
+	return 0;
+}
+
 static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf,
 				size_t data_offset, size_t data_len)
 {
@@ -179,6 +197,7 @@ static int u_boot_env_probe(struct platform_device *pdev)
 	struct nvmem_config config = {
 		.name = "u-boot-env",
 		.reg_read = u_boot_env_read,
+		.cell_post_process = u_boot_env_cell_post_process,
 	};
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ