powerpc/papr_scm: initialise metadata_size before reading it
Subsystems (2)
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
@@ -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
Quoted 8 lines · Hyunjung Ko
papr_scm_probe()reads "ibm,metadata-size" intometadata_sizewithout 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 propertyp->metadata_sizeis set from an uninitialised stack value.
p->metadata_sizeis 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.
Signed-off-by Hyunjung Ko <[email protected]>
With that LGTM, feel free to add: