public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@armlinux.org.uk>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H . Peter Anvin" <hpa@zytor.com>, Jon Medhurst <tixy@linaro.org>,
	Wang Nan <wangnan0@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	"David A . Long" <dave.long@linaro.org>,
	Sandeepa Prabhu <sandeepa.s.prabhu@gmail.com>
Subject: Re: [BUGFIX PATCH tip/master V2 3/3] kprobes/arm: Fix a possible deadlock case in kretprobe
Date: Thu, 9 Feb 2017 16:49:00 +0000	[thread overview]
Message-ID: <20170209164859.GI27312@n2100.armlinux.org.uk> (raw)
In-Reply-To: <148665793195.22817.17284342421982011651.stgit@devbox>

On Fri, Feb 10, 2017 at 01:32:22AM +0900, Masami Hiramatsu wrote:
> Fix a possibility of deadlock case in kretprobe on arm
> implementation. There may be a chance that the kretprobe
> hash table lock can cause a dead lock.
> 
> The senario is that a user puts 2 kretprobes, one on normal
> function and one on a function which can be called from
> somewhare which can interrupt in irq disabled critical
> section like FIQ.

If we:
- hit a kernel tracing feature from FIQ context
- the tracing feature takes a lock
- the lock is also taken elsewhere on the same CPU with IRQs disabled

we will quite simply deadlock.

In this case, kretprobe_hash_lock() takes the hlist_lock using
raw_spin_lock_irqsave().

Now, from what I can see in the kprobes code, this lock is taken in
other contexts (eg, kprobe_flush_task()), which means even with this
fix, it's still risky if a kprobe is placed on a FIQ-called function.

> In this case, if the kernel hits the 1st kretprobe on a
> normal function return which calls trampoline_handler(),
> acquire a spinlock on the hash table in kretprobe_hash_lock()
> and disable irqs. After that, if the 2nd kretprobe is kicked
> from FIQ, it also calls trampoline_handler() and tries to
> acquire the same spinlock (since the hash is based on
> current task, same as the 1st kretprobe), it causes
> a deadlock.

So my deadlock scenario is:

- we're in the middle of kprobe_flush_task()
- FIQ happens, calls trampoline_handler()
- deadlock in kretprobe_hash_lock()

>From what I can see, kretprobes in FIQ are just unsafe.

I suspect that avoiding these deadlocks means that we have to deny
kprobes from FIQ context - making trampoline_handler() return
immediately if in_nmi() is true.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

  reply	other threads:[~2017-02-09 17:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-09 16:28 [BUGFIX PATCH tip/master V2 0/3] kprobes: Fix a possible deadlock in kretprobe Masami Hiramatsu
2017-02-09 16:30 ` [BUGFIX PATCH tip/master V2 1/3] kprobes/x86: Fix a possible deadlock case " Masami Hiramatsu
2017-02-09 16:31 ` [BUGFIX PATCH tip/master V2 2/3] kprobes/arm64: " Masami Hiramatsu
2017-02-09 16:32 ` [BUGFIX PATCH tip/master V2 3/3] kprobes/arm: " Masami Hiramatsu
2017-02-09 16:49   ` Russell King - ARM Linux [this message]
2017-02-10  2:34     ` Masami Hiramatsu
2017-02-10 22:33       ` Masami Hiramatsu
2017-02-10 23:21         ` Russell King - ARM Linux
2017-02-11  9:21           ` Masami Hiramatsu
2017-02-10 22:52 ` [BUGFIX PATCH tip/master V2 0/3] kprobes: Fix a possible deadlock " Masami Hiramatsu

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=20170209164859.GI27312@n2100.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=catalin.marinas@arm.com \
    --cc=dave.long@linaro.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sandeepa.s.prabhu@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=tixy@linaro.org \
    --cc=wangnan0@huawei.com \
    --cc=will.deacon@arm.com \
    /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