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 40C75E65D3F for ; Fri, 22 Nov 2024 10:12:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C24666B00B0; Fri, 22 Nov 2024 05:12:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD6D26B00C3; Fri, 22 Nov 2024 05:12:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9D466B00C4; Fri, 22 Nov 2024 05:12:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 87FA76B00B0 for ; Fri, 22 Nov 2024 05:12:45 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 434DBA1420 for ; Fri, 22 Nov 2024 10:12:45 +0000 (UTC) X-FDA: 82813314318.03.BFB2DA2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id B547214000F for ; Fri, 22 Nov 2024 10:12:02 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf26.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732270226; a=rsa-sha256; cv=none; b=WNdOGlZyQvM99lPzaxeBscyWikb9Gu8s/FmofwsWdedlfkXpLnQAeo7cEfZblYzrf4Fevp SAsPhV9ALDMqKn5G8hdaOOHb4cyfsQu/wBYsJ8CtZGFKNuppyT1A48PC1vDJ1Z18rVUxtQ ZoI393uAhVEYSNHI6l59gmrrldj3ahY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf26.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 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=1732270226; 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=+uJow0VGWe1KPC4Kp7AYwoUo0cmANCmTENYekTsY+7Q=; b=Jr0XPjH8Cv6hzckJDmvhUwLxdueJhJH+TKWRy0kEvGxbLox+BDfOuvoqShURtRRSIU558S XimihW1Mfv9SzYA7CzxifMJOndUatY05ZL4Ya4cmDKiQrAg7um6btzPdnedg1pChPLSefl zaaXbRejmSomT8leeAyGDSdyGxcahgQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C67905C599A; Fri, 22 Nov 2024 10:11:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8162C4CECE; Fri, 22 Nov 2024 10:12:39 +0000 (UTC) Date: Fri, 22 Nov 2024 10:12:37 +0000 From: Catalin Marinas To: Sebastian Andrzej Siewior Cc: Steven Rostedt , Alessandro Carminati , Andrew Morton , Clark Williams , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Thomas Weissschuh , 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> <20241122081437.AKxGgM9n@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20241122081437.AKxGgM9n@linutronix.de> X-Rspamd-Queue-Id: B547214000F X-Stat-Signature: aj4axw6btbjgrdn8woeiis7kpk837xkc X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732270322-385160 X-HE-Meta: U2FsdGVkX19vKx/dAEdIC+XqYpUZ+UDAltKsvZ5n0Ks4XPbYrsm631HuhqDdkekMOBssYtqYfAoxtLyKkMfi6FP2uBeVvty382bKNJZE/KepnMeOtPk9QumuB7RakCXTpq8kdIFVH+L5VVLSdpOfgzDj9pL68UIrMsOE0WLQ+Tmy+xcHKxAzerCndyUaViQTNP7O9CQXIFB0WEUXc7bV101qUfgSTBHrTruVO+e/grux2UuIpOySWvjobQfYEfNg6FrgJ8Eu41IGfvhGgTZlQtKugEzN70JbtCa3ypp1t0XHKIA17Lw5WB0Z9DmZtDvLprVgBOgU8vCeTiJcjFtZ8N6idffb1t4TSVJ5VVasAN/tNPlRbBHi7IB1teNkJB8jnFQXEN3oyHtGM4Zs4QL0E8QpCy0EZwfHx5gSHnfgT1cndiOXIk5eRJWDIPBEsgReYiFk1GuNKsxH3CVptPRDD5WxUG79FnrCkXkVxAPbd+gL1NV/0XBpUJMDwf0iaZFz4A7XhJdaoxYjGvpFC0VoAGdENyzKrhQntCkPvU+Mmtdi8ZSX79oVJJ2V7TwcfloxeWtQ3XdlJ7CBLRhMTvaUCrrjk5SnYvpH/I1/8r09uNVc+bwRjyejTSVoP15abeyYkkb1kYqvJ62NwPu8bOsHzdZvlr5ypDMFwFqpqqz5skbBqPIDvVcVmDetq9KELo2KXqBbIo2/PgUTXvJ1bO0u2EQ6vcdV+mf4qC/1mEJw6G57kENKor0dZGgo9DPOrFZgy07aZ4/hx7VhOu9GVFIdggI7TjaQgFl932F1goMSsT+/QaSifG/IB041z2f+kxeXEhiQ1O53mYrXhcx4LALfghezck8QmlaUK4I9qkj4bOcurZ0CaxAPeSz+XPx+rqT0i58aP3cKdnMYm2yurh7TR/U47HS38RCu/xAtsafCcArkx0s2gBIIRgFb9y2A3AB5qAnowZIDtDpmKCxf/YV ywqnlkcA TJmIfDrp0qvWHkcz7t3w5O9wODKJPY7OxAtKUuzhKzO5SEkLhwfY9GUU1Zwcvjo8LAVZuKpbyeAaEKuhs9wb9A4XVfWO0PDL/ZAlpfYxNZBx21P7kuauaOcBPlr4kbNHs2U+1z+7V4WpY9FBAu/HYahmRgHYQtCBrf4cvxh3SfA6pq2JwvIQVvP64h4UueDeoZBUg8Ammu4QnMD7Vr6l+ktTjDI/eriCaM9wvj1ElMztnaw6w/rTnrfiZq4VkmfRBfx4E3kQVEd2CrYMyEjPYzIdcOKT5Z6hunVdSc3nB+TVS8nDkQOuvENBz37y86knnea0+Deq6V+T3WQN4MLnYMVkqqyBBZqTJdqXQpnvwAA74IQWGVcgY19h9PTwB0uwL5xb6y3RCGzBsnvkgQHUyIpjK7rPqc16FVC+XaCUW17uF0+xpPQjxQUfPUh2f7nWS8WhRWXU4kOgvNpYBJ2/F5yDcsJPdzkyDqQQyDoulE0L4wWM= 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 Fri, Nov 22, 2024 at 09:14:37AM +0100, Sebastian Andrzej Siewior wrote: > On 2024-11-21 19:19:05 [+0000], Catalin Marinas wrote: > … > > > Maybe SELinux locks should be converted to raw? I don't know how long that > > > lock is held. There are some loops though :-/ > > > > > > avc_insert(): > > > > > > spin_lock_irqsave(lock, flag); > > > hlist_for_each_entry(pos, head, list) { > > > if (pos->ae.ssid == ssid && > > > pos->ae.tsid == tsid && > > > pos->ae.tclass == tclass) { > > > avc_node_replace(node, pos); > > > goto found; > > > } > > > } > > > hlist_add_head_rcu(&node->list, head); > > > found: > > > spin_unlock_irqrestore(lock, flag); > > > > > > Perhaps that could be converted to simple RCU? > > > > > > As I'm sure there's other places that call vsprintf() under a raw_spin_lock > > > or non-preemptable context, perhaps this should be the fix we do. > > > > My preference would also be to convert SELinux rather than avoiding the > > issue in kmemleak (and other similar places). > > No. kmemleak has been made use a raw_spinlock_t because most of what it > does is something that is not used in production on a PREEMPT_RT system > and falls in the same category as lockdep for instance. And that code > calls into LSM/ selinux. > Before making the lock in selinux a raw_spinlock_t you have to think > about the consequences in general and audit the code. From a quick > look, there is also avc_insert() invoked in that callchain which > allocates memory and this is a no no. > Also, if you make the solution here in selinux to use a raw_spinlock_t > you would have to do it also in every LSM as they might be used instead > of selinux. Good point, thanks. Kmemleak is indeed a debug tool not supposed to be used in production. Modifying SELinux has wider implications for PREEMPT_RT. > Therefore, I still prefer adding PREEMPT_RT to the restricted_pointer() > category for atomic invocations. This should work. If one wants the actual (hashed) pointers with kmemleak, I guess they can disable kptr_restrict. -- Catalin