linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6.1] mm/memory_hotplug: prevent accessing by index=-1
@ 2024-09-26 14:49 Mikhail Lobanov
  0 siblings, 0 replies; only message in thread
From: Mikhail Lobanov @ 2024-09-26 14:49 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: Mikhail Lobanov, David Hildenbrand, Oscar Salvador,
	Andrew Morton, linux-mm, linux-kernel, lvc-project,
	Anastasia Belova

From: Anastasia Belova <abelova@astralinux.ru>

commit 5958d35917e1296f46dfc8b8c959732efd6d8d5d upstream.

nid may be equal to NUMA_NO_NODE=-1.  Prevent accessing node_data array by
invalid index with check for nid.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: e83a437faa62 ("mm/memory_hotplug: introduce "auto-movable" online policy")
Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Oscar Salvador <osalvador@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
---
 mm/memory_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index dc17618bad8b..90f0cc9a298a 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -783,7 +783,6 @@ static bool auto_movable_can_online_movable(int nid, struct memory_group *group,
 	unsigned long kernel_early_pages, movable_pages;
 	struct auto_movable_group_stats group_stats = {};
 	struct auto_movable_stats stats = {};
-	pg_data_t *pgdat = NODE_DATA(nid);
 	struct zone *zone;
 	int i;
 
@@ -794,6 +793,8 @@ static bool auto_movable_can_online_movable(int nid, struct memory_group *group,
 			auto_movable_stats_account_zone(&stats, zone);
 	} else {
 		for (i = 0; i < MAX_NR_ZONES; i++) {
+			pg_data_t *pgdat = NODE_DATA(nid);
+
 			zone = pgdat->node_zones + i;
 			if (populated_zone(zone))
 				auto_movable_stats_account_zone(&stats, zone);
-- 
2.43.0



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-12-05 15:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-26 14:49 [PATCH 6.1] mm/memory_hotplug: prevent accessing by index=-1 Mikhail Lobanov

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