bpf: fail mmap without CONFIG_MMU
Subsystems (4)
PATCH 1/1 bpf: fail mmap without CONFIG_MMU
mmap() support for BPF array depends on vmalloc_user_node_flags, which is available only on CONFIG_MMU configurations. Fail mmap-able allocations if no CONFIG_MMU is set.
--- kernel/bpf/syscall.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/bpf/syscall.c +4 -0
@@ -156,8 +156,12 @@ static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable) }if (mmapable) {BUG_ON (!PAGE_ALIGNED (size)); +#ifndef CONFIG_MMU +return NULL ; +#else return vmalloc_user_node_flags (size, numa_node,GFP_KERNEL | __GFP_RETRY_MAYFAIL | flags); +#endif } return __vmalloc_node_flags_caller(size, numa_node, GFP_KERNEL | __GFP_RETRY_MAYFAIL |
Signature · 1 line
2.17.1
Daniel Borkmann
maintainerQuoted 16 lines · Andrii Nakryiko
mmap()support for BPF array depends onvmalloc_user_node_flags, which is available only onCONFIG_MMUconfigurations. Fail mmap-able allocations if noCONFIG_MMUis set.Cc Johannes Weiner <[email protected]>Reported-by kbuild test robot <[email protected]>Signed-off-by Andrii Nakryiko <[email protected]>--- kernel/bpf/syscall.c | 4 ++++ 1 file changed, 4 insertions(+)kernel/bpf/syscall.c +0
-0
kernel/bpf/syscall.c static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable) · line 163
Quoted 8 lines
kernel/bpf/syscall.c +3
-0@@ -156,8 +156,12 @@ static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable) }if (mmapable) {BUG_ON (!PAGE_ALIGNED (size)); +#ifndef CONFIG_MMU +return NULL ; +#else return vmalloc_user_node_flags (size, numa_node,GFP_KERNEL | __GFP_RETRY_MAYFAIL | flags);
Hmm, this should rather live in include/linux/vmalloc.h, otherwise every future user of vmalloc_user_node_flags() would need to add this ifdef? vmalloc.h has the below, so perhaps this could be added there instead:
[..]
#ifndef CONFIG_MMU
extern void *__vmalloc_node_flags(unsigned long size, int node, gfp_t flags); static inline void *__vmalloc_node_flags_caller(unsigned long size, int node,
gfp_t flags, void *caller)
{
return __vmalloc_node_flags(size, node, flags);
}
#else
extern void *__vmalloc_node_flags_caller(unsigned long size,
int node, gfp_t flags, void *caller);#endif
[..]
Quoted 5 lines
kernel/bpf/syscall.c +1
-0+#endif } return __vmalloc_node_flags_caller(size, numa_node, GFP_KERNEL | __GFP_RETRY_MAYFAIL |
Quoted 22 lines · Daniel Borkmann
Quoted 20 lines · Andrii Nakryiko
mmap()support for BPF array depends onvmalloc_user_node_flags, which is available only onCONFIG_MMUconfigurations. Fail mmap-able allocations if noCONFIG_MMUis set.Cc Johannes Weiner <[email protected]>Reported-by kbuild test robot <[email protected]>Signed-off-by Andrii Nakryiko <[email protected]>--- kernel/bpf/syscall.c | 4 ++++ 1 file changed, 4 insertions(+)kernel/bpf/syscall.c +1
-0@@ -156,8 +156,12 @@ static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable) }if (mmapable) {BUG_ON (!PAGE_ALIGNED (size)); +#ifndef CONFIG_MMU
Quoted 8 lines
kernel/bpf/syscall.c static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable) · line 163
Quoted 4 lines
kernel/bpf/syscall.c +2
-0+return NULL ; +#else return vmalloc_user_node_flags (size, numa_node,GFP_KERNEL | __GFP_RETRY_MAYFAIL | flags);Hmm, this should rather live in
include/linux/vmalloc.h, otherwise every future user ofvmalloc_user_node_flags()would need to add this ifdef?vmalloc.hhas the below, so perhaps this could be added there instead:
Ok, I finally untangled this all. The real fix is to implement vmalloc_user_node_flags() in mm/no_mmu.c. Took me a bit to understand how all this stuff is supposed to compile. If you take a look at vmalloc.h, you'll see that most variants of vmalloc() are not conditionally defined like __vmalloc_node_flags_caller. I'll send a different patch with proper fix in few minutes.
Quoted 21 lines
[..]
#ifndefCONFIG_MMU
extern void *__vmalloc_node_flags(unsigned long size, int node,gfp_tflags); static inline void *__vmalloc_node_flags_caller(unsigned long size, int node,
gfp_tflags, void *caller){ return __vmalloc_node_flags(size, node, flags); } #else extern void *__vmalloc_node_flags_caller(unsigned long size, int node, gfp_t flags, void *caller);#endif
[..]Quoted 5 lines
kernel/bpf/syscall.c +1
-0+#endif } return __vmalloc_node_flags_caller(size, numa_node, GFP_KERNEL | __GFP_RETRY_MAYFAIL |
Quoted 16 lines · Andrii Nakryiko
mmap()support for BPF array depends onvmalloc_user_node_flags, which is available only onCONFIG_MMUconfigurations. Fail mmap-able allocations if noCONFIG_MMUis set.Cc Johannes Weiner <[email protected]>Reported-by kbuild test robot <[email protected]>Signed-off-by Andrii Nakryiko <[email protected]>--- kernel/bpf/syscall.c | 4 ++++ 1 file changed, 4 insertions(+)kernel/bpf/syscall.c +0
-0
kernel/bpf/syscall.c static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable) · line 164
Quoted 9 lines
kernel/bpf/syscall.c +4
-0@@ -156,8 +156,12 @@ static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable) }if (mmapable) {BUG_ON (!PAGE_ALIGNED (size)); +#ifndef CONFIG_MMU +return NULL ; +#else return vmalloc_user_node_flags (size, numa_node,GFP_KERNEL | __GFP_RETRY_MAYFAIL | flags); +#endif
Typically such ifdef goes into .h. There are several examples of such !CONFIG_MMU in vmalloc.h. May be move it there?