From nobody Sat Jul 25 17:33:47 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C77EA3CE083 for ; Wed, 15 Jul 2026 09:04:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784106250; cv=none; b=efR0pbl1oBF2oZ67gz7VdhHpr7pXb7JcrZ49tdyu2ynVyC0Nx1IU75Xi9r1VN2wj7m8sxKpe52dKdWEiQyea+Wrm0ihX+11+U+8RY4zTclexuejycNwBt1hj+eysU451X0UNPmDvSYj9uhpJ3qrhSP9+Q7wp9OuC5GIZp5PFAQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784106250; c=relaxed/simple; bh=7eoePbvSqh0YaMS9xWVd9GuaJ5G8xU8vZn5SQIU+NqI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sWzAkXqFGsiQj1cNGdM1R668tbnZtWUsUNCC6W1VRWcCqFWHbLE+uYhvaW2IbzvN2RzULKCKwlaF++vNskd7Tj0lzSSFY9VHmHYXA5gIOhHzQGS2fb7pqYlJcinA9pBW7Foqzw2kHd6LFbuxOkGPZ4t5xMitWdnaKsPvWNhv2Xo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dEndOrBD; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dEndOrBD" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-493dc8408fdso15629755e9.1 for ; Wed, 15 Jul 2026 02:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784106243; x=1784711043; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=JV1FEY2WoHNNRK+gCNUw7lvhLp/1mE5IHJqYJCHXcJw=; b=dEndOrBDjXdDQDuY4c2uOy8vgPtDVHtDVoA5i3Lqpe3B9B9br3fbUzSGuGVurJDl8a Lou8ssTpV4ZMwe4Dz79hn9dqxkrzU0NEwacgKmhNfRgMA72Sgn9/bKh81KjlCW8D4PZY L3XObJK87lQ1lPly1EJHTlSNiWpfxlzmBSXl+NwPjI3RMjtD3vnG0wTXTOuvKlOseoaM KH9MaLUzFLlDIKnMGqTnW9j2WyXJnIOvGDEbgxN9+eMvRvYWNgFiNMTGL5b+ApWsMyGp t/T1xsxHCvS1zEABOOrr5Ed03xWMiOcZ3JuacetNXBX8Znd+8tT5vJN50I8Ihya/vx9t HQRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784106243; x=1784711043; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JV1FEY2WoHNNRK+gCNUw7lvhLp/1mE5IHJqYJCHXcJw=; b=dsvmK2kS/ctR+3N+pVLv+QbO0GQVTpVsrBsrmYts4wZlk6uLcrJvSbfgf9IkyK5nSc ze1gz5kTcp/RiiijqtjF/MbGQ8YZqesVcoIYhSHuu1fqWIrY8MLmbQ8t0E7+lljQ9XOn ERniAnuprFqGvaC5uYGI3iCoBLUdcYFXOXum56QrLxEobj3+IflH4v8i9yy00wQZgpPS /hZOUV56SLLOGJO8jS1LlWPJImuw3sDkIHraCrFbhYtzF6r3+peQ5Al8ZQMIOzhvLUnO dN1yrAc8+mY3X3KdkuZuwWMVizDZQPD8kAhETP0QEBSOLS0vpJyCxdtw7U1yWbvU214X +aIQ== X-Forwarded-Encrypted: i=1; AHgh+RoioYeMRiKREi4jauarUJ/XntplYgL8ZlwxitMJ3lsxlMhketYf1moIbxqZ7Slfr4XDicRgULHcKE0yE08=@vger.kernel.org X-Gm-Message-State: AOJu0YzZ17gEPkWvq/JFUqU7RtYmlqvqFVVqiFm0bGaFoyVUPJ7WMQ7J d7cKbEM8LdUOTf7vEMPzGtvKG/wv45AgfkmxKQ16clQxffUhch0INibyPI/mXM03sJTxIq2ezVb KpaTAJmp2ewxXeg== X-Received: from wmqe20.prod.google.com ([2002:a05:600c:4e54:b0:493:b719:1145]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1d15:b0:493:ee2b:c8c7 with SMTP id 5b1f17b1804b1-493f87d5819mr160649475e9.4.1784106242700; Wed, 15 Jul 2026 02:04:02 -0700 (PDT) Date: Wed, 15 Jul 2026 09:03:58 +0000 In-Reply-To: <20260715-alloc-nolock-fixes-v1-0-fadc49952dda@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260715-alloc-nolock-fixes-v1-0-fadc49952dda@google.com> X-Mailer: b4 0.15.2 Message-ID: <20260715-alloc-nolock-fixes-v1-1-fadc49952dda@google.com> Subject: [PATCH 1/2] mm/page_alloc: don't spin_trylock() in NMI on UP From: Brendan Jackman To: Andrew Morton , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Johannes Weiner , Zi Yan , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Harry Yoo , Shakeel Butt Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Brendan Jackman , sashiko-bot@kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable As noted in can_spin_trylock(), using this is unsafe in this context. commit 620b46ed6ae17 ("mm/page_alloc: return NULL early from alloc_frozen_pages_nolock() in NMI on UP") fixed this on the alloc side but missed the free side. Impact: If BPF programs using these features in NMI (probably tracing) are present on non-SMP builds this might crash the kernel and is probably exploitable by local attackers for privilege escalation. Reported-by: sashiko-bot@kernel.org Link: https://sashiko.dev/#/patchset/20260703-alloc-trylock-v5-0-c87b714e19= d3%40google.com?part=3D18 Cc: stable@vger.kernel.org Fixes: 8c57b687e8331 ("mm, bpf: Introduce free_pages_nolock()") Signed-off-by: Brendan Jackman Reviewed-by: Harry Yoo (Oracle) Reviewed-by: Vlastimil Babka (SUSE) --- mm/page_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index af63558391345..5f9873dfccc5a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2979,8 +2979,7 @@ static void __free_frozen_pages(struct page *page, un= signed int order, migratetype =3D MIGRATE_MOVABLE; } =20 - if (unlikely((fpi_flags & FPI_TRYLOCK) && IS_ENABLED(CONFIG_PREEMPT_RT) - && (in_nmi() || in_hardirq()))) { + if (unlikely((fpi_flags & FPI_TRYLOCK) && !can_spin_trylock())) { add_page_to_zone_llist(zone, page, order); return; } --=20 2.54.0 From nobody Sat Jul 25 17:33:47 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DB853EB11D for ; Wed, 15 Jul 2026 09:04:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784106253; cv=none; b=soOO044b2716vRXqK4OtLKLIxVP1Bfm4nUED3mGwbjLuNm5j9X3yFQyHm3QEcCKIpqF6sdFsFsBKluVw1nigiXXJ8JWcDL1FOSyJvlR7ZsGZ7b4qd5CyHUF3KiOMy0wb3OxCTZ7DwxjS0+S2qY2d7kVRop/5lm0GJsM4JE8Jx5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784106253; c=relaxed/simple; bh=T132sxp6UaJ+WwsQy/GiXCN6xCpAzZ0KSvradejtUNI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XQRkzH66kzFh7AwQ0B0jFW3eBZZqy8xVR0lKaeTmLWyG1SO/doJnmweSatsAGSOtvufetfyRIrm7V0Rc49p/BUjI3hQat6K9C+n+PBOFgRRGnNaZvrQDb6vgwOiB/keXPRUul39mLi9ZkRr1V5s2wuiSlKm0g81Ooh5XcSjok64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ErZCpzGg; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ErZCpzGg" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-493b21b1fe8so16787185e9.0 for ; Wed, 15 Jul 2026 02:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784106245; x=1784711045; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tAjEggZE5XRXoCbkcOS6/MLSgIQDuHRdiYiNvUA8HH0=; b=ErZCpzGgMGRZa9gNKYXx4yIMAVdYtEgDoNT1B0eNQDRZPo09BtN/32Wc6YLMTd8TKF 7qiuo3KBS1aIdDufYifiliP1CIJzzrhqKlpD2+h13w4JkrIBxNZSYqHzg1fHXeREwSXc EbXhLiz6oVNxkdnu8H/hZ1zWyHOLmSYk984tnPFi88G2NloROxarRtz9/AlJvT1SgHaq Q7pfHJTrjWrpWker0/QIMpWMpK3NjEWuHJJ45WUrOYQ9+DKZ9+MqaLeKpI/RmQ+5wAyO rfRcRxJDzYsGfiTcnzxJ8qtr8MmPFaTJK1L8x5/FUuqNi/hzssROPAOkltOvgT8aKqOW AxUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784106245; x=1784711045; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tAjEggZE5XRXoCbkcOS6/MLSgIQDuHRdiYiNvUA8HH0=; b=BdXhfLzGXR8+ochYZ0Ku1HhyAvM8CAz3m7NBdLPRSBvALleCqF3q1aW6OHEkEcpFl5 D83QhXVEZiBnDdNKsDF/E3m5DBjKJoib3a73mgtw70ixfyUWZOPsV30KxPVgt2dI7xOp bg1xOsCZhmxiGG3IXnHnozk5YuMELA5MfHbGOjDeu5Obw8oBgtu0zpNmzr9Hn6F6z93v lCMyRmhVq7xjhmS1U5M6vWa+lmpCKIJ70M/b2ZAmZdJGBOiZgrF1kGKxys2aSYing4Bz wWJPYXg/aed0GZHW7QKV5NfhJpeYm3ErXvn/D9606LBGbofxn1ULQD1Q2q8/YNSenEW9 VtZg== X-Forwarded-Encrypted: i=1; AHgh+Rot6+XWaLxfo57KFwt3WpQ0Oc7bDo1VZeVJFuOncC7AR7P1dEH+xBGk+ZVNpmhu/i6kfZbs7++kNy9BRX4=@vger.kernel.org X-Gm-Message-State: AOJu0YzNSra3BEu34+Tms/QizqacNdUtoIDNYYovzMBUtK9LPqRwzIV8 sH5/uXtZQE3WidXExCAz2NSVkQS06HUKKEy8+F0moZDn9JBZri7NQjjVBcp/6KFO4h1JIAhdOZF q3lAvhjFdNYvoVQ== X-Received: from wmby15.prod.google.com ([2002:a05:600c:c04f:b0:493:bdba:620b]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8217:b0:495:3c6d:f294 with SMTP id 5b1f17b1804b1-4953cbdc7e6mr20439975e9.23.1784106244314; Wed, 15 Jul 2026 02:04:04 -0700 (PDT) Date: Wed, 15 Jul 2026 09:03:59 +0000 In-Reply-To: <20260715-alloc-nolock-fixes-v1-0-fadc49952dda@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260715-alloc-nolock-fixes-v1-0-fadc49952dda@google.com> X-Mailer: b4 0.15.2 Message-ID: <20260715-alloc-nolock-fixes-v1-2-fadc49952dda@google.com> Subject: [PATCH 2/2] mm/page_alloc: don't spin_trylock() when disallowed in free_one_page() From: Brendan Jackman To: Andrew Morton , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Johannes Weiner , Zi Yan , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Harry Yoo , Shakeel Butt Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Brendan Jackman , sashiko-bot@kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable __free_frozen_pages() checks can_spin_trylock() before entering into the main free_frozen_page_commit()/free_one_page() path, but before this it can get to free_one_page() via the !pcp_allowed_order() and MIGRATE_ISOLATE paths. The !pcp_allowed_order() path depends on usage by callers so might not be possible in practice. The MIGRATE_ISOLATE path probably means kernel crashes and privilege escalation if anyone ever did memory hotplug and BPF tracing on a PREEMPT_RT or !SMP build. Cc: stable@vger.kernel.org Fixes: 8c57b687e8331 ("mm, bpf: Introduce free_pages_nolock()") Reported-by: sashiko-bot@kernel.org Link: https://sashiko.dev/#/patchset/20260710-spin-trylock-followup-v1-0-af= fb5fe5ed00%40google.com?part=3D2 Signed-off-by: Brendan Jackman Reviewed-by: Harry Yoo (Oracle) Reviewed-by: Vlastimil Babka (SUSE) --- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 5f9873dfccc5a..46e5ea59c71df 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1559,7 +1559,7 @@ static void free_one_page(struct zone *zone, struct p= age *page, unsigned long flags; =20 if (unlikely(fpi_flags & FPI_TRYLOCK)) { - if (!spin_trylock_irqsave(&zone->lock, flags)) { + if (!can_spin_trylock() || !spin_trylock_irqsave(&zone->lock, flags)) { add_page_to_zone_llist(zone, page, order); return; } --=20 2.54.0