Messages in this thread | | | Date | Mon, 25 Jul 2022 12:45:18 +0200 | From | Robert Richter <> | Subject | Re: [PATCH v2] EDAC/ghes: Fix buffer overflow in ghes_edac_register() |
| |
On 25.07.22 12:14:21, Borislav Petkov wrote: > On Mon, Jul 25, 2022 at 11:53:06AM +0200, Robert Richter wrote: > > The dimm->label buffer must be pre-initialized zero. This broke with: > > > > b9cae27728d1 EDAC/ghes: Scan the system once on driver init > > > > since krealloc/krealloc_array() does not zero out the new allocated > > buffer for struct dimm_info in enumerate_dimms(). This uninitialized > > broken struct is then copied in ghes_edac_register() to the final > > dimm_info destination. Originally, before b9cae27728d1, the struct was > > zero initialized with kzalloc'ed by edac_mc_alloc() and directly used. > > Now, that a copy is created first, this copy must be also zero > > initialized. > > > > IMO this is the proper fix: > > Maybe, but this needs fixing too: > > /* both strings must be non-zero */ > if (bank && *bank && device && *device) > > Obviously one of those strings are zero coming from that BIOS...
But the label is pre-initialized in edac_mc_alloc_dimms():
p = dimm->label; n = snprintf(p, len, "mc#%u", mci->mc_idx);
You check if the label is emtpy when copying it in ghes_edac_register():
if (strlen(src->label)) memcpy(dst->label, src->label, sizeof(src->label));
So if there is nothing that comes from the bios, this default label string from edac_mc_alloc_dimms() will be used.
If you write "N/A" to the label instead, the sysfs dimm_label values wont be unique any longer between dimms, which might break existing applications.
-Robert
> > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette
| |