public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
	Dylan Hatch <dylanbhatch@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] getrusage: use sig->stats_lock rather than lock_task_sighand()
Date: Tue, 23 Jan 2024 16:53:49 +0100	[thread overview]
Message-ID: <20240123155349.GA9978@redhat.com> (raw)
In-Reply-To: <20240122155723.149081552c9a9e122b1f783b@linux-foundation.org>

On 01/22, Andrew Morton wrote:
>
> On Mon, 22 Jan 2024 16:50:53 +0100 Oleg Nesterov <oleg@redhat.com> wrote:
>
> > lock_task_sighand() can trigger a hard lockup. If NR_CPUS threads call
> > getrusage() at the same time and the process has NR_THREADS, spin_lock_irq
> > will spin with irqs disabled O(NR_CPUS * NR_THREADS) time.
>
> It would be super interesting to see Dylan's original report.

from "[RFC PATCH] getrusage: Use trylock when getting sighand lock."
https://lore.kernel.org/all/20240117192534.1327608-1-dylanbhatch@google.com/

	Processes with many threads run the risk of causing a hard lockup if
	too many threads are calling getrusage() at once. This is because a
	calling thread with RUSAGE_SELF spins on the sighand lock with irq
	disabled, and the critical section of getrusage scales linearly with the
	size of the process. All cpus may end up spinning on the sighand lock
	for a long time because another thread has the lock and is busy
	iterating over 250k+ threads.

> Is it possible for carefully-crafted unprivileged userspace to
> deliberately trigger this?

Yes, just you need to create a process with a lot of threads calling
getrusage().

See mine and Dylan's test-cases in
https://lore.kernel.org/all/CADBMgpz7k=LhktfcJhSDBDWN0oLeQxPqhOVws3fq0LNpnfOSYg@mail.gmail.com/
There are very similar and simple.


And again, this is a known problem and we need more fixes.

Oleg.


  reply	other threads:[~2024-01-23 15:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22 15:50 [PATCH v2 0/2] getrusage: use sig->stats_lock Oleg Nesterov
2024-01-22 15:50 ` [PATCH v2 1/2] getrusage: move thread_group_cputime_adjusted() outside of lock_task_sighand() Oleg Nesterov
2024-01-22 15:50 ` [PATCH v2 2/2] getrusage: use sig->stats_lock rather than lock_task_sighand() Oleg Nesterov
2024-01-22 23:57   ` Andrew Morton
2024-01-23 15:53     ` Oleg Nesterov [this message]
2024-01-23 23:45 ` [PATCH v2 0/2] getrusage: use sig->stats_lock Dylan Hatch
2024-01-24  0:39   ` Oleg Nesterov

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=20240123155349.GA9978@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=dylanbhatch@google.com \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.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