Subject: Re: [PATCH 42/53] perf record: Prevent reading invalid data in record__mmap_read

From: Sergei Shtylyov <[email-masked]>
Date: Mon, 11 Jan 2016 17:21:44 +0300

Hello.

On 01/11/2016 04:48 PM, Wang Nan wrote:

> When record__mmap_read() require data more than the size of ring
> buffer, drop those data to avoid access invalid memory.
>
> This can happen when reading from overwritable ring buffer, which
> should be avoided. However, check this for robustness.
>
> Signed-off-by: Wang Nan <[email-masked]>
> Signed-off-by: He Kuang <[email-masked]>
> Cc: Arnaldo Carvalho de Melo <[email-masked]>
> Cc: Jiri Olsa <[email-masked]>
> Cc: Masami Hiramatsu <[email-masked]>
> Cc: Namhyung Kim <[email-masked]>
> Cc: Zefan Li <[email-masked]>
> Cc: [email-masked]
> ---
>   tools/perf/builtin-record.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
>
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index b65b41f..3f58426 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -37,6 +37,7 @@
>   #include <unistd.h>
>   #include <sched.h>
>   #include <sys/mman.h>
> +#include <asm/bug.h>
>
>
>   struct record {
> @@ -94,6 +95,13 @@ static int record__mmap_read(struct record *rec, int idx)
>   	rec->samples++;
>
>   	size = head - old;
> +	if (size > (unsigned long)(md->mask) + 1) {
> +		WARN_ONCE(1, "WARNING: failed to keep up with mmap data. (warn only once)\n");

    WARNING is already printed by WARN*(), no?

[...]

MBR, Sergei