Skip to contentSkip to conversation

powerpc/papr_scm: initialise metadata_size before reading it

PATCH In review Hyunjung Ko 2 participants 2 messages Nov 19 – Nov 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/papr_scm: initialise metadata_size before reading it

papr_scm_probe() reads "ibm,metadata-size" into metadata_size without checking the return value, and the property is optional, as the comment right above the call says. of_property_read_u32() only writes the output when it can decode a value, so for a device tree without that property p->metadata_size is set from an uninitialised stack value.

p->metadata_size is the bound for the metadata get/set commands:

	if ((hdr->in_offset + hdr->in_length) > p->metadata_size)

so a garbage value decides which metadata accesses are accepted. Initialise it to zero, which makes those commands reject every access when the platform does not advertise a metadata area.

---
 arch/powerpc/platforms/pseries/papr_scm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/papr_scm.c +1 -1
index 5c3bf06bb59b..e9895e9b070c 100644
@@ -1361,7 +1361,7 @@ static struct notifier_block mce_ue_nb =
 static int papr_scm_probe(struct platform_device *pdev)
 {
 	struct device_node *dn = pdev->dev.of_node;
-	u32 drc_index, metadata_size;
+	u32 drc_index, metadata_size = 0;
 	u64 blocks, block_size;
 	struct papr_scm_priv *p;
 	u8 uuid_raw[UUID_SIZE];
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Hyunjung Ko

papr_scm_probe() reads "ibm,metadata-size" into metadata_size without checking the return value, and the property is optional, as the comment right above the call says. of_property_read_u32() only writes the output when it can decode a value, so for a device tree without that property p->metadata_size is set from an uninitialised stack value.

p->metadata_size is the bound for the metadata get/set commands:

Quoted 8 lines
	if ((hdr->in_offset + hdr->in_length) > p->metadata_size)

so a garbage value decides which metadata accesses are accepted. Initialise it to zero, which makes those commands reject every access when the platform does not advertise a metadata area.

Fixes b5beae5e224f ("powerpc/pseries: Add driver for PAPR SCM regions")

With that LGTM, feel free to add: