LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: songliubraving@fb.com, peterz@infradead.org, mingo@redhat.com,
	alexander.shishkin@linux.intel.com, miklos@szeredi.hu
Cc: acme@kernel.org, jolsa@redhat.com, namhyung@kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] perf/core: Fix crash when using HW tracing kernel filters
Date: Mon, 16 Jul 2018 17:13:51 -0600
Message-ID: <1531782831-1186-1-git-send-email-mathieu.poirier@linaro.org> (raw)

In function perf_event_parse_addr_filter(), the path::dentry of each struct
perf_addr_filter is left unassigned (as it should be) when the pattern
being parsed is related to kernel space.  But in function
perf_addr_filter_match() the same dentry'ies are given to d_inode() where
the value is not expected to be NULL, resulting in the following splat:

[   53.451557] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000058
[   53.460368] Mem abort info:
[   53.463134]   ESR = 0x96000004
[   53.466158]   Exception class = DABT (current EL), IL = 32 bits
[   53.472019]   SET = 0, FnV = 0
[   53.475042]   EA = 0, S1PTW = 0
[   53.478150] Data abort info:
[   53.481000]   ISV = 0, ISS = 0x00000004
[   53.484796]   CM = 0, WnR = 0
[   53.487734] user pgtable: 4k pages, 48-bit VAs, pgdp = 00000000f0644b81
[   53.494283] [0000000000000058] pgd=0000000000000000
[   53.499181] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[   53.504697] Modules linked in:
[   53.507726] CPU: 2 PID: 2860 Comm: uname Not tainted 4.18.0-rc5-dirty #288
[   53.514531] Hardware name: ARM Juno development board (r0) (DT)
[   53.520392] pstate: 20000085 (nzCv daIf -PAN -UAO)
[   53.525141] pc : perf_event_mmap+0x2fc/0x5a0
[   53.529368] lr : perf_event_mmap+0x2c8/0x5a0
[   53.533593] sp : ffff000010883a10
[   53.536872] x29: ffff000010883a10 x28: ffff8009749126c0
[   53.542137] x27: 0000000000000000 x26: ffff800971221000
[   53.547401] x25: ffff80097678bef0 x24: ffff0000091cb000
[   53.552665] x23: ffff800971221430 x22: ffff80097100fe00
[   53.557930] x21: 0000000000001078 x20: ffff0000091af000
[   53.563194] x19: ffff800971221420 x18: 0000000000006451
[   53.568457] x17: 000000000000644f x16: ffff000009404790
[   53.573721] x15: ffff00000932c3b0 x14: 000000000000644e
[   53.578985] x13: 00000000ed3bb5ef x12: ffff8009711e1de8
[   53.584248] x11: 0000000000000000 x10: ffff0000091af808
[   53.589512] x9 : ffff0000091ea000 x8 : ffff0000091af808
[   53.594776] x7 : 0000000000000002 x6 : ffff8009740c7540
[   53.600040] x5 : 0000000000000000 x4 : 00000000000067e8
[   53.605303] x3 : 0000000000000000 x2 : ffff800971131800
[   53.610567] x1 : 0000000000000002 x0 : 0000000000000000
[   53.615832] Process uname (pid: 2860, stack limit = 0x000000001cbcca37)
[   53.622378] Call trace:
[   53.624798]  perf_event_mmap+0x2fc/0x5a0
[   53.628683]  mmap_region+0x124/0x570
[   53.632221]  do_mmap+0x344/0x4f8
[   53.635414]  vm_mmap_pgoff+0xe4/0x110
[   53.639037]  vm_mmap+0x2c/0x40
[   53.642061]  elf_map+0x60/0x108
[   53.645169]  load_elf_binary+0x450/0x12c4
[   53.649138]  search_binary_handler+0x90/0x290
[   53.653449]  __do_execve_file.isra.13+0x6e4/0x858
[   53.658104]  sys_execve+0x3c/0x50
[   53.661385]  el0_svc_naked+0x30/0x34
[   53.664924] Code: eb02027f 54000300 f9400c45 f94012c6 (f9402ca5)
[   53.670959] ---[ end trace 3ef799e7226990e4 ]---

This patch is fixing the problem by introducing a new check in function
perf_addr_filter_match() to see if the filter's dentry is NULL.

Fixes: 9511bce9fe8e ("perf/core: Fix bad use of igrab()")
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 kernel/events/core.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 8f0434a9951a..a56f10b1e13b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7335,6 +7335,10 @@ static bool perf_addr_filter_match(struct perf_addr_filter *filter,
 				     struct file *file, unsigned long offset,
 				     unsigned long size)
 {
+	/* d_inode(NULL) won't be equal to any mapped user space file */
+	if (!filter->path.dentry)
+		return false;
+
 	if (d_inode(filter->path.dentry) != file_inode(file))
 		return false;
 
-- 
2.7.4


             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16 23:13 Mathieu Poirier [this message]
2018-07-25 14:31 ` [tip:perf/core] " tip-bot for Mathieu Poirier

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=1531782831-1186-1-git-send-email-mathieu.poirier@linaro.org \
    --to=mathieu.poirier@linaro.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=songliubraving@fb.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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git