* [PATCH] EDAC/ghes: Fix buffer overflow in ghes_edac_register()
@ 2022-07-19 22:01 Toshi Kani
2022-07-20 11:51 ` Borislav Petkov
0 siblings, 1 reply; 5+ messages in thread
From: Toshi Kani @ 2022-07-19 22:01 UTC (permalink / raw)
To: bp, rrichter, mchehab
Cc: toshi.kani, elliott, linux-edac, linux-kernel, Borislav Petkov
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().
Change dimm_setup_label() to always initialize the label.
detected buffer overflow in __fortify_strlen
------------[ cut here ]------------
kernel BUG at lib/string_helpers.c:983!
invalid opcode: 0000 [#1] PREEMPT SMP NOPTI
CPU: 1 PID: 1 Comm: swapper/0 Tainted: G I 5.18.6-200.fc36.x86_64 #1
Hardware name: HPE ProLiant DL360 Gen10/ProLiant DL360 Gen10, BIOS U32 03/15/2019
RIP: 0010:fortify_panic+0xf/0x11
...
Call Trace:
<TASK>
ghes_edac_register.cold+0x128/0x128
ghes_probe+0x142/0x3a0
platform_probe+0x41/0x90
really_probe+0x19e/0x370
__driver_probe_device+0xfc/0x170
driver_probe_device+0x1f/0x90
__driver_attach+0xbb/0x190
? __device_attach_driver+0xe0/0xe0
bus_for_each_dev+0x5f/0x90
bus_add_driver+0x159/0x200
driver_register+0x89/0xd0
acpi_ghes_init+0x72/0xc3
acpi_init+0x441/0x493
? acpi_sleep_proc_init+0x24/0x24
do_one_initcall+0x41/0x200
Fixes: b9cae27728d1f ("EDAC/ghes: Scan the system once on driver init")
Tested-by: Robert Elliott <elliott@hpe.com>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Robert Richter <rrichter@marvell.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
---
drivers/edac/ghes_edac.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
index 59b0bedc9c24..3ad3d5fc45e0 100644
--- a/drivers/edac/ghes_edac.c
+++ b/drivers/edac/ghes_edac.c
@@ -106,6 +106,8 @@ static void dimm_setup_label(struct dimm_info *dimm, u16 handle)
/* both strings must be non-zero */
if (bank && *bank && device && *device)
snprintf(dimm->label, sizeof(dimm->label), "%s %s", bank, device);
+ else
+ dimm->label[0] = '\0';
}
static void assign_dmi_dimm_info(struct dimm_info *dimm, struct memdev_dmi_entry *entry)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] EDAC/ghes: Fix buffer overflow in ghes_edac_register()
2022-07-19 22:01 [PATCH] EDAC/ghes: Fix buffer overflow in ghes_edac_register() Toshi Kani
@ 2022-07-20 11:51 ` Borislav Petkov
2022-07-20 15:41 ` Kani, Toshi
0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2022-07-20 11:51 UTC (permalink / raw)
To: Toshi Kani
Cc: rrichter, mchehab, elliott, linux-edac, linux-kernel, Borislav Petkov
On Tue, Jul 19, 2022 at 04:01:24PM -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().
> Change dimm_setup_label() to always initialize the label.
Do we also know why dmi_memdev_name() doesn't give bank and/or device?
SMBIOS handle wrong?
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] EDAC/ghes: Fix buffer overflow in ghes_edac_register()
2022-07-20 11:51 ` Borislav Petkov
@ 2022-07-20 15:41 ` Kani, Toshi
2022-07-20 15:57 ` Borislav Petkov
0 siblings, 1 reply; 5+ messages in thread
From: Kani, Toshi @ 2022-07-20 15:41 UTC (permalink / raw)
To: Borislav Petkov
Cc: rrichter, mchehab, Elliott, Robert (Servers),
linux-edac, linux-kernel, Borislav Petkov
Borislav Petkov wrote:
> On Tue, Jul 19, 2022 at 04:01:24PM -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().
> > Change dimm_setup_label() to always initialize the label.
>
> Do we also know why dmi_memdev_name() doesn't give bank and/or device?
Yes.
> SMBIOS handle wrong?
SMBIOS handle is correct.
In dimm_setup_label(), *device is set but *bank is null (dmi_empty_string).
*bank is set from SMBIOS type 17 Bank Locator, offset 11h. This value is
set to 0x0 (null string) on this system, as shown below.
Handle 0x0020, DMI type 17, 84 bytes
Memory Device
Array Handle: 0x0013
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: 32 GB
Form Factor: DIMM
Set: None
Locator: PROC 1 DIMM 1 <===== device
Bank Locator: Not Specified <===== bank
....
Handle 0x0020, DMI type 17, 84 bytes
Header and Data:
11 54 20 00 13 00 FE FF 48 00 40 00 FF 7F 09 00
01 00 1A 80 20 75 0B 02 00 00 03 02 00 80 00 00
^^
75 0B B0 04 B0 04 B0 04 03 08 00 00 89 83 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00
Strings:
50 52 4F 43 20 31 20 44 49 4D 4D 20 31 00
PROC 1 DIMM 1
55 4E 4B 4E 4F 57 4E 00
UNKNOWN
4E 4F 54 20 41 56 41 49 4C 41 42 4C 45 00
NOT AVAILABLE
Thanks,
Toshi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] EDAC/ghes: Fix buffer overflow in ghes_edac_register()
2022-07-20 15:41 ` Kani, Toshi
@ 2022-07-20 15:57 ` Borislav Petkov
2022-07-20 16:17 ` Kani, Toshi
0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2022-07-20 15:57 UTC (permalink / raw)
To: Kani, Toshi
Cc: rrichter, mchehab, Elliott, Robert (Servers), linux-edac, linux-kernel
On Wed, Jul 20, 2022 at 03:41:20PM +0000, Kani, Toshi wrote:
> SMBIOS handle is correct.
>
> In dimm_setup_label(), *device is set but *bank is null (dmi_empty_string).
> *bank is set from SMBIOS type 17 Bank Locator, offset 11h. This value is
> set to 0x0 (null string) on this system, as shown below.
>
> Handle 0x0020, DMI type 17, 84 bytes
> Memory Device
> Array Handle: 0x0013
> Error Information Handle: Not Provided
> Total Width: 72 bits
> Data Width: 64 bits
> Size: 32 GB
> Form Factor: DIMM
> Set: None
> Locator: PROC 1 DIMM 1 <===== device
> Bank Locator: Not Specified <===== bank
I think it'll be more user-friendly to put
"PROC 1 DIMM 1" for device
and
"NA" or so for bank
instead of setting the label to the NULL string.
I.e., relax that
if (bank && *bank && device && *device)
check there.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] EDAC/ghes: Fix buffer overflow in ghes_edac_register()
2022-07-20 15:57 ` Borislav Petkov
@ 2022-07-20 16:17 ` Kani, Toshi
0 siblings, 0 replies; 5+ messages in thread
From: Kani, Toshi @ 2022-07-20 16:17 UTC (permalink / raw)
To: Borislav Petkov
Cc: rrichter, mchehab, Elliott, Robert (Servers), linux-edac, linux-kernel
Borislav Petkov wrote:
> I think it'll be more user-friendly to put
>
> "PROC 1 DIMM 1" for device
>
> and
>
> "NA" or so for bank
>
> instead of setting the label to the NULL string.
>
> I.e., relax that
>
> if (bank && *bank && device && *device)
>
> check there.
Good idea. I will send a v2 patch to set "NA" in case device or bank
is null.
Thanks,
Toshi
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-07-20 16:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 22:01 [PATCH] EDAC/ghes: Fix buffer overflow in ghes_edac_register() Toshi Kani
2022-07-20 11:51 ` Borislav Petkov
2022-07-20 15:41 ` Kani, Toshi
2022-07-20 15:57 ` Borislav Petkov
2022-07-20 16:17 ` Kani, Toshi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).