From nobody Mon Feb 9 03:30:27 2026 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 7371A2DC349 for ; Tue, 13 Jan 2026 15:07:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768316843; cv=none; b=dr6xOf78oDATGBruE89aODfeJ6ysUrW1d30c/nuV77zGKlqeGII9Q/sM0tOOtq2rfERThzecv+vvR4utw0Sjpgn5p/e4bSx0C6CR+x5W8sX30cdCHPmpUV/+3h06IYXvEwEVqzBEU4YTTYzMhaOiBCML53WYMUT2zAwOMUnVOeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768316843; c=relaxed/simple; bh=bVPIfKS/5fXxENMewaVZzRevyuDMEikMCDmxAN/yMPk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Gq0T4bU2f68kx89KszN2W0ClI0NhPnLNKrBGzPREmlFULjK3Vers93k4ubmeJtgNoo31kkbfJoPzhq/x39mviC3tlfSuNrTdAN74njeUhdQxEbEFA4YM890sHyacYl3FP1pZQOuNioxgwPDYwuqr/J7p+iX6h5gJLxiNli8z6Kc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TOwTFOvO; arc=none smtp.client-ip=209.85.216.50 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.b="TOwTFOvO" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-34c213f7690so5102065a91.2 for ; Tue, 13 Jan 2026 07:07:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768316841; x=1768921641; 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; bh=DQnWPRxNH9q72zgZ6FoCl23Dsj1j6a70O0K1DDg0+mo=; b=TOwTFOvOcnYLGRdbwDdGeHsPjRnHoNXPpj/AEWbLAhKL/EQNBZb8T3xuHqF4wZFqY7 jvJndT4dgo1ZBiVbiXUZ2eCnYsohYOarIhwOx5XgGCsSgtxyuoHhiWrQur9a/ZxZb7WM pQdIHk8dvTNA/OvxO59Rm7PUX5eSrAQ191J2fRbo/blInhcSwWXaqGhVNFXnLux+SQrx lNk2G3lRn49Rwb71U4sd1NtVMJ+FDtzE2G9TmUdLLT7bBoLq4VRR/acO1vfkw6BsLoFz lEoNY7e0ItsEqTqtt1UnkX9UJy3hp5lZsKlC2pHKazFN5fw3kpIVA1ex+75wJa2T5U2x jrpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768316841; x=1768921641; 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; bh=DQnWPRxNH9q72zgZ6FoCl23Dsj1j6a70O0K1DDg0+mo=; b=Ad84X3ZZmUvv0JjA1o6W1tgTiveqpUiuZZsmO9jh7KaQ7Bef3s+zgLAjrCnuEccPdg xZAnHY3t9H/B5eWz0aM+uBvnQsJj21wafzqYsVaQMPUNuq/2VE0aJv2KFWWn7Cr0k1Hn 1I3AMwJDnYHyxta5wy6Aq5+D+b9VBPlz+4W8Vq4oBLPBK1AeX3IhgxCOOQOC2OJU0Olr IlpPIfcMfHTIsw/wsCgsqLFey6xb3mW4o8ThE8g8zRfLVmEy2yGJ+0mI0gTwK4Klza18 2Yvj8jB6He+YSQJSHHCXs/MR0qpo9h2gPWdAFJq35hrdRuNHu2TEKbOS4yih8suAgNAG 1Qcw== X-Forwarded-Encrypted: i=1; AJvYcCWVLfW6xeXO1VZ3pOnDInf8X+f5a8FhbtHKV93K+0wLLZMVYW8I7op7f6TGF9OtR2eDITVVQKt/+y0rnrQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzpeY5gncN8M+u46lAYoOtVQNO+h+P6Mt0IxTyNQQeQWz8motgq b9DtisSpgpTijFvBzvlEf/QHy8hn9+opYebpaib3wLWiEsa6IVEnNtSa X-Gm-Gg: AY/fxX5cknBbhmP1RHiU/KsMobJXJMkZJjXPKxvQgb69YML3lK7KCkCi1NRCYkGBWWF IMZC2d8jrzufz0S6Opgr7oW90CnZ6RYOSn/7QKY4CzgoQK30yhlmBwkzn1EGuTP0shHh8n/+B0Y Mz1U4jpsW5G/D+LHNWeJIt6L9gRHf66CV1gIVAkSCSWNURhsbGMPquWKgf1B7cir/C8A8/EGEwH npZvcoq/CaEmuDpcYrnfYvYW5tAshtXWPmM/7Wovb24reKwnWp2ISieQBTyWVg2KRZx27arTqTJ IqSRc//3ZZsOKJyVv8oCMN/i5F+sKlhVNCGAw4/AjcwnsdTUxQRbNjSB/UVpJZo67Ayr9UnSUhV J1DHJ0FX30cwwE1L8SOH7xkWK3fR9Q0ja7MIw2kIHobE/elyBZBQ7V5d/JedT03ngjUR8kiYOMn R4BcjaU/xXucbQgAy7Op6wwFXDpKBR X-Google-Smtp-Source: AGHT+IHKPSJ8kXxnj8Kql9+bODbOjeYJ8UeB1XiJVxthrhBSw85O6NRJi1luNAgVbTgInY27JkJcvw== X-Received: by 2002:a17:90b:3c09:b0:34c:2db6:57f1 with SMTP id 98e67ed59e1d1-34f68c28425mr17392421a91.30.1768316840509; Tue, 13 Jan 2026 07:07:20 -0800 (PST) Received: from LilGuy ([2409:40c2:1000:ae08:9f24:c96f:d20:3f76]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-34f5fb7419csm20596125a91.13.2026.01.13.07.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 07:07:20 -0800 (PST) From: Swaraj Gaikwad To: Vlastimil Babka , Andrew Morton , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , linux-mm@kvack.org (open list:SLAB ALLOCATOR), linux-kernel@vger.kernel.org (open list), linux-rt-devel@lists.linux.dev (open list:Real-time Linux (PREEMPT_RT):Keyword:PREEMPT_RT) Cc: skhan@linuxfoundation.org, david.hunter.linux@gmail.com, Swaraj Gaikwad , syzbot+b1546ad4a95331b2101e@syzkaller.appspotmail.com Subject: [PATCH v2] slab: fix kmalloc_nolock() context check for PREEMPT_RT Date: Tue, 13 Jan 2026 20:36:39 +0530 Message-ID: <20260113150639.48407-1-swarajgaikwad1925@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On PREEMPT_RT kernels, local_lock becomes a sleeping lock. The current check in kmalloc_nolock() only verifies we're not in NMI or hard IRQ context, but misses the case where preemption is disabled. When a BPF program runs from a tracepoint with preemption disabled (preempt_count > 0), kmalloc_nolock() proceeds to call local_lock_irqsave() which attempts to acquire a sleeping lock, triggering: BUG: sleeping function called from invalid context in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 6128 preempt_count: 2, expected: 0 Fix this by checking !preemptible() on PREEMPT_RT, which directly expresses the constraint that we cannot take a sleeping lock when preemption is disabled. This encompasses the previous checks for NMI and hard IRQ contexts while also catching cases where preemption is disabled. Fixes: af92793e52c3 ("slab: Introduce kmalloc_nolock() and kfree_nolock().") Reported-by: syzbot+b1546ad4a95331b2101e@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Db1546ad4a95331b2101e Signed-off-by: Swaraj Gaikwad Acked-by: Alexei Starovoitov Acked-by: Harry Yoo Acked-by: Sebastian Andrzej Siewior --- Changes in v2: - Simplified condition from (in_nmi() || in_hardirq() || preempt_count()) to !preemptible() as suggested by Luis Claudio R. Goncalves and agreed by Vlastimil Babka - Updated comment to reflect the more descriptive check Tested by building with syz config and running the syzbot reproducer - kernel no longer crashes. mm/slub.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 2acce22590f8..642f4744d5c6 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5689,8 +5689,12 @@ void *kmalloc_nolock_noprof(size_t size, gfp_t gfp_f= lags, int node) if (unlikely(!size)) return ZERO_SIZE_PTR; - if (IS_ENABLED(CONFIG_PREEMPT_RT) && (in_nmi() || in_hardirq())) - /* kmalloc_nolock() in PREEMPT_RT is not supported from irq */ + if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible()) + /* + * kmalloc_nolock() in PREEMPT_RT is not supported from + * non-preemptible context because local_lock becomes a + * sleeping lock on RT. + */ return NULL; retry: if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) base-commit: 559e608c46553c107dbba19dae0854af7b219400 -- 2.52.0