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 DCD0AD711C0 for ; Wed, 20 Nov 2024 16:36:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65E726B0088; Wed, 20 Nov 2024 11:36:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 60E1E6B0093; Wed, 20 Nov 2024 11:36:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 439B66B009B; Wed, 20 Nov 2024 11:36:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1FAE86B0088 for ; Wed, 20 Nov 2024 11:36:22 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BA1CFA03BA for ; Wed, 20 Nov 2024 16:36:21 +0000 (UTC) X-FDA: 82807025700.14.EBD21E6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id CB09A140005 for ; Wed, 20 Nov 2024 16:35:43 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="H8SI4x6/"; spf=pass (imf09.hostedemail.com: domain of acarmina@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=acarmina@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732120518; 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:dkim-signature; bh=qhU3S0A4Mnpsnqs/3/13cFEa605q4UA1j817veP3A6U=; b=L4SnlAV80AuitGwEINxesQaohL8WL5EwVWQ29RUyatKOsSnd51eMX6WcFvP5ip+QUC3Qar XujIzMakdD4J/Kd7PHNbtg7PpT2HySRbWfWjSL94FIScYOVCvUD2hqxmjaePhuclnF68J9 cNrg/VsBcjEg3dHTT7GWaRQs83E2Dyw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732120518; a=rsa-sha256; cv=none; b=nsGGFaa8VIP+26jRp5vO1+GIqENlh7p7SD2BwGZQt8xOAXI5w0y5ogS6aI0LIghbzpDFvN scbjalvHxqPtc+wwYj5nyKc5GV6rNZkhq9Rai5NtXahOfcrC2vJf7g0JKkkOFX2fiGTws6 g6PwBAGJ3AAT4hIe3MTPZnhF5iKpgTQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="H8SI4x6/"; spf=pass (imf09.hostedemail.com: domain of acarmina@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=acarmina@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732120578; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qhU3S0A4Mnpsnqs/3/13cFEa605q4UA1j817veP3A6U=; b=H8SI4x6/v1Oiu1noo1vpMGIV/3aK/hIKu+jzMplO2gaHcydXi1mTo3mqvs6taI0si9eD3L QPLjkEecqqqQC2j9ue0hqwBlObnmX2bL48MhZx5LRxMC10ozBgZkTOuWiOwBNSdnlJxYbZ poxmgWGWmpbl8hGKvJRhku/eo6ZjgwM= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-RkUpF9IoOLew2Tv1uwc-lA-1; Wed, 20 Nov 2024 11:36:16 -0500 X-MC-Unique: RkUpF9IoOLew2Tv1uwc-lA-1 X-Mimecast-MFC-AGG-ID: RkUpF9IoOLew2Tv1uwc-lA Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-20d15285c87so49527415ad.3 for ; Wed, 20 Nov 2024 08:36:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732120575; x=1732725375; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qhU3S0A4Mnpsnqs/3/13cFEa605q4UA1j817veP3A6U=; b=VzJd8j3xxFGLKjVxWl+sWMfXg4SjmtgOqxVEQ5A/QrCinHYpzFJCTp+SziFBXXIGSL Kl2cGntSTc+PNnoSAWyOIgyokwS5p202D+yvZZd4Xsu6p9Bz9QYYhpaUvNHDatKm3M7u dkY3+xQgtX1v0m9x/0lrfOXJwR39CXDifI7Qpl8qpbexKhYjQZ9mtl3tIHgG+WhOgBmB sOicLX2JkaRukR9AW+ZXDXfbj/1pHNRcLVlMIloXIITnmIcfmLwxBYF1fkedCfc/pREK ad95QdiqUpkTr1JKpxVbWkTPRzJKajXOm6cvfJar34Ez1jrpiPM4LJaCjnt3u5ZWsDDU o32g== X-Forwarded-Encrypted: i=1; AJvYcCXy+Ta9HkaoOVVAb3y4aZGmokVOaUCnvaMdJGeSzJFmQ+5G9P6lzSOdW5yzDOLY4YQkJgs6qhKDDQ==@kvack.org X-Gm-Message-State: AOJu0YzR3ee60d+ifyOhdqmvZYcGDSK5Bvk7s8zyogWIUMDUckPcG9+s PV/e4yk90vQkG97jxXwqVPB8hloadJ3tn/+YURhwt1pO7Wwp5H20XBxrpdgdmK1D3h7E6QWTzjv iclBxXudNpK5IUmO8T8VktYUqvZ2APlyEY2ADCuaHwL3Xj8P7VLTcUAIZRJBt1xEHNwr47t8stS V/sS77vSPbDaGYxsE1OQj78m4= X-Received: by 2002:a17:902:ccd1:b0:20b:b40b:3454 with SMTP id d9443c01a7336-2126f9fb108mr36420085ad.0.1732120575531; Wed, 20 Nov 2024 08:36:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEndC+AthKB1mpAbXnqOydUaK60UqI1oD1suHPMIJwIkfHNBJIHODhd4fFPf5EbSrZJ9RZvD8mL6P1+1iEOyY= X-Received: by 2002:a17:902:ccd1:b0:20b:b40b:3454 with SMTP id d9443c01a7336-2126f9fb108mr36419915ad.0.1732120575211; Wed, 20 Nov 2024 08:36:15 -0800 (PST) MIME-Version: 1.0 References: <20241120102325.3538-1-acarmina@redhat.com> <20241120102602.3e17f2d5@gandalf.local.home> In-Reply-To: <20241120102602.3e17f2d5@gandalf.local.home> From: Alessandro Carminati Date: Wed, 20 Nov 2024 17:36:04 +0100 Message-ID: Subject: Re: [PATCH] mm/kmemleak: Fix sleeping function called from invalid context in kmemleak_seq_show To: Paul Moore , Stephen Smalley , Ondrej Mosnacek Cc: Catalin Marinas , Andrew Morton , Sebastian Andrzej Siewior , Clark Williams , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Thomas Weissschuh , Steven Rostedt , Alessandro Carminati , Juri Lelli , Gabriele Paoloni , Eric Chanudet , selinux@vger.kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5ARGCKx8R66_3kLcjONEDSOskf-KoPiFHpS1nLci-S8_1732120576 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: dizr5dexatg3dayx3qbqas6p81e96wg3 X-Rspam-User: X-Rspamd-Queue-Id: CB09A140005 X-Rspamd-Server: rspam02 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WAboIin1QA8kh6Sprpua1WY3jYnLNRZnnloGRyoIdDtMAubxcq1iYG0diio76zPsvw9CMQCyJhn3TicnKJljB/h2+OI3YpLIKUG+XtcIAFWx9inCYYO/fEpCITe94uN23zkKJPABt66kRyEbKeTFFlw1HbQnYkSwAupy0C/Cs7DW7USHjfI7bSYb2+KNuVp1UVIjslk/sMfVFvYpjaTPrR4+5anWp5PX/JjOdCUA+IbspvNf4NlT0S5NMM1/ZU26BAA7OKfREkP236IOX1NUEtpcZNJBkaTh7KTtNg5ThfpkADFGQFpcP22tejWBwgWESk0fG9uUrLTXPn7xvIDFYZCoVkdUYqb2rR9JwWVIJ8flOyTlDImDD/KGdye2mudwQEp1SHvZVUBOQdWH9TJTpzYSdbEjQasLQLy596JMUNNMVfYgBmk= 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: Looping selinix Maintainers into the conversation. On Wed, Nov 20, 2024 at 4:30=E2=80=AFPM Steven Rostedt wrote: > > On Wed, 20 Nov 2024 14:53:13 +0000 > Catalin Marinas wrote: > > > > -static void print_unreferenced(struct seq_file *seq, > > > +static depot_stack_handle_t print_unreferenced(struct seq_file *seq, > > > struct kmemleak_object *object) > > > { > > > - int i; > > > - unsigned long *entries; > > > - unsigned int nr_entries; > > > - > > > - nr_entries =3D stack_depot_fetch(object->trace_handle, &entries); > > > warn_or_seq_printf(seq, "unreferenced object 0x%08lx (size %zu):\= n", > > > object->pointer, object->size); > > > warn_or_seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu\n", > > > @@ -371,6 +366,23 @@ static void print_unreferenced(struct seq_file *= seq, > > > hex_dump_object(seq, object); > > > warn_or_seq_printf(seq, " backtrace (crc %x):\n", object->checks= um); > > > > > > + return object->trace_handle; > > > +} > > > > 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 no= t > > 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. > > In PREEMPT_RT, to achieve the ability to preempt in more context, > spin_lock() is converted to a special sleeping mutex. But there's some > places where it can not be converted, and in those cases we use > raw_spin_lock(). kmemleak has been converted to use raw_spin_lock() which > means anything that gets called under that lock can not take a normal > spin_lock(). > > What happened here is that the kmemleak raw spinlock is held and > seq_printf() is called. Normally, this is not an issue, but the behavior = of > seq_printf() is dependent on what values is being printed. > > 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 wou= ld > not have been an issue if it wasn't for that "%pK" in the format. > > Maybe SELinux locks should be converted to raw? I don't know how long tha= t > 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 =3D=3D ssid && > pos->ae.tsid =3D=3D tsid && > pos->ae.tclass =3D=3D 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_lo= ck > or non-preemptable context, perhaps this should be the fix we do. @Paul and @Stephen do you have any feedback on this idea? > > -- Steve > --=20 --- 172