From mboxrd@z Thu Jan 1 00:00:00 1970 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" 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-c87b714e19d3%40google.com?part=18 Cc: stable@vger.kernel.org Fixes: 8c57b687e8331 ("mm, bpf: Introduce free_pages_nolock()") Signed-off-by: Brendan Jackman --- 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, unsigned int order, migratetype = MIGRATE_MOVABLE; } - 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; } -- 2.54.0