From: Thomas Weissschuh <thomas.weissschuh@linutronix.de>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Alessandro Carminati <acarmina@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-rt-devel@lists.linux.dev,
Alessandro Carminati <alessandro.carminati@gmail.com>,
Juri Lelli <juri.lelli@redhat.com>,
Gabriele Paoloni <gpaoloni@redhat.com>,
Eric Chanudet <echanude@redhat.com>
Subject: Re: [PATCH] mm/kmemleak: Fix sleeping function called from invalid context in kmemleak_seq_show
Date: Wed, 20 Nov 2024 16:13:28 +0100 [thread overview]
Message-ID: <20241120160448-11661c83-6a2e-4afb-9711-ffec3f9342b5@linutronix.de> (raw)
In-Reply-To: <Zz332cG45rNSeE_B@arm.com>
On Wed, Nov 20, 2024 at 02:53:13PM +0000, Catalin Marinas wrote:
> On Wed, Nov 20, 2024 at 10:23:25AM +0000, Alessandro Carminati wrote:
> > This patch addresses a bug in the RT variant of the kernel where a
> > "sleeping function called from invalid context" warning may occur in
> > kmemleak_seq_show under specific conditions:
> > - CONFIG_PREEMPT_RT=y
> > - SELinux is the LSM for the system
> > - `kptr_restrict` is set to 1.
> > - The kmemleak buffer contains at least one item.
> >
> > Commit 8c96f1bc6fc49c724c4cdd22d3e99260263b7384 ("mm/kmemleak: turn
> > kmemleak_lock and object->lock to raw_spinlock_t") introduced a change
> > where kmemleak_seq_show is executed in atomic context within the RT kernel.
> > However, the SELinux capability check within this function flow still
> > relies on regular spinlocks, leading to potential race conditions that
> > trigger the error when printing the kmemleak backtrace.
> >
> > To resolve this, the backtrace printing has been moved out of the critical
> > section.
[..]
> 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 not
> 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.
Yes, this is a problem for all users of lib/vsprintf.c.
I am working on a fix for this, to avoid calling the sleeping functions
from contexts which are not allowed to do so.
In these cases the pointers would not be printed.
This fix for kmemleak is still needed as the pointers in the kmemleak
report are useful.
Thomas
next prev parent reply other threads:[~2024-11-20 15:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-20 10:23 Alessandro Carminati
2024-11-20 14:53 ` Catalin Marinas
2024-11-20 15:13 ` Thomas Weissschuh [this message]
2024-11-20 15:26 ` Steven Rostedt
2024-11-20 16:36 ` Alessandro Carminati
2024-11-20 16:40 ` Sebastian Andrzej Siewior
2024-11-21 16:50 ` Alessandro Carminati
2024-11-21 17:03 ` Sebastian Andrzej Siewior
2024-11-22 10:48 ` Alessandro Carminati
2024-11-26 8:11 ` Thomas Weissschuh
2024-11-26 10:49 ` Catalin Marinas
2024-11-21 19:19 ` Catalin Marinas
2024-11-22 8:14 ` Sebastian Andrzej Siewior
2024-11-22 10:12 ` Catalin Marinas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241120160448-11661c83-6a2e-4afb-9711-ffec3f9342b5@linutronix.de \
--to=thomas.weissschuh@linutronix.de \
--cc=acarmina@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alessandro.carminati@gmail.com \
--cc=bigeasy@linutronix.de \
--cc=catalin.marinas@arm.com \
--cc=clrkwllms@kernel.org \
--cc=echanude@redhat.com \
--cc=gpaoloni@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox