From patchwork Tue Dec 17 14:20:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alessandro Carminati X-Patchwork-Id: 13911883 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 9BF34E7717F for ; Tue, 17 Dec 2024 14:21:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 213A56B0089; Tue, 17 Dec 2024 09:21:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C39C6B009C; Tue, 17 Dec 2024 09:21:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0647D6B009D; Tue, 17 Dec 2024 09:21:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E12B96B0089 for ; Tue, 17 Dec 2024 09:21:46 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 86F661203DA for ; Tue, 17 Dec 2024 14:21:46 +0000 (UTC) X-FDA: 82904662428.20.480C36F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 3F1F712001D for ; Tue, 17 Dec 2024 14:21:01 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RY2kE76n; spf=pass (imf29.hostedemail.com: domain of acarmina@redhat.com designates 170.10.129.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=1734445284; 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: references:dkim-signature; bh=8Dr2EHbX/y+fl2ClFkwVxyN+xWUTEC0vyjnXgy6CKlY=; b=lIsJ+JyiZlrMW4fa3XFZqkE4eZdFJJRCJMStxYFcvGNAFw5ibCmCX4gNyWKza3mfddOmk0 zD//E3EP7GBVuYG4+t5smMURxrmamdP3xP6KpqDsqMGf10WEJt2Q/CQwEWZfVHOOIe/D92 XeRdMSPlDynIvMEvT7U3YnMI68kuTns= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734445284; a=rsa-sha256; cv=none; b=iIbxc9OS17VSfH6C9onsP59UOHgoiebSo6+esaRWnnhAdAaiym5hqdbVsnhHrZhxLrm8UF 435aHnOpCMotuSBCInA/YU3LCsXp5HG/woggd5Z5KIrkT2rQZ4PP5dzBcyIUOC1qY6Y8U3 v+cRyrDqYLu2gN9ZPEsPciQkFgRha1w= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RY2kE76n; spf=pass (imf29.hostedemail.com: domain of acarmina@redhat.com designates 170.10.129.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=1734445303; 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; bh=8Dr2EHbX/y+fl2ClFkwVxyN+xWUTEC0vyjnXgy6CKlY=; b=RY2kE76n8FlI4JuWVIeeQQOvFkrr2rwlCC5JzzjmJDNrpJPo2e9JqJHanPaZ8QErzwrTUf cChVcsakSHZLJ4PmUKmzDTUhcP6xhVmrNS1R/43IoyDaexctxsdYEVzkEdbC7c7izH866a JNJ7N46SFXeMiGAtwQhRoT7cOViBv6c= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-617-nxSWT98INnyprcIQUAkNMA-1; Tue, 17 Dec 2024 09:21:42 -0500 X-MC-Unique: nxSWT98INnyprcIQUAkNMA-1 X-Mimecast-MFC-AGG-ID: nxSWT98INnyprcIQUAkNMA Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4362153dcd6so13371815e9.2 for ; Tue, 17 Dec 2024 06:21:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734445301; x=1735050101; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8Dr2EHbX/y+fl2ClFkwVxyN+xWUTEC0vyjnXgy6CKlY=; b=Vut3E3iijT3KHppBKpFaW6MLrx4TBWECPl10SXw/5fx4ZzEfRFNZf/1u9yioP38ldj kRh64TQ9S6mqnOSAoKapr16rkv/JQaukzJ7yEw2oe9jghx6lCUQHkUIVqnC9CHP5cMIV WwZQvupDrvMOdrDo6ecqA9S0P+jILNCHGa/kE01WZLKHY1V7uRkGHLATEqOV0CsuGj41 byViUAEEQUdP86vsKx/QvGt29c+D0Qsy6eLN1JkOg8HHiNojC7WshNfR8lTN7rG2D714 ij0cM4MGKt/lfwfZ9jrLBhdpYtKAumL98TebpjIiOhK6/0/Ry68m2Floz2EED7wxi3FK pSFw== X-Forwarded-Encrypted: i=1; AJvYcCVakkUegiNr70gKPcVkNlIQqpipXFR4auqvnykk+Lb83F/zWoYmQorNy0UdLK5lAn40u1KzvwPQlw==@kvack.org X-Gm-Message-State: AOJu0YypRnZdh7/JrRVXes3HdBOKEbRKtKvjPjAFmuXLL/wDArjK3l79 nHhhC5/kOYxRmF0xkMyCJo8jwQI9ksJEVenzZ80PYqYDsshJy2Al8DfcYn/hrJaC4qIRwOq93UD C37bj2BgqbwnhDwpCCK/ZCEhd/Mw48oGLyiVF+Mvyke1pGWEu X-Gm-Gg: ASbGnctmSCRP5JWP7Nzgj4UEB4dwQBItCd4ZOoI43TKFt/Lps2aUZtfvVfffJIAJ0cJ aBN3foolCVVFVGhg+OCY6llq/Vvuk9Gk3vtQvLmWN0UJuCiSjWRUBiSuQMRESKimODvfnau7Qfg pfLOnITvoj3LGtPldPHmEr27vAJVWvYRP650vrpCXXp6GIr822hgR4qf9BMn7QaMvVi7WaPiWiD wDaVUthukx6ZpHsskCL8egpcA6czA+BppKZ9NbWMvD4OiRxyoDZ1/9zAxucHw== X-Received: by 2002:a05:6000:787:b0:385:f114:15bd with SMTP id ffacd0b85a97d-3888e0b8614mr13448730f8f.37.1734445300988; Tue, 17 Dec 2024 06:21:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuGTV7yX6OAyCGz+mhik59B+KccVwP+GQIMkxCeBkGgKnKosocOSTTeZKg4gnWSMhLmmy2fw== X-Received: by 2002:a05:6000:787:b0:385:f114:15bd with SMTP id ffacd0b85a97d-3888e0b8614mr13448709f8f.37.1734445300580; Tue, 17 Dec 2024 06:21:40 -0800 (PST) Received: from lab.hqhome163.com ([81.57.75.210]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4362557c57dsm173106295e9.12.2024.12.17.06.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 06:21:39 -0800 (PST) From: Alessandro Carminati To: Catalin Marinas , Andrew Morton , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev Cc: Alessandro Carminati , Thomas Weissschuh , Juri Lelli , Gabriele Paoloni , Eric Chanudet , Alessandro Carminati Subject: [PATCH v2] mm/kmemleak: Fix sleeping function called from invalid context at print message Date: Tue, 17 Dec 2024 14:20:33 +0000 Message-Id: <20241217142032.55793-1-acarmina@redhat.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: pMhZGvwA_z2wu319Qte2CLl77TFsAlohLmz37LRmECc_1734445301 X-Mimecast-Originator: redhat.com Content-type: text/plain X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3F1F712001D X-Stat-Signature: 6ki4rfk66yjib4z3zonp49uxgmntozc3 X-Rspam-User: X-HE-Tag: 1734445261-644706 X-HE-Meta: U2FsdGVkX18XA105FYVLFf3X6UybGHg4PkDjFhW+UUEwKo75u34zURNqcWnMWJ5mdWEC0+0uuFJg54Em7Wz60aFeYcSN0ctU3uBaz0kpW9t+DTL6Rp+YszfHvhxaCqVVk/+eBtSmFBCU0QQiEbIWs6nJtYpszWl0zs9z42Nl1It05ahkyaiytfKO44YUiUtCwnqfuLkpbF5142haGCLRTKCNbulaPa/rNCSxVFSFaAPFzPCzShjbwzHwi02tviwfpX6hi3c3qKmQhpAx9IbwiKciIH6SZYGxxM9m79ezUxGKkGqt6hmjN/yWrCKv8M5/Ri+UZy7yY8jQMsFCsbnNYat10+ccQaB/24QwkN/429tMBiNIqId9oxOpEllcFwZ7/9+ijXmyYkcfJLZ/B1UQQqbaIdvE9sHzmxwaZVaOiqan9qdoGK8lZxcfy4vM0OEsGEVVsDD5fcHPP4RMsgQ1nV3Vcg7DpWEBUK7OIRFO24NOLvBI5lde/SD0kTXur7tCQuIWw4qY9hpptPMST1aBFtt/trdRRVrPHCVeMesqvDSEdkXjXMP0+WkE3Qkr09N0a2uPVsp8rdp0AahLTVOaDP9CFP8jp/zKOILFngeKn2MCkquT7aptCiYDfAto4+YyYvc9kTyrHlPh+X9xN3nTaoDyo95jHKmEonH5FEVNINN4lE/c3WT/I/CFA/BUZWmM1opC8w6GyZfFBTiqabCVFE3oU5Jwa8w6NUoBN22m398ajpUeLIcO+sAqAUgr+rFq8iBE39PQBxpesKG+gdK3hbW6pjDWoWGPVh8+CVdgefqVYt/z6QcTrq8HStAgbSxZVIHPVTpft/nj+p/+9T3r0sk4UVdBr+RgDquuo9B9U7zozyoFH12ZGDL+IsDt58AbsCOOrgaTRWmbtKtOUo3LmwTjsvJlczNB+brJGzuqwwvnMj9BhjJUPbVgDPXV6eAUV19D9bnmi5gJOZFZgGN P1cs48G0 mrHN1LQ7JU9+CeKkQ+uxulwcpzSYlxcro71LM9ttFw6j5ww6NeaumcrvQbQDQvYnpCuHWAaKx0BH/51VMVeq6osgxcZ4tP3kWoRyWuyglkkeJzulZbxneyEggty8+EXyNJKCoicw7i7QoHDzCEziP775Faz0ZHw96FsMfj2qUQ33jFkEeoZIyeCGLBUjXybSWrVuDSoOqbzHEbGBRw2B6lrk7cIxLyDiLUqj9cRTpgoDPBuCZ7M3qerIxV5vah2fQHE5/7V9SYoyAa2Y1rcFnZ62416cKV60Q5EjE2UdXrodDFG8aBCO9OeWk0ldbEaQMK9PNQvpFR7+OR0NVV3KbOz1/rTn/VU1n0yeelyj8oCwyTSrU50WD5R6h6BclCszkfZ0DLqxgrlB4F1dR4+GZ6L+D/SJ2rBh93Z5I9bwy4mBm54M= 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: Address a bug in the kernel that triggers a "sleeping function called from invalid context" warning when /sys/kernel/debug/kmemleak is printed under specific conditions: - CONFIG_PREEMPT_RT=y - Set SELinux as the LSM for the system - Set kptr_restrict to 1 - kmemleak buffer contains at least one item BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 136, name: cat preempt_count: 1, expected: 0 RCU nest depth: 2, expected: 2 6 locks held by cat/136: #0: ffff32e64bcbf950 (&p->lock){+.+.}-{3:3}, at: seq_read_iter+0xb8/0xe30 #1: ffffafe6aaa9dea0 (scan_mutex){+.+.}-{3:3}, at: kmemleak_seq_start+0x34/0x128 #3: ffff32e6546b1cd0 (&object->lock){....}-{2:2}, at: kmemleak_seq_show+0x3c/0x1e0 #4: ffffafe6aa8d8560 (rcu_read_lock){....}-{1:2}, at: has_ns_capability_noaudit+0x8/0x1b0 #5: ffffafe6aabbc0f8 (notif_lock){+.+.}-{2:2}, at: avc_compute_av+0xc4/0x3d0 irq event stamp: 136660 hardirqs last enabled at (136659): [] _raw_spin_unlock_irqrestore+0xa8/0xd8 hardirqs last disabled at (136660): [] _raw_spin_lock_irqsave+0x8c/0xb0 softirqs last enabled at (0): [] copy_process+0x11d8/0x3df8 softirqs last disabled at (0): [<0000000000000000>] 0x0 Preemption disabled at: [] kmemleak_seq_show+0x3c/0x1e0 CPU: 1 UID: 0 PID: 136 Comm: cat Tainted: G E 6.11.0-rt7+ #34 Tainted: [E]=UNSIGNED_MODULE Hardware name: linux,dummy-virt (DT) Call trace: dump_backtrace+0xa0/0x128 show_stack+0x1c/0x30 dump_stack_lvl+0xe8/0x198 dump_stack+0x18/0x20 rt_spin_lock+0x8c/0x1a8 avc_perm_nonode+0xa0/0x150 cred_has_capability.isra.0+0x118/0x218 selinux_capable+0x50/0x80 security_capable+0x7c/0xd0 has_ns_capability_noaudit+0x94/0x1b0 has_capability_noaudit+0x20/0x30 restricted_pointer+0x21c/0x4b0 pointer+0x298/0x760 vsnprintf+0x330/0xf70 seq_printf+0x178/0x218 print_unreferenced+0x1a4/0x2d0 kmemleak_seq_show+0xd0/0x1e0 seq_read_iter+0x354/0xe30 seq_read+0x250/0x378 full_proxy_read+0xd8/0x148 vfs_read+0x190/0x918 ksys_read+0xf0/0x1e0 __arm64_sys_read+0x70/0xa8 invoke_syscall.constprop.0+0xd4/0x1d8 el0_svc+0x50/0x158 el0t_64_sync+0x17c/0x180 %pS and %pK, in the same back trace line, are redundant, and %pS can void %pK service in certain contexts. %pS alone already provides the necessary information, and if it cannot resolve the symbol, it falls back to printing the raw address voiding the original intent behind the %pK. Additionally, %pK requires a privilege check CAP_SYSLOG enforced through the LSM, which can trigger a "sleeping function called from invalid context" warning under RT_PREEMPT kernels when the check occurs in an atomic context. This issue may also affect other LSMs. This change avoids the unnecessary privilege check and resolves the sleeping function warning without any loss of information. Signed-off-by: Alessandro Carminati --- mm/kmemleak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 2a945c07ae99..737af23f4f4e 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -373,7 +373,7 @@ static void print_unreferenced(struct seq_file *seq, for (i = 0; i < nr_entries; i++) { void *ptr = (void *)entries[i]; - warn_or_seq_printf(seq, " [<%pK>] %pS\n", ptr, ptr); + warn_or_seq_printf(seq, " %pS\n", ptr); } }