mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* perf: bug, kernel ignores the buffer size on large read
@ 2015-09-02 16:34 Vince Weaver
  2015-09-02 23:08 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Vince Weaver @ 2015-09-02 16:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo


OK, this time I found the actual bug.

event->read_size is declared as a u16 in include/linux/perf_event.h

but it is very easy to get event->read_size larger than 64k
(in my case, create 10000 events in a group).

Because we wrap around the u16, the 
	 if (count < event->read_size) return -ENOSPC;
in perf_read_hw() doesn't trigger reliably and so if you do a read
on a large group event the kernel will quite happily copy_to_user()
beyond the bounds of the value set in the read syscall.  

In my case it completely smashed the stack and caused the program to 
segfault.

I'm not sure what the solution is here.  Change read_size to be larger?
Ban events whose read size would be larger than 64k?  Although that gets 
tricky because the related header_size is also only a u16.

Vince


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-03  2:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-02 16:34 perf: bug, kernel ignores the buffer size on large read Vince Weaver
2015-09-02 23:08 ` Peter Zijlstra
2015-09-03  2:32   ` Vince Weaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome