fixes for bpf_prog_pack
Subsystems (6)
Song Liu
reviewerv2 cover fixes for bpf_prog_pack
Changes v1 => v2:
1. Rephrase comments in 2/2. (Yonghong)
Two fixes for bpf_prog_pack.
Song Liu (2):
x86: disable HAVE_ARCH_HUGE_VMALLOC on 32-bit x86 bpf, x86: set header->size properly before freeing it
arch/x86/Kconfig | 2 +- arch/x86/net/bpf_jit_comp.c | 5 ++++- kernel/bpf/core.c | 9 ++++++--- 3 files changed, 11 insertions(+), 5 deletions(-)
--
2.30.2
Song Liu
reviewerPATCH v2 1/2 x86: disable HAVE_ARCH_HUGE_VMALLOC on 32-bit x86
kernel test robot reported kernel BUG like:
[ 44.587744][ T1] kernel BUG at arch/x86/mm/physaddr.c:76! [ 44.590151][ T1] __vmalloc_area_node (mm/vmalloc.c:622 mm/vmalloc.c:2995) [ 44.590151][ T1] __vmalloc_node_range (mm/vmalloc.c:3108) [ 44.590151][ T1] __vmalloc_node (mm/vmalloc.c:3157)
which is triggered with HAVE_ARCH_HUGE_VMALLOC on 32-bit x86. Since BPF only uses HAVE_ARCH_HUGE_VMALLOC for x86_64, turn it off for 32-bit x86.
--- arch/x86/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/Kconfig +1 -1
@@ -158,7 +158,7 @@ config X86 select HAVE_ALIGNED_STRUCT_PAGE if SLUB select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_HUGE_VMAP if X86_64 || X86_PAE - select HAVE_ARCH_HUGE_VMALLOC if HAVE_ARCH_HUGE_VMAP + select HAVE_ARCH_HUGE_VMALLOC if X86_64 select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN if X86_64
Signature · 1 line
2.30.2
Song Liu
reviewerPATCH v2 2/2 bpf, x86: set header->size properly before freeing it
In reply to Song LiuOn do_jit failure path, the header is freed by bpf_jit_binary_pack_free. While bpf_jit_binary_pack_free doesn't require proper ro_header->size, bpf_prog_pack_free still uses it. Set header->size in bpf_int_jit_compile before calling bpf_jit_binary_pack_free.
--- arch/x86/net/bpf_jit_comp.c | 5 ++++- kernel/bpf/core.c | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
arch/x86/net/bpf_jit_comp.c +4 -1
@@ -2330,8 +2330,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)if (proglen <=0 ) { out_image: image =NULL ; -if (header) +if (header) { +bpf_arch_text_copy (&header->size, &rw_header->size, +sizeof (rw_header->size));bpf_jit_binary_pack_free (header, rw_header); + } prog = orig_prog; goto out_addrs; }
kernel/bpf/core.c +6 -3
@@ -1112,13 +1112,16 @@ int bpf_jit_binary_pack_finalize(struct bpf_prog *prog,* 1) when the program is freed after; * 2) when the JIT engine fails (before bpf_jit_binary_pack_finalize). * For case 2), we need to free both the RO memory and the RW buffer. -* Also, ro_header->size in 2) is not properly set yet, so rw_header->size -* is used for uncharge. +* +* bpf_jit_binary_pack_free requires proper ro_header->size. However, +* bpf_jit_binary_pack_alloc does not set it. Therefore, ro_header->size +* must be set with either bpf_jit_binary_pack_finalize (normal path) or +* bpf_arch_text_copy (when jit fails). */ void bpf_jit_binary_pack_free (struct bpf_binary_header *ro_header,struct bpf_binary_header *rw_header) { -u32 size = rw_header ? rw_header->size : ro_header->size; +u32 size = ro_header->size;bpf_prog_pack_free (ro_header);kvfree (rw_header);
Signature · 1 line
2.30.2
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 10 lines · On Wed, 2 Mar 2022 09:51:24 -0800 you wrote:
Changes v1 => v2:
1. Rephrase comments in 2/2. (Yonghong)Two fixes for
bpf_prog_pack.Song Liu (2):
x86: disableHAVE_ARCH_HUGE_VMALLOCon 32-bit x86 bpf, x86: setheader->sizeproperly before freeing it[...]
Here is the summary with links:
- [v2,bpf-next,1/2] x86: disable HAVE_ARCH_HUGE_VMALLOC on 32-bit x86
https://git.kernel.org/bpf/bpf-next/c/eed1fcee556f - [v2,bpf-next,2/2] bpf, x86: set header->size properly before freeing it https://git.kernel.org/bpf/bpf-next/c/676b2daabaf9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html