From: David Hildenbrand <david@redhat.com>
To: Anastasia Belova <abelova@astralinux.ru>
Cc: Oscar Salvador <osalvador@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
lvc-project@linuxtesting.org
Subject: Re: [PATCH] mm/memory_hotplug: prevent accessing by index=-1
Date: Mon, 3 Jun 2024 18:07:39 +0200 [thread overview]
Message-ID: <3c2b1b1e-c9b3-442e-8f7b-5c7518d3fbdb@redhat.com> (raw)
In-Reply-To: <20240603112830.7432-1-abelova@astralinux.ru>
On 03.06.24 13:28, Anastasia Belova wrote:
> 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>
> ---
> mm/memory_hotplug.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 431b1f6753c0..bb98ee8fe698 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -846,7 +846,7 @@ 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);
> + pg_data_t *pgdat = (nid != NUMA_NO_NODE) ? NODE_DATA(nid) : NULL;
> struct zone *zone;
> int i;
pgdat is never dereferenced when "nid == NUMA_NO_NODE".
NODE_DATA is defined as
arch/arm64/include/asm/mmzone.h:#define NODE_DATA(nid) (node_data[(nid)])
arch/loongarch/include/asm/mmzone.h:#define NODE_DATA(nid) (node_data[(nid)])
arch/mips/include/asm/mach-ip27/mmzone.h:#define NODE_DATA(n) (&__node_data[(n)]->pglist)
arch/mips/include/asm/mach-loongson64/mmzone.h:#define NODE_DATA(n) (__node_data[n])
arch/powerpc/include/asm/mmzone.h:#define NODE_DATA(nid) (node_data[nid])
arch/riscv/include/asm/mmzone.h:#define NODE_DATA(nid) (node_data[(nid)])
arch/s390/include/asm/mmzone.h:#define NODE_DATA(nid) (node_data[nid])
arch/sh/include/asm/mmzone.h:#define NODE_DATA(nid) (node_data[nid])
arch/sparc/include/asm/mmzone.h:#define NODE_DATA(nid) (node_data[nid])
arch/x86/include/asm/mmzone_32.h:#define NODE_DATA(nid) (node_data[nid])
arch/x86/include/asm/mmzone_64.h:#define NODE_DATA(nid) (node_data[nid])
Regarding architectures that's actually support memory hotplug, this is pure pointer arithmetic.
(it is for mips as well, just less obvious)
So how is that a real problem? Do we have a reproducer?
--
Cheers,
David / dhildenb
next parent reply other threads:[~2024-06-03 16:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240603112830.7432-1-abelova@astralinux.ru>
2024-06-03 16:07 ` David Hildenbrand [this message]
2024-06-03 17:53 ` Oscar Salvador
2024-06-03 17:58 ` David Hildenbrand
[not found] ` <20240603-4f7a5fd957aa1f9cbc8d5f14-pchelkin@ispras.ru>
2024-06-03 20:15 ` David Hildenbrand
[not found] ` <20240606080659.18525-1-abelova@astralinux.ru>
2024-06-07 7:34 ` [PATCH v2] " Oscar Salvador
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3c2b1b1e-c9b3-442e-8f7b-5c7518d3fbdb@redhat.com \
--to=david@redhat.com \
--cc=abelova@astralinux.ru \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lvc-project@linuxtesting.org \
--cc=osalvador@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox