lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20200209102530.26115-1-frextrite@gmail.com>
Date:   Sun,  9 Feb 2020 15:55:31 +0530
From:   Amol Grover <frextrite@...il.com>
To:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...hat.com>,
        Namhyung Kim <namhyung@...nel.org>
Cc:     linux-kernel@...r.kernel.org,
        linux-kernel-mentees@...ts.linuxfoundation.org,
        Joel Fernandes <joel@...lfernandes.org>,
        Madhuparna Bhowmik <madhuparnabhowmik10@...il.com>,
        "Paul E . McKenney" <paulmck@...nel.org>,
        Amol Grover <frextrite@...il.com>
Subject: [PATCH] perf_event: Annotate rb pointer with __rcu

perf_event::rb is used in RCU context, tell sparse
about it aswell to eliminate false-positives.

Fixes the following instances of sparse error:
incompatible types in comparison expression (different address spaces)
kernel/events/core.c:5596:9
kernel/events/core.c:5302:22
kernel/events/core.c:5438:14
kernel/events/core.c:5471:14
kernel/events/core.c:5528:14
kernel/events/core.c:5614:14
kernel/events/core.c:5627:14
kernel/events/core.c:7182:13
kernel/events/ring_buffer.c:169:14
kernel/events/ring_buffer.c:169:14
kernel/events/ring_buffer.c:169:14

This introduces the following 2 new sparse errors:
kernel/events/core.c:7212:9
kernel/events/core.c:5749:31

which are fixed by using RCU primitives, rcu_dereference()
and rcu_access_pointer() on perf_event::rb.

Signed-off-by: Amol Grover <frextrite@...il.com>
---
 include/linux/perf_event.h | 2 +-
 kernel/events/core.c       | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 6d4c22aee384..1691107d2800 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -694,7 +694,7 @@ struct perf_event {
 	struct mutex			mmap_mutex;
 	atomic_t			mmap_count;
 
-	struct ring_buffer		*rb;
+	struct ring_buffer __rcu	*rb;
 	struct list_head		rb_entry;
 	unsigned long			rcu_batches;
 	int				rcu_pending;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 2173c23c25b4..7b9411d21165 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5746,7 +5746,7 @@ static void perf_mmap_close(struct vm_area_struct *vma)
 		 * still restart the iteration to make sure we're not now
 		 * iterating the wrong list.
 		 */
-		if (event->rb == rb)
+		if (rcu_access_pointer(event->rb) == rb)
 			ring_buffer_attach(event, NULL);
 
 		mutex_unlock(&event->mmap_mutex);
@@ -7209,7 +7209,8 @@ static void perf_pmu_output_stop(struct perf_event *event)
 
 restart:
 	rcu_read_lock();
-	list_for_each_entry_rcu(iter, &event->rb->event_list, rb_entry) {
+	list_for_each_entry_rcu(iter, &rcu_dereference(event->rb)->event_list,
+				rb_entry) {
 		/*
 		 * For per-CPU events, we need to make sure that neither they
 		 * nor their children are running; for cpu==-1 events it's
-- 
2.24.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ