[PATCH v1 net 06/15] bpf: Fix data-races around bpf_jit_kallsyms.

From: Kuniyuki Iwashima
Date: Tue Aug 16 2022 - 04:04:18 EST


While reading bpf_jit_kallsyms, it can be changed concurrently.
Thus, we need to add READ_ONCE() to its readers.

Fixes: 74451e66d516 ("bpf: make jited programs visible in traces")
Signed-off-by: Kuniyuki Iwashima <kuniyu@xxxxxxxxxx>
---
CC: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
---
include/linux/filter.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/filter.h b/include/linux/filter.h
index 09566ad211bd..35881fccce05 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -1110,14 +1110,16 @@ static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog)

static inline bool bpf_jit_kallsyms_enabled(void)
{
+ int jit_kallsyms = READ_ONCE(bpf_jit_kallsyms);
+
/* There are a couple of corner cases where kallsyms should
* not be enabled f.e. on hardening.
*/
if (READ_ONCE(bpf_jit_harden))
return false;
- if (!bpf_jit_kallsyms)
+ if (!jit_kallsyms)
return false;
- if (bpf_jit_kallsyms == 1)
+ if (jit_kallsyms == 1)
return true;

return false;
--
2.30.2