[PATCH] block: partitions: of: Fix NULL dereference on partition without reg

Loic Poulain <[email protected]>
Newsgroups org.kernel.vger.linux-block,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
A child node of a fixed-partitions node may lack a reg property, either
because it is malformed or because it is not a partition entry at all.
In that case of_get_property() returns NULL to reg, which is then
dereferenced without proper checking.

Fixes: 2e3a191e89f9 ("block: add support for partition table defined in OF")
Cc: [email protected]
Reviewed-by: Bartosz Golaszewski <[email protected]>
Signed-off-by: Loic Poulain <[email protected]>
---
 block/partitions/of.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/block/partitions/of.c b/block/partitions/of.c
index 53664ea06b6540e3d1155141adaafac7286f2d21..dab36513eba336344c9558d486a8915624b0fca8 100644
--- a/block/partitions/of.c
+++ b/block/partitions/of.c
@@ -15,6 +15,9 @@ static int validate_of_partition(struct device_node *np, int slot)
 	int a_cells = of_n_addr_cells(np);
 	int s_cells = of_n_size_cells(np);
 
+	if (!reg)
+		return -EINVAL;
+
 	/* Make sure reg len match the expected addr and size cells */
 	if (len / sizeof(*reg) != a_cells + s_cells)
 		return -EINVAL;

---
base-commit: fce2dfa773ced15f27dd27cd0b482a7473cdcf2a
change-id: 20260717-partition-null-b05e2c956ee7

Best regards,
-- 
Loic Poulain <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.