From: Pekka Enberg Date: Mon, 8 Nov 2010 19:29:07 +0000 (+0200) Subject: perf_events: Fix perf_counter_mmap() hook in mprotect() X-Git-Tag: firefly_0821_release~10186^2~661 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8d5be245dde97e848d0a52340e1fecbec829eb0f;p=firefly-linux-kernel-4.4.55.git perf_events: Fix perf_counter_mmap() hook in mprotect() commit 63bfd7384b119409685a17d5c58f0b56e5dc03da upstream. As pointed out by Linus, commit dab5855 ("perf_counter: Add mmap event hooks to mprotect()") is fundamentally wrong as mprotect_fixup() can free 'vma' due to merging. Fix the problem by moving perf_event_mmap() hook to mprotect_fixup(). Note: there's another successful return path from mprotect_fixup() if old flags equal to new flags. We don't, however, need to call perf_event_mmap() there because 'perf' already knows the VMA is executable. Reported-by: Dave Jones Analyzed-by: Linus Torvalds Cc: Ingo Molnar Reviewed-by: Peter Zijlstra Signed-off-by: Pekka Enberg Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- diff --git a/mm/mprotect.c b/mm/mprotect.c index 8bc969d8112d..1737c7e7af53 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -212,6 +212,7 @@ success: mmu_notifier_invalidate_range_end(mm, start, end); vm_stat_account(mm, oldflags, vma->vm_file, -nrpages); vm_stat_account(mm, newflags, vma->vm_file, nrpages); + perf_event_mmap(vma); return 0; fail: @@ -300,7 +301,6 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, error = mprotect_fixup(vma, &prev, nstart, tmp, newflags); if (error) goto out; - perf_event_mmap(vma); nstart = tmp; if (nstart < prev->vm_end)