From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796367186; b=HbJVCusCc9wzdRj1m9sYwww2P6Bk7fuq0Hm1E+kZIFyPr61wzoJK+KktAJvMquaESbQk dUCF7T43QGXhsJigO1CDgCIii1oNnfnP+GwTEjY/y+sRouYUkJOPak4yV2lZD/cOV18+S QHpQU/n/qu+iEKtH/0h9rKC10X6aYdXBgkQrFLsXjpNyP7scYeslwj7bhZ5cz5DW+A/UF BR9/qP5enHq32/fOtxjnE+KNXo5ErTjQRRnvPjfVMHC4JiUIebqNX5CQBWtBIOEUPf3cM jWvD8EfgBOb6oa9PNBQO9BUevljUK/pUJ1L6R3zeru2iENifDsGIBluopRXBwsUXH+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796367186; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ncDZfjpkQ+/aMfMVkx6z9B24kGE1BJhBElkUUuB7ego=; b=hJb+GW7a5UxsaRxnevMplBwnKjGm6GOOYsk43dh/tvDWKo31DRhJ6MwixPIBeQvo8fVF PryZssY7MaDAQiRS3LNpkpANPUZoIDfiPzcFnpClP1YawGcHHg34YvLXM4NClBL+VaoAT KSTfwUSdH0oBpzNHHM3GaYLXQt6RIDBrrD3/rZe8PRIOKlUhgv05wlsrCtz3T4C3/vm3p Bglm3wDtu0eAobBvIF24yJ3j5+4GMBvAT1xD0HHEF1Ja8EKZOUhWsefZ3G8dhOl1oCwh2 VOfJVfWE7QOuDSdXVsyJO5baf4oxWs2dwcxs58fIg40z4xOTLx0+dBjjK/EP/9rWikw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=VWvTsZO2; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EF1D606A687 for ; Fri, 4 Dec 2026 06:53:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=VWvTsZO2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 098F01F000C2; Fri, 4 Dec 2026 06:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796367186; bh=ncDZfjpkQ+/aMfMVkx6z9B24kGE1BJhBElkUUuB7ego=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=VWvTsZO24fdwKIfD65boAB/jpTU6MujgdRuaKHpmoQHV1p3A7V/ua4+JgYee6dMou a8rxSlfNlVF5TKQxDjDaj1AZpPCY3F6Por0GMvFWP28mW7afefzLyogcpubCqk0xnb CMrajbXCngiZSbrK9tnigP9ch8dyKxLxio4Lq0y5hFWLFTBOtTwoj4C7xSbBxUsebY SG2swUt6agMjKnW6JNNIMgwz7R+UCE0MdXBondBST45D2v0CqCnmjcvuqNnE02bjNt mwIqX/4cKto27xhPkTPh/nAEWLr6axLIrIMBlPUr9y2bqGx2j6qPy7xyveQDR/beCJ GlUFeV4Gv9W+Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 2/5] nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver Reply-To: sashiko-reviews@lists.linux.dev To: "Hongmei Xu" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204-nvmem-byte-mask-for-split-macaddr-v5-2-13c12a99383f@oss.qualcomm.com> References: <20261204-nvmem-byte-mask-for-split-macaddr-v5-0-13c12a99383f@oss.qualcomm.com> <20261204-nvmem-byte-mask-for-split-macaddr-v5-2-13c12a99383f@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 06:53:05 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] nvmem: qcom-eth-mac: use-after-free of layout devm cell priv and priv->dev - [Medium] nvmem: qcom-eth-mac: fw_devlink_purge_absent_suppliers() breaks device links - [Medium] nvmem: qcom-eth-mac: 32-bit unsigned overflow in device-size bounds checks - [Medium] nvmem: qcom_eth_mac_add_cells() fails on unaligned QFPROM cell offsets - [Low] nvmem: qcom-eth-mac: unchecked of_property_read_u32() return for byte-mask - [Low] nvmem: qcom-eth-mac: unnecessary kmemdup() allocation in qcom_eth_mac_post_process() -- commit 13f6b8a719713c9b87d23ea33aed9c0b2e45236c Author: Hongmei Xu nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver This commit adds an NVMEM layout driver for reading contiguous and non-contiguous Ethernet MAC addresses from Qualcomm QFPROM eFuse cells. > diff --git a/drivers/nvmem/layouts/qcom-eth-mac.c b/drivers/nvmem/layouts= /qcom-eth-mac.c > new file mode 100644 > index 0000000000000..990b096a0a5f4 > --- /dev/null > +++ b/drivers/nvmem/layouts/qcom-eth-mac.c [ ... ] > +static int qcom_eth_mac_post_process(void *priv, const char *id, int ind= ex, > + unsigned int offset, void *buf, size_t bytes) > +{ > + struct qcom_eth_mac_priv *p =3D priv; > + u8 *out =3D buf; > + u32 out_idx =3D 0; > + u8 *raw; > + u32 i; > + > + raw =3D kmemdup(buf, p->raw_len, GFP_KERNEL); > + if (!raw) > + return -ENOMEM; > + > + memset(out, 0, bytes); > + > + for (i =3D 0; i < p->raw_len && out_idx < bytes; i++) { > + if (p->byte_mask & BIT(i)) > + out[out_idx++] =3D raw[i]; > + } > + > + kfree(raw); [Severity: Low] Does qcom_eth_mac_post_process() need to kmemdup() buf on every cell read? Since out_idx never exceeds i, the loop can compact in place with out[out_idx++] =3D out[i] and zero the tail with memset(out + out_idx, 0, bytes - out_idx), dropping both the allocation and the -ENOMEM path. [ ... ] > + info.name =3D child->name; > + info.offset =3D reg[0]; > + info.bytes =3D ETH_ALEN; > + info.np =3D of_node_get(child); [Severity: Medium] Can qcom_eth_mac_add_cells() handle cells whose reg[0] offset is not 4-byte aligned, such as a second contiguous 6-byte MAC cell at offset 0x6? qcom,qfprom sets stride =3D 4 and relies on qfprom_fixup_dt_cell_info(), which only runs via nvmem_add_cells_from_dt(). Because this driver calls nvmem_add_one_cell() directly, nvmem core rejects any unaligned reg[0] with -EINVAL and aborts layout registration. Aligning info.offset down to QCOM_QFPROM_WORD_SIZE and adjusting raw_len and byte_mask for the leading bytes would avoid this. > + > + of_property_read_u32(child, "byte-mask", &byte_mask); > + > + if (byte_mask) { [Severity: Low] Should the return value of of_property_read_u32() be checked here? Ignoring it treats a malformed byte-mask property (-ENODATA or -EOVERFLOW) or an explicit byte-mask =3D <0> the same as an absent property (-EINVAL), silently reading contiguous eFuse bytes instead of failing probe. [ ... ] > + if (info.offset + raw_len > nvmem_dev_size(nvmem)) { > + dev_err(dev, "%pOF: offset %u + raw_len %u exceeds device size %zu\n= ", > + child, info.offset, raw_len, > + nvmem_dev_size(nvmem)); > + of_node_put(info.np); > + ret =3D -EINVAL; > + goto out; > + } [Severity: Medium] Can info.offset + raw_len overflow 32-bit unsigned arithmetic and bypass the device-size bounds check? Both info.offset and raw_len are 32-bit, so the sum wraps modulo 2^32 before promotion to size_t even on 64-bit systems (e.g. reg[0] =3D 0xffffff= fc with raw_len =3D 8 wraps to 4). The contiguous info.offset + info.raw_len check below can also wrap on 32-bit architectures. Because neither nvmem_add_one_cell() nor qfprom_reg_read() checks against nvmem->size, a wrapped offset leads to out-of-bounds MMIO reads in qfprom_reg_read(). check_add_overflow() or size_add() avoids this. > + > + priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) { > + of_node_put(info.np); > + ret =3D -ENOMEM; > + goto out; > + } > + > + priv->byte_mask =3D byte_mask; > + priv->raw_len =3D raw_len; > + priv->dev =3D dev; > + info.raw_len =3D raw_len; > + info.read_post_process =3D qcom_eth_mac_post_process; > + info.priv =3D priv; [Severity: High] Can qcom_eth_mac_post_process() hit a use-after-free on priv and priv->dev? priv is devm-allocated on &layout->dev and caches priv->dev =3D dev, but nvmem_add_one_cell() attaches it to nvmem->cells, which outlives layout->dev. On driver unbind or rmmod, nvmem_layout_unregister() is a no-op that leaves cells in sysfs while devres_release_all() frees priv. Any later read of the sysfs cell file then runs qcom_eth_mac_post_process() on freed priv, passing stale p->raw_len to kmemdup() and freed p->dev to dev_dbg(). Partial probe failure in qcom_eth_mac_add_cells() exposes earlier cells with freed priv as well. [ ... ] > + /* > + * Mark the cell fwnode as not-a-device so fw_devlink stops > + * blocking ethernet on this supplier link. Must be called > + * after nvmem_add_one_cell() so the fwnode exists. > + * fw_devlink_refresh_fwnode() cannot be used here because the > + * efuse device is still in probe and not yet DL_DEV_DRIVER_BOUND. > + */ > + fw_devlink_purge_absent_suppliers(of_fwnode_handle(child)); [Severity: Medium] Does calling fw_devlink_purge_absent_suppliers() here break managed device links between layout->dev and its Ethernet consumers? fw_devlink_purge_absent_suppliers() deletes consumer fwnode links on each cell before device_links_driver_bound(&layout->dev) can adopt them via fw_devlink_pickup_dangling_consumers(). Without those managed links, unbind, suspend/resume, and shutdown ordering for consumers is lost. Purging links mid-loop while layout->dev.driver is already set also lets consumers of earlier cells probe before remaining cells are added, and leaves those cell fwnodes permanently mutated if a later iteration fails. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-nvmem-byte= -mask-for-split-macaddr-v5-0-13c12a99383f@oss.qualcomm.com?part=3D2