perf/core: Fix perf_sample_regs_user() mm check
authorPeter Zijlstra <peterz@infradead.org>
Wed, 29 May 2019 12:37:24 +0000 (14:37 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 5 Oct 2019 15:20:01 +0000 (16:20 +0100)
commit 085ebfe937d7a7a5df1729f35a12d6d655fea68c upstream.

perf_sample_regs_user() uses 'current->mm' to test for the presence of
userspace, but this is insufficient, consider use_mm().

A better test is: '!(current->flags & PF_KTHREAD)', exec() clears
PF_KTHREAD after it sets the new ->mm but before it drops to userspace
for the first time.

Possibly obsoletes: bf05fc25f268 ("powerpc/perf: Fix oops when kthread execs user process")

Reported-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Reported-by: Young Xiao <92siuyang@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 4018994f3d87 ("perf: Add ability to attach user level registers dump to sample")
Signed-off-by: Ingo Molnar <mingo@kernel.org>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
kernel/events/core.c

index 3beed0ea98d9cb7fabbbe0437092971d839e6689..b4c6887bdf5cf38f659b41d28d7fd83f0c5d7413 100644 (file)
@@ -4581,7 +4581,7 @@ static void perf_sample_regs_user(struct perf_regs_user *regs_user,
                                  struct pt_regs *regs)
 {
        if (!user_mode(regs)) {
-               if (current->mm)
+               if (!(current->flags & PF_KTHREAD))
                        regs = task_pt_regs(current);
                else
                        regs = NULL;