From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795141056; b=1FwF6k84Uatq2E2b1jlLE4JY71Bn9R/IFYd5FK8nzt85FjWPBw+5VqdVHBBMxpjaZNYr ZBjF5ylUPfBWWFFudAAurRIp0e6aYJC4wSkRMoKSidjG57vGBZoL33z4dyp2bXLSLdCWc aoznmMXTRdtT/oITHqRJq4Vpx3RV0A5j71mvotj/YLyZokN4xbxfAuc2PpPPhzI8iisqh YkRKDgcn83SqtPz6Itw/HDyt3GPozLm7iZCJu8AlpEcVeFPFuQny9wsUauqUGNKt3kCR2 DUEOL+8JS15LAwLiw+rxkaKuoOoTEPr1ONCRsxPRlVtn1W6SaLtM2efNi84VVgLWqlw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795141056; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=Qrne1U4Gq2URgk+EKe+uNj5xFft/8oosPyNbOoW67yY=; b=Fny6dBXQmqGovGFTKPcqsh89wuFC1BbjdWUFSwTnBEoBYVqXuhblYyqmN7qyDo3tarXl gHor0Yvf3tzI6Xh1KJd5cHIH6nigt38dFJgTJzwJly1Ahq8OD7ysBdUBXg+gEfzVCMyHO OyPYKC4aGfJepfN4RPMBYGIb9u3+xjq4cBcaAFedRawP7ZTEA1kNCbMneeim3kTMPZmCd YLahMrjZsC2AMz+F4xt7KMZlGdoE0syxRT1ehcPOV2DV2flVK0hB8ClDM9uQ4O6K/xjuL /8MrlO6R9Y2+h6gaEC3qau2n1Q+0iaMxU3AExOR6TALtoVS343k7rj47H54p8b6i7sQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dk0wFmrb; arc=none smtp.remote-ip=209.85.214.174 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E721606A320 for ; Fri, 20 Nov 2026 02:17:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5E721606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dk0wFmrb Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2f0414c1062so2206675ad.2 for ; Thu, 19 Nov 2026 18:17:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795141055; x=1795745855; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Qrne1U4Gq2URgk+EKe+uNj5xFft/8oosPyNbOoW67yY=; b=dk0wFmrbOWHHA/sZMb1BuFyOgxGpiAiMvFQVB45s+uDstllAlf6cJIerjKVe2hT1u8 HFbF4W6Du4euIyp1k6G7BrLayOMBUxuX+sHDRyXSMLtfBeXnGwTzYzo1G6ZEE1J8Wtav RW5UcNb6YmJw98S9+GqnVGbGClgJO25945PdbKsmy4aosSw2xcJuKmBNL+SZHH6dwHIQ by1EEDkTGcYA+41idX6Thr5nbNaVhWQ4pTZBLkNYEsILqasoxo4dxy8MYsTPFp0oX0ls HujPzHoJ3eXdCDsCZodHmSAc80e+9DGhXtUSaxbwpwa0SExniobOtoKowV65sHxUmBRK nr1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795141055; x=1795745855; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Qrne1U4Gq2URgk+EKe+uNj5xFft/8oosPyNbOoW67yY=; b=2EtcHtqNs9YLjhFs6kL4CtfFtXMPbbBCsTow+xzaOhW0XgzTVCUbBGbfsMnbeoixRh MeSPRku3WRKBlOdoBXFLAjNogi5mvBLRf6+VVtWN/eeWrfrzlLUvNYvn8TFIFw3wGqAn K1rGCi8wVDUraNHQWq3CIAkKGcbOSNMF656hOThCIm9jHBh/E+jNHF1t04akLljKwBq6 Z9fT2cJTUGHLHDzd5WiQZy2dg5iGXi/qw6YwPw2/0oId9ibSkGvV1r4pg8E73BXsQ3e4 lpJkNg3+0YKg64F+rX7NwMMKFGODnMHxq6O4UlHZhn6cyj9vTnCq/B7mU0LBUHJ1Th7o qx4A== X-Gm-Message-State: APuU4Z9U7eH7ke5/s0SpVnPTx5duhGC1r1YjSFgmmu66CUab3Dn2ViG9 xooBfMLbP24AL6XgJkgmIOT33lfOTjzHEsHx9zS89aCT7vZgDVuuK8lt X-Gm-Gg: AZFdTZdjMCPKgcNRGh7LOkPOgD2WFafc1ACy7AraFhalQ/v+QebtfBODu5m35iE8ObR VFv6jmcqsWhiLL1vbuQA1r66g1ABJiAp/oxcJn5vs5EGUbD4IohBXrphFKGFurF0NixO/KipeLW SOBi8Gi2bdE5i7+DRY/Jl1EPPbCPDFNGdW92WTed2q0Bncz9UeigP6WteDO9oXT9WVpAN0/AlJc MB5mJnstL/Ba8pa/xL3KItscgwwK4Q4VDOIwOwM8CfCZlruLaNK8vsHqC7uwTZTW+3pl50WqnWE jz9TrCUJlnWzdfhqo3/m4AXOthv9ij3qqwEvlAw1b4MaqcmeUzFvlKnahIE2+OaWyQZQnNOj353 ULGVu2leBOe9tmc9DVdQupUkINK0I0OGbxpQyqmT1C1e/pWQKPLWUdFBGMba/TSmPq8gJhYoZ2N D9ukUcMGQl3Dgp3TP6nAwzfObkChgnid2mdUH0s3h8J3k5jcOIDixiaCK5dhsNLNmYFbuFe88Zj Nggv0+7LUnMhy/qqvjRmyv4OPLwcuG5bpf6w/j5eTVUOcc3X5yLLm8uV5rgcLKUpHUkjBzzDQKt Gy2d/y8K9QUM3aM63LM4yO0vovD70FAImZ3oW8HQRyb+G5H8colVUsAmTyE= X-Received: by 2002:a17:90b:2c84:b0:3a5:c08:4c41 with SMTP id 98e67ed59e1d1-3b41c98a138mr1104076a91.50.1795141054397; Thu, 19 Nov 2026 18:17:34 -0800 (PST) Received: from ysq-QiTianM428-A376 ([111.201.209.250]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41cfbaf2bsm708563a91.2.2026.11.19.18.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 18:17:33 -0800 (PST) From: Franklin-Qi To: Miguel Ojeda , Danilo Krummrich , Alice Ryhl , Vlastimil Babka Cc: rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?UTF-8?q?Onur=20=C3=96zkan?= , Lorenzo Stoakes , "Liam R . Howlett" , Uladzislau Rezki , Harry Yoo , Georgios Androutsopoulos , Vitaly Wool , stable@vger.kernel.org, Franklin-Qi Subject: [PATCH] rust: alloc: reject offline NUMA nodes in allocator Date: Fri, 20 Nov 2026 10:16:29 +0800 Message-ID: <20261120021633.12274-1-yusq77@gmail.com> X-Mailer: git-send-email 2.55.0 X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Fixes: 7760b6421b6c ("rust: add support for NUMA ids in allocations") Cc: stable@vger.kernel.org Reported-by: Georgios Androutsopoulos Closes: https://github.com/Rust-for-Linux/linux/issues/1263 Signed-off-by: Franklin-Qi --- 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 +#include #include __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, 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`. -- 2.55.0