Skip to content

Commit 63bfd73

Browse files
penbergtorvalds
authored andcommitted
perf_events: Fix perf_counter_mmap() hook in mprotect()
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 <[email protected]> Analyzed-by: Linus Torvalds <[email protected]> Cc: Ingo Molnar <[email protected]> Reviewed-by: Peter Zijlstra <[email protected]> Signed-off-by: Pekka Enberg <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 814ce25 commit 63bfd73

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/mprotect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
211211
mmu_notifier_invalidate_range_end(mm, start, end);
212212
vm_stat_account(mm, oldflags, vma->vm_file, -nrpages);
213213
vm_stat_account(mm, newflags, vma->vm_file, nrpages);
214+
perf_event_mmap(vma);
214215
return 0;
215216

216217
fail:
@@ -299,7 +300,6 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
299300
error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
300301
if (error)
301302
goto out;
302-
perf_event_mmap(vma);
303303
nstart = tmp;
304304

305305
if (nstart < prev->vm_end)

0 commit comments

Comments
 (0)