From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Franklin-Qi <yusq77@gmail.com>, Miguel Ojeda <ojeda@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Alice Ryhl <aliceryhl@google.com>
Cc: rust-for-linux@vger.kernel.org, linux-mm@kvack.org,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R . Howlett" <liam@infradead.org>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Harry Yoo" <harry@kernel.org>,
"Georgios Androutsopoulos" <georgeandrout13@gmail.com>,
"Vitaly Wool" <vitaly.wool@konsulko.se>,
stable@vger.kernel.org
Subject: Re: [PATCH] rust: alloc: reject offline NUMA nodes in allocator
Date: Fri, 20 Nov 2026 10:47:11 +0100 [thread overview]
Message-ID: <73c18685-8115-4ee5-876d-a276902488aa@kernel.org> (raw)
In-Reply-To: <20261120021633.12274-1-yusq77@gmail.com>
On 11/20/26 03:16, Franklin-Qi wrote:
> NumaNode::new() only checks that the id is in [0, MAX_NUMNODES). Safe
> Allocator APIs can still forward an offline node into
> k[v]realloc_node_align(), which may dereference NODE_DATA(nid) == NULL
> and panic (GPF).
>
> Reject offline nodes at the shared ReallocFunc boundary for nonzero
> allocations. Leave NUMA_NO_NODE and zero-sized free/realloc paths
> unchanged. A residual hotplug TOCTOU remains if a node goes offline
> after the check; this matches practical C usage for rejecting
> statically missing nodes from safe Rust.
IIRC we however don't remove node data on offline, so the NULL dereference
won't happen?
> Fixes: 7760b6421b6c ("rust: add support for NUMA ids in allocations")
> Cc: stable@vger.kernel.org
> Reported-by: Georgios Androutsopoulos <georgeandrout13@gmail.com>
> Closes: https://github.com/Rust-for-Linux/linux/issues/1263
>
> Signed-off-by: Franklin-Qi <yusq77@gmail.com>
> ---
> rust/helpers/mm.c | 6 ++++++
> rust/kernel/alloc/allocator.rs | 18 ++++++++++++++++++
> 2 files changed, 24 insertions(+)
>
> diff --git a/rust/helpers/mm.c b/rust/helpers/mm.c
> index b5540997b..b61e54e16 100644
> --- a/rust/helpers/mm.c
> +++ b/rust/helpers/mm.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0
>
> #include <linux/mm.h>
> +#include <linux/nodemask.h>
> #include <linux/sched/mm.h>
>
> __rust_helper void rust_helper_mmgrab(struct mm_struct *mm)
> @@ -38,6 +39,11 @@ __rust_helper void rust_helper_mmap_read_unlock(struct mm_struct *mm)
> mmap_read_unlock(mm);
> }
>
> +__rust_helper bool rust_helper_node_online(int nid)
> +{
> + return node_online(nid);
> +}
> +
> __rust_helper struct vm_area_struct *
> rust_helper_vma_lookup(struct mm_struct *mm, unsigned long addr)
> {
> diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs
> index cd4203f27..15e17f598 100644
> --- a/rust/kernel/alloc/allocator.rs
> +++ b/rust/kernel/alloc/allocator.rs
> @@ -101,6 +101,23 @@ unsafe fn call(
> nid: NumaNode,
> ) -> Result<NonNull<[u8]>, AllocError> {
> let size = layout.size();
> +
> + // `NumaNode::new` validates the ID range, not whether the node is online.
> + // The C allocation paths require an online node for nonzero allocations.
> + // Keep `NUMA_NO_NODE` and zero-sized deallocations unchanged.
> + //
> + // Residual TOCTOU remains if a node goes offline after this check and
> + // before the allocator runs; that matches practical C usage for rejecting
> + // statically missing/offline nodes from safe Rust.
> + if size != 0 && nid != NumaNode::NO_NODE {
> + // SAFETY: The helper only reads the kernel's online-node mask. `nid`
> + // is either `NUMA_NO_NODE` (excluded above) or a value in
> + // `[0, MAX_NUMNODES)` from `NumaNode::new`.
> + if !unsafe { bindings::node_online(nid.0) } {
> + return Err(AllocError);
> + }
> + }
> +
> let ptr = match ptr {
> Some(ptr) => {
> if old_layout.size() == 0 {
> @@ -116,6 +133,7 @@ unsafe fn call(
> // - `self.0` is one of `krealloc`, `vrealloc`, `kvrealloc` and thus only requires that
> // `ptr` is NULL or valid.
> // - `ptr` is either NULL or valid by the safety requirements of this function.
> + // - For nonzero allocations with a specific node, `nid` was checked online above.
> //
> // GUARANTEE:
> // - `self.0` is one of `krealloc`, `vrealloc`, `kvrealloc`.
prev parent reply other threads:[~2026-11-20 9:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 2:16 [PATCH] rust: alloc: reject offline NUMA nodes in allocator Franklin-Qi
2026-11-20 9:47 ` Vlastimil Babka (SUSE) [this message]
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=73c18685-8115-4ee5-876d-a276902488aa@kernel.org \
--to=vbabka@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=georgeandrout13@gmail.com \
--cc=harry@kernel.org \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vitaly.wool@konsulko.se \
--cc=work@onurozkan.dev \
--cc=yusq77@gmail.com \
/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