From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6BB721A444 for ; Wed, 18 Mar 2026 13:59:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773842381; cv=none; b=EHQdTfippxDLiXxwKX2rQAnMe7wq9Xr9jpsR06lwGLJbHJilm4lSj89+/o8XX3sQLg2fGectu4398+jTrOa1uP8lJv3q+A2+TpMfCqnbAGu0bK2J9RSMUi0viy/MfXvZZNNVtxZYHHN6nJQUy0LwPeUvTBl/HELCLDUdjJ1NYdA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773842381; c=relaxed/simple; bh=m2SoAavqtnnI4nLrjb5awGH5kOFLCT78gYa+WMwSw10=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GHRVjqolLlKkkhcm8DhNfUBMeb+R5Ki2xyZlXs4uP3z59ynr8EXNEylr6m+cTUsGcD+ZLC6Q532HRqelXi95BJWaMYUlitHUNT2AkgveZ5TEBL28PCzmkmhtf9TFCYcNLZDB+A8EHKZStZIgiTZo9yfUcwbGCc0KiSiT7vnbBFw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KYr7maak; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/DHFrLfQ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KYr7maak"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/DHFrLfQ" Date: Wed, 18 Mar 2026 14:59:36 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1773842377; 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=7249HTTW29v0vxRbX6U7cyYfaKsruoSCMLAVHS4OrjE=; b=KYr7maak3L+Vkef0xLV1X34KQL7rpM9IJ+JaagTLeMBi636Ha0Ky1c2EPiuYxzJe7MfMof mXb73YXXlOS06L4sBth0UKTpMNYfyCnmVu6btUp8qlqLZHJLwDupUzzayfY1oLwoOJqW5d 2eAvXpE22Pa5PgO6zdxBjDeXAJNI6Xma4RkkStUI+Gdb+wr4nmyGQkI0mCpNeZwB0PvcD1 l3xnyeKlOSs0mmr+y2Ju0sCoaJKT1TDBYesYNaFGNwDQJNHqMPR3OJ8Z+O3ZGfGdY6K3Bg 7RC4mfkOjmrjmbUGKGGVqJ8S3ZlnTrBnB3RwN8nOTjMXPIOIQWNCIt199rUR1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1773842377; 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=7249HTTW29v0vxRbX6U7cyYfaKsruoSCMLAVHS4OrjE=; b=/DHFrLfQBad/AHkWm6lVLnO8CrWHo0IVAhiSuTwnRDNiKKPYi/921S5CoCzx7tuP37m1d/ Z9zbNS9eiumEidAg== From: Sebastian Andrzej Siewior To: Petr Mladek , Kees Cook Cc: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= , Andrew Morton , Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , linux-kernel@vger.kernel.org, John Ogness Subject: Re: [PATCH] lib/vsprintf: Validate sleepable context during restrictred pointer formatting Message-ID: <20260318135936.mGaAlujF@linutronix.de> References: <20260317-restricted-pointers-final-v1-1-b4dca0ed6483@linutronix.de> <20260318094555-37b1a6ce-4977-4e54-95f2-2a30bec904e1@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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: On 2026-03-18 12:03:39 [+0100], Petr Mladek wrote: > Now, really with John and Sebastian in Cc. >=20 > On Wed 2026-03-18 09:48:06, Thomas Wei=C3=9Fschuh wrote: > > On Tue, Mar 17, 2026 at 12:41:23PM +0100, Thomas Wei=C3=9Fschuh wrote: > > > Depending on the system configuration, the restricted pointer formatt= ing > > > might call into the security subsystem which might sleep. > > > As %pK is intended to be only used from read handlers of virtual file= s, > > > which always run in task context, this should never happen in practic= e. > > > 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 accidental= ly > > > in the future. > > >=20 > > > Add a might_sleep(), so that misuse of %pK from atomic context is > > > detected right away. > > >=20 > > > Link: https://lore.kernel.org/lkml/20250113171731-dc10e3c1-da64-4af0-= b767-7c7070468023@linutronix.de/ > > > Link: https://lore.kernel.org/lkml/20241217142032.55793-1-acarmina@re= dhat.com/ > > > Signed-off-by: Thomas Wei=C3=9Fschuh > > > --- > > > This depends on commit 5886cc8f895b ("drm/msm/dpu: Don't use %pK thro= ugh > > > printk (again)"), which was merged in v7.0-rc2. > > > --- > > > lib/vsprintf.c | 3 +++ > > > 1 file changed, 3 insertions(+) > > >=20 > > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > > > index 800b8ac49f53..eb9dbb28fb9b 100644 > > > --- a/lib/vsprintf.c > > > +++ b/lib/vsprintf.c > > > @@ -862,6 +862,9 @@ static noinline_for_stack > > > char *restricted_pointer(char *buf, char *end, const void *ptr, > > > struct printf_spec spec) > > > { > > > + /* Only usable from task context, The call to has_capability_noaudi= t() might sleep. */ > > > + might_sleep(); > > > + > >=20 > > So might_sleep() is not actually the right thing to do here. > > Some callers use %pK under a spinlock, which fails the might_sleep() ch= eck. > > However this is fine to do, as has_capability_noaudit() also only takes= a > > spinlock. >=20 > My understanding is that we want to simulate that we are going > to call a normal spin_lock() which might sleep in PREEMPT_RT. > So that we trigger the warning when %pK is used under > a raw_spin_lock. >=20 > It might likely be achieved by adding a "fake" spin_lock and might_lock(). > I am not sure if there is an easier way by using just > a struct lockdep_map. >=20 > I am always a bit confused by the lockdep annotation. might_sleep() seems reasonable if any usage under spinlock_t can be excluded. If the usage is intended to happen only from task context then in_task() would make sense. This would already ban any softirq context and everything else I know we had in the past. The fake spinlock_t could be achieved by just something like might_lock() which would avoid any overhead of real locking. But do we still need %pK? There are far more %p users in seq_printf() context as per git grep -E 'seq_printf.*%p\>' than %pK. According to commit 312b4e226951f ("vsprintf: check real user/group id for %pK") it is temporary as of 2013. There should be a check at open time instead. > >=20 > > > switch (kptr_restrict) { > > > case 0: > > > /* Handle as %p, hash and do _not_ leak addresses. */ >=20 > Best Regards, > Petr Sebastian