Re: [PATCH v2] EDAC/ghes: Fix buffer overflow in ghes_edac_register()

From: Borislav Petkov
Date: Mon Jul 25 2022 - 06:14:38 EST


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...

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette