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 CDBE2D59D90 for ; Tue, 26 Nov 2024 10:49:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41E356B0083; Tue, 26 Nov 2024 05:49:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A6506B0085; Tue, 26 Nov 2024 05:49:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2205D6B0088; Tue, 26 Nov 2024 05:49:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F20B26B0083 for ; Tue, 26 Nov 2024 05:49:34 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6EC04140CDE for ; Tue, 26 Nov 2024 10:49:34 +0000 (UTC) X-FDA: 82827924858.19.2AF4E91 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf02.hostedemail.com (Postfix) with ESMTP id AED4580017 for ; Tue, 26 Nov 2024 10:49:24 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf02.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732618169; a=rsa-sha256; cv=none; b=ijJypZsPqLeZ7JMW6hFQWP5nopzTB0XhQYorrmAA24DUL24+sJB6U9KYqzb0dI73Um05E/ rAZ44aYnDIb6LQEZZRIIQkdTWCXZAdO+oXpIyhXsQna62rpx3tJoYJ9P53sUWbu8xFQPpN ZkUHxWelLpG/Wip9qAEHvxnCcWXfRAY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf02.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732618169; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dCdcStUXFBDB4g1gGtfaKDhBS9QAkkF2vXvGZYFefTE=; b=PQ/VfQ5rIDLKtu2qm57e21I3m4+2YgIaA88SClk/Q5AvDesZd5AiJ103JCJiZl5EiyeusQ bJuVkZJos4XItnQR0/KipHsOJFCsGZGV8RXP97TYb0idywTfWPaDcj5UtuH9LGIi4dEvwJ K4EdmGnlVpjYb2VrSxzoEd4/zmwwehk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 0650BA41BCF; Tue, 26 Nov 2024 10:47:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40926C4CECF; Tue, 26 Nov 2024 10:49:29 +0000 (UTC) Date: Tue, 26 Nov 2024 10:49:26 +0000 From: Catalin Marinas To: Thomas Weissschuh Cc: Alessandro Carminati , Sebastian Andrzej Siewior , Steven Rostedt , Andrew Morton , Clark Williams , 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: References: <20241120102325.3538-1-acarmina@redhat.com> <20241120102602.3e17f2d5@gandalf.local.home> <20241120164043.T1JuBALe@linutronix.de> <20241121170356.eC7f3-1v@linutronix.de> <20241126090438-dfd305cb-3736-4d31-a690-4d00208783d5@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20241126090438-dfd305cb-3736-4d31-a690-4d00208783d5@linutronix.de> X-Rspamd-Queue-Id: AED4580017 X-Stat-Signature: gk456rz8xohtfzc8u4pd7sg8naonhtds X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732618164-347405 X-HE-Meta: U2FsdGVkX1/ppuQYjZnDqEVU5D4S3Q7ljCMyK08wwOKKksvhU5wr3+ih8aXHtD93Gs9znRUMjWWC9qMCfTlx7CwQfTqPvZhRncwUXlvjyhSM9VLz7guE8LG48QkMomw9VUSvAatrA1OL5bXjvlKfwY7O9E49b9yimh74nJfPxUfCbWNXGIIRLRiDMM+WMYyUm/mMpg+RJkC8+e7xLSbf0ImW+zDLINQ7Wr1WvyytP/k2tMZdPhzhXbn6UCnOD5qdnhKCTXC5c7BxuK9DIaW7aWj3zOOXV+y2Z/sXpsDB6iuV3CRpoR3hF6MouuDwneYdo2vQtjKFRtH13wlV65a6nCyf/e7wnZ1gwYLsr/mYx3LkgV7Eu6ivCPQzYEuLK5ncRFxWBynebyyI4Hqi+wr+GTz/3ygxtBMYUewTV5qNnheIes5FK4NI4lUW3xRIqM8MwX+72dRYGBpCO4IVLPCqVaywj/z1Np27g/uDqOwZsRd8Nlcqbr7tBEWjbJKQZ8BKNpbYVu22sEfXskV0jnzGLCTzyBhnHbuwEpecOjgQkDK6+CnRXjx70s9g7yZuIB060rTdP92UpN60IZAac2d7blayfqBYvMIXEmZfx3YJcTfksmR6M4yfVEtun/kZd/GS6z6INWpmuB0+OjJQr/SZCIpcPsM3kNAmEPgZzl3NS23CMtUgMQ9GSp4I8b/svwFPi5A8sKsBD6HzUnzVGXs2CNwUkN7YSQwRIYgu8cE3/xW6YzV4UThihFoabkjJ5Pbup2+tUcJj8NGb6chHjEmAURo1ltG9aPfsLqxwolrO1N/kly4vTot9RI2MBrcOvrAGbNMDNEfSD10bPWdGlgVHMwQMBL9qBLt+F0Tj9n9LXJ6PI7BsyNJ/ohWiymOvGAWmPt4+EITyC5goJY8m1Lx7SzJDDO4Fwm6391wn+gOpF/vtMTeVeqAAmwKvtL1FkBmvPMR4jOn9gyn5Ssi0MGx ZYepAW5p BW1OrTjGijtrIEF1azjvshD38hRForLfOXJXrOB6iXKvczwaQYgavigqIq8wYT2rPV5WFqlRp/6kr6qUQfjTEKtmzupv2mHrKdsjQJ+gdDwgiQtPRg/cnVoAvoPAzWm735OPWuKv23Ib2Oc1m2FLx2M9Huvi99kkrvhhJ0RBKsEOZuE3Kt/zhFYi8KrAH+TncbaBDwoQVtHjLiLWToPa/TKm069ATMxY8lr81sCh6ovzL8xt+S6LBVK+aavnN1sSzby0A1u3G0O089wCtX3K0G819A7eVGNiG72JccSDuPfJEKQpssbbuqRCPzvJ6G7HdH21C1PAxfhE8cPKbEW3cB47PzUAAv8wyqO4Fw4pZRKYDDmitRVTqHzpJXuEyW5Ev8WQZ6l4P4woTuioxWMRp/HkHW6Nbm7FDl6+ctzlXEyOx5IbNhbCeMwuviZe/mcFpjRrsfbcOslY5KEr/tcRU+2I42zPHf9IBvjEb9DlzogwvsrA= 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 Tue, Nov 26, 2024 at 09:11:31AM +0100, Thomas Weissschuh wrote: > On Fri, Nov 22, 2024 at 11:48:04AM +0100, Alessandro Carminati wrote: > > On Thu, Nov 21, 2024 at 6:04 PM Sebastian Andrzej Siewior > > wrote: > > > On 2024-11-21 17:50:06 [+0100], Alessandro Carminati wrote: > > > > On Wed, Nov 20, 2024 at 5:40 PM Sebastian Andrzej Siewior > > > > wrote: > > > > > > > > > > On 2024-11-20 10:26:02 [-0500], Steven Rostedt wrote: > > > > > > The "%pK" dereferences a pointer and there's some SELinux hooks attached to > > > > > > that code. The problem is that the SELinux hooks take spinlocks. This would > > > > > > not have been an issue if it wasn't for that "%pK" in the format. > > > > > > > > > > That is missing check and I think Thomas Weissschuh wanted to add it. So > > > > > we don't call into selinux. > > > > > > > > Your comment confuses me a bit, as I'm unsure what Thomas is actually > > > > working on. > > > > Am I correct in assuming he's addressing a fix in lib/vsprintf.c to ensure > > > > that sleeping functions aren't called, allowing these functions to work in > > > > any context? > > > > > > restricted_pointer() has a check for in_hardirq() among others. This > > > needs an additional PREEMPT_RT check. > > > I would be actual in favour to get rid of case 1 for kptr_restrict and > > > have either 0 or 2. > > > > > > > However, his mention of "This fix for kmemleak is still needed as the > > > > pointers in the kmemleak report are useful" adds to my confusion. > > > > Meanwhile, Steven suggests reworking SELinux to resolve the issue. > > > > Could you clarify what you mean by "So we don't call into selinux"? > > > > > > This getting out of hand. By adding the PREEMPT_RT check to > > > restricted_pointer() we don't call in selinux so the problem is gone. > > > > I am really glad that now we have a clear solution, however practically > > speaking is Thomas working on such a patch or is he working on something > > related that does not fully solve the problem? > > I am working on a change to lib/vsprintf.c. Something like the > following: > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index c5e2ec9303c5..54ad175a22bd 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -870,6 +870,9 @@ char *restricted_pointer(char *buf, char *end, const void *ptr, > return error_string(buf, end, "pK-error", spec); > } > > + if (IS_ENABLED(CONFIG_PREEMPT_RT) && ...) > + return error_string(buf, end, "pK-error", spec); > + > /* > * Only print the real pointer value if the current > * process has CAP_SYSLOG and is running with the > > > Hoping to replace the ... with something that can detect actual > problematic situations at runtime. > I'm fairly new to PREEMPT_RT so need to do some digging. > > > Even if he is working on a partial solution, I am happy to coordinate > > off-list working on his own private branch > > (or else I would just give up and review the Thomas' patchset when it is > > out...) > > Given that there is no direct interaction between your kmemleak patches > and the vsprintf ones I don't think coordination is necessary. > I'll Cc you for review. > > Please do go ahead with your kmemleak patches. If the above fixes the kmemleak warnings by not triggering a call into SELinux, I'd rather not change kmemleak. I don't know how important it is to run kmemleak with kptr_restrict=1 and get meaningful pointers. -- Catalin