Message ID | 20220726164628.1756924-1-toshi.kani@hpe.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v3] EDAC/ghes: Set the DIMM label unconditionally | expand |
On Tue, Jul 26, 2022 at 10:46:28AM -0600, Toshi Kani wrote: > The following buffer overflow BUG was observed on an HPE system. > ghes_edac_register() called strlen() on an uninitialized label, > which had non-zero values from krealloc_array(). ... > Fixes: b9cae27728d1f ("EDAC/ghes: Scan the system once on driver init") > Signed-off-by: Toshi Kani <toshi.kani@hpe.com> > Co-developed-by: Robert Richter <rric@kernel.org> > Tested-by: Robert Elliott <elliott@hpe.com> > --- > drivers/edac/ghes_edac.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) Amended and pushed out. Thx.
diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c index 59b0bedc9c24..c229ed0ce678 100644 --- a/drivers/edac/ghes_edac.c +++ b/drivers/edac/ghes_edac.c @@ -103,9 +103,15 @@ static void dimm_setup_label(struct dimm_info *dimm, u16 handle) dmi_memdev_name(handle, &bank, &device); - /* both strings must be non-zero */ - if (bank && *bank && device && *device) - snprintf(dimm->label, sizeof(dimm->label), "%s %s", bank, device); + /* + * Set a null string when both bank and device are zero. + * This keeps ghes_edac_register() preserving the default + * label from edac_mc_alloc_dimms(). + */ + snprintf(dimm->label, sizeof(dimm->label), "%s%s%s", + (bank && *bank) ? bank : "", + (bank && *bank && device && *device) ? " " : "", + (device && *device) ? device : ""); } static void assign_dmi_dimm_info(struct dimm_info *dimm, struct memdev_dmi_entry *entry)