Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5b6c1b4d authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller
Browse files

bpf, trace: use READ_ONCE for retrieving file ptr



In bpf_perf_event_read() and bpf_perf_event_output(), we must use
READ_ONCE() for fetching the struct file pointer, which could get
updated concurrently, so we must prevent the compiler from potential
refetching.

We already do this with tail calls for fetching the related bpf_prog,
but not so on stored perf events. Semantics for both are the same
with regards to updates.

Fixes: a43eec30 ("bpf: introduce bpf_perf_event_output() helper")
Fixes: 35578d79 ("bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter")
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a27758ff
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ static u64 bpf_perf_event_read(u64 r1, u64 index, u64 r3, u64 r4, u64 r5)
	if (unlikely(index >= array->map.max_entries))
		return -E2BIG;

	file = (struct file *)array->ptrs[index];
	file = READ_ONCE(array->ptrs[index]);
	if (unlikely(!file))
		return -ENOENT;

@@ -247,7 +247,7 @@ static u64 bpf_perf_event_output(u64 r1, u64 r2, u64 flags, u64 r4, u64 size)
	if (unlikely(index >= array->map.max_entries))
		return -E2BIG;

	file = (struct file *)array->ptrs[index];
	file = READ_ONCE(array->ptrs[index]);
	if (unlikely(!file))
		return -ENOENT;