From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C08939DBF2 for ; Tue, 16 Jun 2026 09:14:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781601296; cv=none; b=ag7/CIJateiDfRiYkcrNt9HHSxsEl8d0gjJQHwhOnyPoXdPsf2UiP2J1/0XEujM2P9aGpzzm1eE24TG7JSSUMYXoDy+e2FvQu/zz2NH7PKPmKT4x8rJxScKrRf4M4vABLGmkfzrZnuUhvIPl65n/J0XUbxHJjroyz+M42QI8uI4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781601296; c=relaxed/simple; bh=36QuOsrDYCjnp8U7ww8EIJ3McAUGN/4LJTtMIwuyMRM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qHJuq1YeVc2fguI/nOFSrmyiLb0ryoyluNgZPkMrNxI4W/Iyvtr9iTazg2WbrxYrib6ocWATBEsEMUVCEhvQGks8vzSIgs3vmrW2iT3pzOt2BUKzswCDBAsVG+Y5oS2oaF1b6PXU39x1VfaBEgZoZ+v4L0GNoBAs+qTYnu1NLoI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=FE/8IA67; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="FE/8IA67" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-461a15bb7e8so353815f8f.3 for ; Tue, 16 Jun 2026 02:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1781601294; x=1782206094; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=t5fVPPL/MiFjakxmgMV5dR14morQiFY0hOlZW95hlco=; b=FE/8IA67hQY/jSsoPGZTWz82M9JjLoPd6xwbzZqHj7ZvkDTNynNFP4MPcWmJ+fzp3e Uqt684OH9clRqCmqNXmJhLJn3QR9YUyuXo9BWKeAzdvq2fbXQGHOOK2UxhZ2FgCzMcjO MJzxYAkcjqEeJp5/ZjQam5vZX0zkKfxuVG61chSSLVG9ICA/bqlFu6GZ6W+4dH7w5jjA jlG6Ib+IggJgIZXTNatnuEIPTYPWITtH1rk8G7pO7v3tkoLwH0i3wlad5Nod4BdovgAm o+iDIRmK7UqCLDoUyQoA9UN3HXmO6D7gaY7YMIgHjFBAfCdUSFpRmYS3gq0tau2fi08K OfbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781601294; x=1782206094; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t5fVPPL/MiFjakxmgMV5dR14morQiFY0hOlZW95hlco=; b=HzH9nsZcbgv6GBuh2rMk10HqnSBnNzQv7eKZKaGBSPhzs//ygiSYU8NZMgOBshM/wS 0uDJM6mCvJbbRHkGCQjwFf3HGjcotOgKR5kX1pxW9jEFkd7SGjVhDKtxJp7WziUJKgKg wTiHsZO5wIcuEKQIAkYqnULVu8jQX9r1qfzPHh32txaYM+D5G5x3h2wUG0VHzQeQdhhG 5XaUiCnog2W0Z3D4Y5wgErtWIgqhvdOdn6Ju+Wa/R6aHdqMCJQP/g9xErVgdkk6ROhtd TNuwTIt+1q2PY703q0OVBFpCdVx2Fw1dffsEVM/q/vYfu3QP0ZGpzKxyAGoYhICvH5r8 2acw== X-Forwarded-Encrypted: i=1; AFNElJ92FBrw2Czga2aVtz5pS+HojXJQn4qq7kI4eGo14MaWiOKE8TDZv5a0GtqhoDZXGuXU6d+dfT76hn6rXNM=@vger.kernel.org X-Gm-Message-State: AOJu0YwFupPThhuHsbKF+S7Kqh5GaF3+9UNHQBxg85csR3r+88pxVEl/ MnU7k8B/BD4AYNM35JLYkyrF5393Rghj006VU8EYWqRvoXiCw/4TIWXsKJdXgoJeEgg= X-Gm-Gg: Acq92OFnJtfgq6NnzayE0OCUHFvyAPo9NR5eTk0fFizd3RSEeK8O/QNta+IWgwge8Tz 3nMZBxfN7eNZR89MYsyOQ5YeDZYH5aRJxDNsgj5XthXwoy7Pb/k7nD27LlqJxwg6xCRT2TIAqtu KmaaoyGZBH93YsGjUN/1mglwvYErlUmNMdPBv9Dj8fk81Ins1d7CPYHauZ0r/8ktt/PzZg9UGFP 5HO9FvcoAaE0cTkHuECps7oiXhHRCBucyv2AmboFgC+JhRLwBrA4XabPsCkWbNxZo5n6fck2FXU TiED7JMHaGSrczzHL6FLWzO4djLKFwtevEtQ+mDnWIL+eYDAnl5uYfCr60e8pkHE742vWDXB0vZ 7q2dsDQ6NFsn5JOYgZLPg1q+oFW7tk9sck1mr2jVhORjMSeYs8KaS9zVJnjWz2SUjiSYdixlcRt aV/KXcBf3dr7xtvn8BL2g8Vbg8cA== X-Received: by 2002:a5d:458b:0:b0:460:1387:19f6 with SMTP id ffacd0b85a97d-4619f3cfa3fmr3458320f8f.36.1781601293594; Tue, 16 Jun 2026 02:14:53 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4619b9b7750sm14890498f8f.6.2026.06.16.02.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2026 02:14:53 -0700 (PDT) Date: Tue, 16 Jun 2026 11:14:50 +0200 From: Petr Mladek To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= Cc: Andrew Morton , Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , Sebastian Andrzej Siewior , Clark Williams , Kees Cook , linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev Subject: Re: [PATCH v4 5/5] lib/vsprintf: Validate spinlock context during restricted pointer formatting Message-ID: References: <20260608-restricted-pointers-final-v4-0-9a436615799e@linutronix.de> <20260608-restricted-pointers-final-v4-5-9a436615799e@linutronix.de> <20260611120615-4252b75d-55aa-4bed-b64b-0316b2148d2c@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260611120615-4252b75d-55aa-4bed-b64b-0316b2148d2c@linutronix.de> On Thu 2026-06-11 12:09:08, Thomas Weißschuh wrote: > On Mon, Jun 08, 2026 at 04:21:45PM +0200, Thomas Weißschuh wrote: > > Depending on the system configuration, the restricted pointer formatting > > might call into the security subsystem which takes spinlocks, which > > might sleep under PREEMPT_RT. As %pK is intended to be only used from > > read handlers of virtual files, which always run in task context, > > this should not be a problem in practice. > > However, developers have used %pK before from atomic context without > > realizing this restriction. While all existing user of %pK through > > printk() have been removed, new ones might be reintroduced accidentally > > in the future. > > > > Add a lockdep annotation to unconditionally introduce a fake spinlock in > > restricted_pointer(), so lockdep can detect misuse even if the current > > test system configuration would not exhibit the issue. > > This is intentionally a single lock instance shared by all callers, > > as that mirrors what can happen in the security subsystem. > > > > This check comes intentionally after the in_task() one, to have the > > clearer diagnostic first when the function is called from IRQ context, > > which will trigger both. > > > > Link: https://lore.kernel.org/lkml/20250113171731-dc10e3c1-da64-4af0-b767-7c7070468023@linutronix.de/ > > Link: https://lore.kernel.org/lkml/20241217142032.55793-1-acarmina@redhat.com/ > > Signed-off-by: Thomas Weißschuh > > Reviewed-by: Petr Mladek > > --- > > lib/vsprintf.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > > index 09e0e5194d41..728a1acd69ae 100644 > > --- a/lib/vsprintf.c > > +++ b/lib/vsprintf.c > > @@ -864,7 +864,14 @@ static noinline_for_stack > > char *restricted_pointer(char *buf, char *end, const void *ptr, > > struct printf_spec spec) > > { > > + /* > > + * has_capability_noaudit() may use spinlocks. > > + * Make sure %pK is only used from valid contexts. > > + */ > > + static DEFINE_WAIT_ASSERT_MAP(vsprintf_restricted_pointer_map, LD_WAIT_CONFIG); > > + > > lockdep_assert(in_task()); > > + guard(lock_map_acquire)(&vsprintf_restricted_pointer_map); > > The kernel test robot found a lockdep violation with this patch: > https://lore.kernel.org/all/202606110945.d3871219-lkp@intel.com/ > > My suspicion is that this is a pre-existing problem that was not visible > to lockdep so far, exactly what this patch is supposed to mitigate. > I'll investigate some more and try to reproduce it. I was curious and found the following. The problematic patch seems to be: [ 92.754552][ T3827] lock_acquire (locking/lockdep.c:5868) [ 92.757345][ T3827] class_lock_map_acquire_constructor (linux/lockdep.h:557 (discriminator 1)) [ 92.759895][ T3827] restricted_pointer (vsprintf.c:874) [ 92.770231][ T3827] pointer (vsprintf.c:2582) [ 92.772166][ T3827] vsnprintf (vsprintf.c:2956) [ 92.774145][ T3827] seq_printf (seq_file.c:392 seq_file.c:407) [ 92.776083][ T3827] tcp6_seq_show (ipv6/tcp_ipv6.c:2147 (discriminator 1) ipv6/tcp_ipv6.c:2221 (discriminator 1)) [ 92.778212][ T3827] traverse (seq_file.c:112) [ 92.780125][ T3827] seq_lseek (seq_file.c:324 (discriminator 1)) [ 92.782106][ T3827] proc_reg_llseek (proc/inode.c:283) [ 92.789616][ T3827] __ia32_sys_lseek (read_write.c:391) [ 92.791786][ T3827] ia32_sys_call (kbuild/obj/consumer/i386-randconfig-013-20260610/./arch/x86/include/generated/asm/syscalls_32.h:20) [ 92.793792][ T3827] __do_fast_syscall_32 (x86/entry/syscall_32.c:83) [ 92.795973][ T3827] do_fast_syscall_32 (x86/entry/syscall_32.c:332) [ 92.797992][ T3827] do_SYSENTER_32 (x86/entry/syscall_32.c:370) [ 92.799987][ T3827] entry_SYSENTER_32 (x86/entry/entry_32.S:835) If I get it correctly then traverse() might take spin_lock_bh(lock) via: + traverse() + tcp_seq_start() + tcp_get_idx() + established_get_idx() + established_get_first() + spin_lock_bh(lock); And then it calls vsnprintf(" %pK" in + tcp6_seq_show() + get_tcp6_sock() + seq_printf() By other words, it calls vsnprintf("%pK") with disabled softirqs. If I get it correctly then this might create a deadlock because vsnprinf("%pK") can be called also with (soft)irqs enabled, then soft(irq) might came and want to take the spin_lock(lock)... As a result, we should not use %pK in tcp6_seq_show(). Best Regards, Petr