ring-buffer: Check if buffer exists before polling
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>
Tue, 10 Jun 2014 13:46:00 +0000 (09:46 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2014 22:58:03 +0000 (15:58 -0700)
commit561237e441b2183b6e22a1c76a23480ff1eedb95
treecdb387d11e47a47cb2a61b828e18f5d59802a113
parent5f4b3e2d0a35f52fe522d8bacc0631d0271e709a
ring-buffer: Check if buffer exists before polling

commit 8b8b36834d0fff67fc8668093f4312dd04dcf21d upstream.

The per_cpu buffers are created one per possible CPU. But these do
not mean that those CPUs are online, nor do they even exist.

With the addition of the ring buffer polling, it assumes that the
caller polls on an existing buffer. But this is not the case if
the user reads trace_pipe from a CPU that does not exist, and this
causes the kernel to crash.

Simple fix is to check the cpu against buffer bitmask against to see
if the buffer was allocated or not and return -ENODEV if it is
not.

More updates were done to pass the -ENODEV back up to userspace.

Link: http://lkml.kernel.org/r/5393DB61.6060707@oracle.com
Reported-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/ring_buffer.h
kernel/trace/ring_buffer.c
kernel/trace/trace.c
kernel/trace/trace.h