Skip to content

Commit f88886d

Browse files
Alexei Starovoitovanakryiko
authored andcommitted
bpf: Add namespace to BPF internal symbols
Add namespace to BPF internal symbols used by light skeleton to prevent abuse and document with the code their allowed usage. Fixes: b1d18a7 ("bpf: Extend sys_bpf commands for bpf_syscall programs.") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/bpf/20250425014542.62385-1-alexei.starovoitov@gmail.com
1 parent 6ae003a commit f88886d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Documentation/bpf/bpf_devel_QA.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ In case of new BPF instructions, once the changes have been accepted
382382
into the Linux kernel, please implement support into LLVM's BPF back
383383
end. See LLVM_ section below for further information.
384384

385+
Q: What "BPF_INTERNAL" symbol namespace is for?
386+
-----------------------------------------------
387+
A: Symbols exported as BPF_INTERNAL can only be used by BPF infrastructure
388+
like preload kernel modules with light skeleton. Most symbols outside
389+
of BPF_INTERNAL are not expected to be used by code outside of BPF either.
390+
Symbols may lack the designation because they predate the namespaces,
391+
or due to an oversight.
392+
385393
Stable submission
386394
=================
387395

kernel/bpf/preload/bpf_preload_kern.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,6 @@ static void __exit fini(void)
8989
}
9090
late_initcall(load);
9191
module_exit(fini);
92+
MODULE_IMPORT_NS("BPF_INTERNAL");
9293
MODULE_LICENSE("GPL");
9394
MODULE_DESCRIPTION("Embedded BPF programs for introspection in bpffs");

kernel/bpf/syscall.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ struct bpf_map *bpf_map_get(u32 ufd)
15831583

15841584
return map;
15851585
}
1586-
EXPORT_SYMBOL(bpf_map_get);
1586+
EXPORT_SYMBOL_NS(bpf_map_get, "BPF_INTERNAL");
15871587

15881588
struct bpf_map *bpf_map_get_with_uref(u32 ufd)
15891589
{
@@ -3364,7 +3364,7 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd)
33643364
bpf_link_inc(link);
33653365
return link;
33663366
}
3367-
EXPORT_SYMBOL(bpf_link_get_from_fd);
3367+
EXPORT_SYMBOL_NS(bpf_link_get_from_fd, "BPF_INTERNAL");
33683368

33693369
static void bpf_tracing_link_release(struct bpf_link *link)
33703370
{
@@ -6020,7 +6020,7 @@ int kern_sys_bpf(int cmd, union bpf_attr *attr, unsigned int size)
60206020
return ____bpf_sys_bpf(cmd, attr, size);
60216021
}
60226022
}
6023-
EXPORT_SYMBOL(kern_sys_bpf);
6023+
EXPORT_SYMBOL_NS(kern_sys_bpf, "BPF_INTERNAL");
60246024

60256025
static const struct bpf_func_proto bpf_sys_bpf_proto = {
60266026
.func = bpf_sys_bpf,

0 commit comments

Comments
 (0)