mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] x86/amd_node: fix integer divide by zero during init
@ 2025-11-14 19:57 Steven Noonan
  2025-11-14 19:57 ` [PATCH 2/2] x86/amd_node: fix null pointer dereference if amd_smn_init failed Steven Noonan
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Steven Noonan @ 2025-11-14 19:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: Steven Noonan, Ariadne Conill, Yazen Ghannam, x86, stable

[-- Attachment #1: Type: text/plain, Size: 1226 bytes --]

On a Xen dom0 boot, this feature does not behave, and we end up
calculating:

    num_roots = 1
    num_nodes = 2
    roots_per_node = 0

This causes a divide-by-zero in the modulus inside the loop.

This change adds a couple of guards for invalid states where we might
get a divide-by-zero.

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Signed-off-by: Ariadne Conill <ariadne@ariadne.space>
CC: Yazen Ghannam <yazen.ghannam@amd.com>
CC: x86@vger.kernel.org
CC: stable@vger.kernel.org
---
 arch/x86/kernel/amd_node.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/x86/kernel/amd_node.c b/arch/x86/kernel/amd_node.c
index 3d0a4768d603c..cdc6ba224d4ad 100644
--- a/arch/x86/kernel/amd_node.c
+++ b/arch/x86/kernel/amd_node.c
@@ -282,6 +282,17 @@ static int __init amd_smn_init(void)
 		return -ENODEV;
 
 	num_nodes = amd_num_nodes();
+
+	if (!num_nodes)
+		return -ENODEV;
+
+	/* Possibly a virtualized environment (e.g. Xen) where we wi
ll get
+	 * roots_per_node=0 if the number of roots is fewer than number of
+	 * nodes
+	 */
+	if (num_roots < num_nodes)
+		return -ENODEV;
+
 	amd_roots = kcalloc(num_nodes, sizeof(*amd_roots), GFP_KERNEL);
 	if (!amd_roots)
 		return -ENOMEM;
-- 
2.51.2


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 322 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-12-05 15:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-14 19:57 [PATCH 1/2] x86/amd_node: fix integer divide by zero during init Steven Noonan
2025-11-14 19:57 ` [PATCH 2/2] x86/amd_node: fix null pointer dereference if amd_smn_init failed Steven Noonan
2025-12-03 20:54   ` Yazen Ghannam
2025-12-03 20:45 ` [PATCH 1/2] x86/amd_node: fix integer divide by zero during init Yazen Ghannam
2025-12-04 20:16   ` Steven Noonan
2025-12-05 15:37     ` Yazen Ghannam
2025-12-03 21:18 ` Borislav Petkov
2025-12-04 16:45   ` Yazen Ghannam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®