Commit 5958d359 authored by Anastasia Belova's avatar Anastasia Belova Committed by Andrew Morton

mm/memory_hotplug: prevent accessing by index=-1

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.

Link: https://lkml.kernel.org/r/20240606080659.18525-1-abelova@astralinux.ru
Fixes: e83a437f ("mm/memory_hotplug: introduce "auto-movable" online policy")
Signed-off-by: default avatarAnastasia Belova <abelova@astralinux.ru>
Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
Acked-by: default avatarOscar Salvador <osalvador@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent f742829d
...@@ -846,7 +846,6 @@ static bool auto_movable_can_online_movable(int nid, struct memory_group *group, ...@@ -846,7 +846,6 @@ static bool auto_movable_can_online_movable(int nid, struct memory_group *group,
unsigned long kernel_early_pages, movable_pages; unsigned long kernel_early_pages, movable_pages;
struct auto_movable_group_stats group_stats = {}; struct auto_movable_group_stats group_stats = {};
struct auto_movable_stats stats = {}; struct auto_movable_stats stats = {};
pg_data_t *pgdat = NODE_DATA(nid);
struct zone *zone; struct zone *zone;
int i; int i;
...@@ -857,6 +856,8 @@ static bool auto_movable_can_online_movable(int nid, struct memory_group *group, ...@@ -857,6 +856,8 @@ static bool auto_movable_can_online_movable(int nid, struct memory_group *group,
auto_movable_stats_account_zone(&stats, zone); auto_movable_stats_account_zone(&stats, zone);
} else { } else {
for (i = 0; i < MAX_NR_ZONES; i++) { for (i = 0; i < MAX_NR_ZONES; i++) {
pg_data_t *pgdat = NODE_DATA(nid);
zone = pgdat->node_zones + i; zone = pgdat->node_zones + i;
if (populated_zone(zone)) if (populated_zone(zone))
auto_movable_stats_account_zone(&stats, zone); auto_movable_stats_account_zone(&stats, zone);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment