Skip to content

Instantly share code, notes, and snippets.

@florianl
Created January 31, 2026 12:52
Show Gist options
  • Select an option

  • Save florianl/41e2bce29ffde797536eef9b2e47ba92 to your computer and use it in GitHub Desktop.

Select an option

Save florianl/41e2bce29ffde797536eef9b2e47ba92 to your computer and use it in GitHub Desktop.
From 9c3af2c44583e83444bfd19a45e0beaba4f2e8e6 Mon Sep 17 00:00:00 2001
From: Florian Lehner <dev@der-flo.net>
Date: Wed, 28 Jan 2026 20:05:10 +0100
Subject: [PATCH] kallsyms: TBD
TBD
Signed-off-by: Florian Lehner <dev@der-flo.net>
---
include/linux/filter.h | 8 ++++++++
kernel/bpf/core.c | 39 +++++++++++++++++++++++++++++++++++++++
kernel/kallsyms.c | 8 +++++---
3 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/include/linux/filter.h b/include/linux/filter.h
index fd54fed8f95f..95fedda5ca9e 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -1380,6 +1380,8 @@ int __bpf_address_lookup(unsigned long addr, unsigned long *size,
bool is_bpf_text_address(unsigned long addr);
int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
char *sym);
+int bpf_get_kallsym_next(void **iter, unsigned long *value, char *type,
+ char *sym);
struct bpf_prog *bpf_prog_ksym_find(unsigned long addr);
static inline int
@@ -1448,6 +1450,12 @@ static inline int bpf_get_kallsym(unsigned int symnum, unsigned long *value,
return -ERANGE;
}
+static inline int bpf_get_kallsym_next(void **iter, unsigned long *value,
+ char *type, char *sym)
+{
+ return -ERANGE;
+}
+
static inline struct bpf_prog *bpf_prog_ksym_find(unsigned long addr)
{
return NULL;
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 1b9b18e5b03c..52b63f1510bb 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -822,6 +822,45 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
return ret;
}
+int bpf_get_kallsym_next(void **iter, unsigned long *value, char *type,
+ char *sym)
+{
+ struct bpf_ksym *ksym = *iter;
+ struct list_head *head = &bpf_kallsyms;
+ int ret = -ERANGE;
+
+ if (!bpf_jit_kallsyms_enabled())
+ return ret;
+
+ rcu_read_lock();
+
+ if (!ksym) {
+ if (list_empty(head))
+ goto out;
+ ksym = list_first_entry_rcu(head, struct bpf_ksym, lnode);
+ } else {
+ if (list_is_last(&ksym->lnode, head))
+ goto out;
+ ksym = list_next_entry_rcu(ksym, lnode);
+ }
+
+ strscpy(sym, ksym->name, KSYM_NAME_LEN);
+ *value = ksym->start;
+ *type = BPF_SYM_ELF_TYPE;
+
+ *iter = ksym;
+ ret = 0;
+
+out:
+ rcu_read_unlock();
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(bpf_get_kallsym_next);
+
int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
struct bpf_jit_poke_descriptor *poke)
{
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 049e296f586c..5260b9caf4c4 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -566,6 +566,7 @@ struct kallsym_iter {
char module_name[MODULE_NAME_LEN];
int exported;
int show_value;
+ void *bpf_ksym_iter;
};
static int get_ksymbol_mod(struct kallsym_iter *iter)
@@ -607,9 +608,9 @@ static int get_ksymbol_bpf(struct kallsym_iter *iter)
strscpy(iter->module_name, "bpf", MODULE_NAME_LEN);
iter->exported = 0;
- ret = bpf_get_kallsym(iter->pos - iter->pos_ftrace_mod_end,
- &iter->value, &iter->type,
- iter->name);
+ ret = bpf_get_kallsym_next(&iter->bpf_ksym_iter,
+ &iter->value, &iter->type,
+ iter->name);
if (ret < 0) {
iter->pos_bpf_end = iter->pos;
return 0;
@@ -656,6 +657,7 @@ static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
iter->pos_mod_end = 0;
iter->pos_ftrace_mod_end = 0;
iter->pos_bpf_end = 0;
+ iter->bpf_ksym_iter = NULL;
}
}
--
2.52.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment