[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tip-8184059e93c200757f5c0805dae0f14e880eab5d@git.kernel.org>
Date: Mon, 21 Mar 2016 02:51:03 -0700
From: tip-bot for Peter Zijlstra <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: vincent.weaver@...ne.edu, sasha.levin@...cle.com, acme@...hat.com,
bp@...en8.de, acme@...nel.org, luto@...capital.net,
namhyung@...nel.org, eranian@...gle.com, peterz@...radead.org,
tglx@...utronix.de, jolsa@...hat.com, brgerst@...il.com,
hpa@...or.com, alexander.shishkin@...ux.intel.com,
dsahern@...il.com, linux-kernel@...r.kernel.org, mingo@...nel.org,
dvlasenk@...hat.com, ryabinin.a.a@...il.com,
torvalds@...ux-foundation.org
Subject: [tip:perf/urgent] perf/core: Fix Undefined behaviour in rb_alloc()
Commit-ID: 8184059e93c200757f5c0805dae0f14e880eab5d
Gitweb: http://git.kernel.org/tip/8184059e93c200757f5c0805dae0f14e880eab5d
Author: Peter Zijlstra <peterz@...radead.org>
AuthorDate: Fri, 29 Jan 2016 15:17:51 +0100
Committer: Ingo Molnar <mingo@...nel.org>
CommitDate: Mon, 21 Mar 2016 09:08:18 +0100
perf/core: Fix Undefined behaviour in rb_alloc()
Sasha reported:
[ 3494.030114] UBSAN: Undefined behaviour in kernel/events/ring_buffer.c:685:22
[ 3494.030647] shift exponent -1 is negative
Andrey spotted that this is because:
It happens if nr_pages = 0:
rb->page_order = ilog2(nr_pages);
Fix it by making both assignments conditional on nr_pages; since
otherwise they should both be 0 anyway, and will be because of the
kzalloc() used to allocate the structure.
Reported-by: Sasha Levin <sasha.levin@...cle.com>
Reported-by: Andrey Ryabinin <ryabinin.a.a@...il.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: Andy Lutomirski <luto@...capital.net>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Borislav Petkov <bp@...en8.de>
Cc: Brian Gerst <brgerst@...il.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Denys Vlasenko <dvlasenk@...hat.com>
Cc: H. Peter Anvin <hpa@...or.com>
Cc: Jiri Olsa <jolsa@...hat.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Stephane Eranian <eranian@...gle.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Vince Weaver <vincent.weaver@...ne.edu>
Link: http://lkml.kernel.org/r/20160129141751.GA407@worktop
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
kernel/events/ring_buffer.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 1faad2c..c61f0cb 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -746,8 +746,10 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
rb->user_page = all_buf;
rb->data_pages[0] = all_buf + PAGE_SIZE;
- rb->page_order = ilog2(nr_pages);
- rb->nr_pages = !!nr_pages;
+ if (nr_pages) {
+ rb->nr_pages = 1;
+ rb->page_order = ilog2(nr_pages);
+ }
ring_buffer_init(rb, watermark, flags);
Powered by blists - more mailing lists