From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83B2DD711B0 for ; Wed, 20 Nov 2024 15:13:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 18AFF6B008A; Wed, 20 Nov 2024 10:13:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 113F66B008C; Wed, 20 Nov 2024 10:13:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0026E6B0092; Wed, 20 Nov 2024 10:13:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DC9516B008A for ; Wed, 20 Nov 2024 10:13:35 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 902AE140D94 for ; Wed, 20 Nov 2024 15:13:35 +0000 (UTC) X-FDA: 82806813978.17.3FA390C Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf27.hostedemail.com (Postfix) with ESMTP id CF8FD4000A for ; Wed, 20 Nov 2024 15:12:38 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=uMZdtdQ+; dkim=pass header.d=linutronix.de header.s=2020e header.b=EoHW11c0; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf27.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732115429; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EyO8yv8V4ueZfLiOBMizzmpe+ea8iyO25drixQuoPIY=; b=Fkyeon2ejcU4tg1OZa/N73CS73ZNHx+52zQmscB4SkyfpRGyVz4wqMZqSvkqOezOTNqvf3 x9lIc3wSbg07wyxFfjkScD1AD8N6b/VKM4Xsdy+XCNPTvjO81VgONAL1BDHPHWgxGN8Udi YnttBQzVShT2MSv1D/RZKbwX5SROn1E= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=uMZdtdQ+; dkim=pass header.d=linutronix.de header.s=2020e header.b=EoHW11c0; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf27.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732115429; a=rsa-sha256; cv=none; b=bb18EiwDp3NCVXT6U5hjl0MICgLu5plXh/R7vaS7mBNGA0+X5pcBr5uH14Fkm9o42c5qUd ++RaDVkEbwPiBcaypMShTHIZ6kBfluSExFn16Ri2YlT4k7qF3nXbioYsLnGPaHjynio372 DJnXS+m1Odp2ZkQjxFlPHIgRZbRUOlU= Date: Wed, 20 Nov 2024 16:13:28 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1732115611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EyO8yv8V4ueZfLiOBMizzmpe+ea8iyO25drixQuoPIY=; b=uMZdtdQ+edsln1z1OlicaONMvdN6iaesn6y5qYMjSZI7zi0tDxUL0YBV7ddareJwzQI/KR AvLUM75RMybwKoeCNOiAHLYEyqYErHxfTYRuo4S6eCCWT33N5dj3BeMYptcDeXd0RQL4w8 zxtS6gcUUd/ingmnljT+0NIlDDp2SkBcW9HdNTnZEmFQBTOyS8A/72IYiuAo9qva+TKKrR e4hGBeNNpLi29j11uiCVoOme1HZtkBCMmzFO9GfW7vUTyXiG+YBiUZ3TsfRKrkM1IDTIKI QH/ex2DWgFdIKv2mM5yde+YErwNjC9aXvQKU6Md1kCJ7zldXcJMKE0KdViN+cQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1732115611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EyO8yv8V4ueZfLiOBMizzmpe+ea8iyO25drixQuoPIY=; b=EoHW11c0n63ekpk9SHmSTus4WuhhFTe/zue9FX/KIpRWzURrr0p2m0qeLAokfkGLfcTcwb W5f5t2S9QTMY5LDg== From: Thomas Weissschuh To: Catalin Marinas Cc: Alessandro Carminati , Andrew Morton , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Alessandro Carminati , Juri Lelli , Gabriele Paoloni , Eric Chanudet Subject: Re: [PATCH] mm/kmemleak: Fix sleeping function called from invalid context in kmemleak_seq_show Message-ID: <20241120160448-11661c83-6a2e-4afb-9711-ffec3f9342b5@linutronix.de> References: <20241120102325.3538-1-acarmina@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CF8FD4000A X-Stat-Signature: uspc7uect4ggob665u5jrun39xh6jk6s X-Rspam-User: X-HE-Tag: 1732115558-769812 X-HE-Meta: U2FsdGVkX18rxDXvYoMc0igCDKeKrE1ZOVcFw9SRNkRv+QTJ2grWsZmSV4mXCP1e4HDaqPpQK7dNzh4BxxruLH3RuXbH2NmxVSJQ/dXpc39b8HmrMxXKW90TxU7g94zBY0SAeiR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8dVXmcWqfxC2CKyx8IiOZ0RFzz1kUz6Zms+84YeKNvkEybsIIh3bpZMkSK7dIH7SZK19YBQLzA7RBXkLjneesT8Pp9BUHCec1Jfv3MoTbVGXANUnMCoz0wkglF/31XBBNGpFXaRf9X6+G/0u3ZjaVEgyDc3vp9rwHpCvXpqI5XDyXu+GiYv8VpXNT+joPcbEjB9zhIn3A+VHxje7y7E+aSnf0sXgWWi5RV6OhtXpYumS3k6A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Nov 20, 2024 at 02:53:13PM +0000, Catalin Marinas wrote: > On Wed, Nov 20, 2024 at 10:23:25AM +0000, Alessandro Carminati wrote: > > This patch addresses a bug in the RT variant of the kernel where a > > "sleeping function called from invalid context" warning may occur in > > kmemleak_seq_show under specific conditions: > > - CONFIG_PREEMPT_RT=y > > - SELinux is the LSM for the system > > - `kptr_restrict` is set to 1. > > - The kmemleak buffer contains at least one item. > > > > Commit 8c96f1bc6fc49c724c4cdd22d3e99260263b7384 ("mm/kmemleak: turn > > kmemleak_lock and object->lock to raw_spinlock_t") introduced a change > > where kmemleak_seq_show is executed in atomic context within the RT kernel. > > However, the SELinux capability check within this function flow still > > relies on regular spinlocks, leading to potential race conditions that > > trigger the error when printing the kmemleak backtrace. > > > > To resolve this, the backtrace printing has been moved out of the critical > > section. [..] > What I don't fully understand - is this a problem with any seq_printf() > or just the backtrace pointers from the stack depot that trigger this > issue? I guess it's something to do with restricted pointers but I'm not > familiar with the PREEMPT_RT concepts. It would be good to explain, > ideally both in the commit log and a comment in the code, why we only > need to do this for the stack dump. Yes, this is a problem for all users of lib/vsprintf.c. I am working on a fix for this, to avoid calling the sleeping functions from contexts which are not allowed to do so. In these cases the pointers would not be printed. This fix for kmemleak is still needed as the pointers in the kmemleak report are useful. Thomas