fixes for bpf_prog_pack
Subsystems (6)
Song Liu
reviewercover fixes for bpf_prog_pack
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 | 6 +++++- kernel/bpf/core.c | 7 ++++--- 3 files changed, 10 insertions(+), 5 deletions(-)
--
2.30.2
Song Liu
reviewerPATCH 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
Re: [PATCH bpf-next 1/2] x86: disable HAVE_ARCH_HUGE_VMALLOC on 32-bit x86
Quoted 7 lines · Song Liu
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)
Quoted 6 lines
which is triggered with
HAVE_ARCH_HUGE_VMALLOCon 32-bit x86. Since BPF only usesHAVE_ARCH_HUGE_VMALLOCforx86_64, turn it off for 32-bit x86.Reported-by kernel test robot <[email protected]>Fixes fac54e2bfb5b ("x86/Kconfig: Select HAVE_ARCH_HUGE_VMALLOC with HAVE_ARCH_HUGE_VMAP")Signed-off-by Song Liu <[email protected]>
Song Liu
reviewerPATCH 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 | 6 +++++- kernel/bpf/core.c | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-)
arch/x86/net/bpf_jit_comp.c +5 -1
@@ -2330,8 +2330,12 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)if (proglen <=0 ) { out_image: image =NULL ; -if (header) +if (header) { +/* set header->size for bpf_arch_text_copy */ +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 +4 -3
@@ -1112,13 +1112,14 @@ 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. +* +* If bpf_jit_binary_pack_free is called before _finalize (jit error), +* it is necessary to set ro_header->size properly before freeing it. */ 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
Re: [PATCH bpf-next 2/2] bpf, x86: set header->size properly before freeing it
Quoted 9 lines · Song Liu
On
do_jitfailure path, the header is freed bybpf_jit_binary_pack_free. Whilebpf_jit_binary_pack_freedoesn't require properro_header->size,bpf_prog_pack_freestill uses it. Setheader->sizeinbpf_int_jit_compilebefore callingbpf_jit_binary_pack_free.Fixes 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc")Fixes 33c9805860e5 ("bpf: Introduce bpf_jit_binary_pack_[alloc|finalize|free]")Reported-by Kui-Feng Lee <[email protected]>Signed-off-by Song Liu <[email protected]>
LGTM with a nit below related to comments.
Quoted 10 lines
--- arch/x86/net/bpf_jit_comp.c | 6 +++++- kernel/bpf/core.c | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-)arch/x86/net/bpf_jit_comp.c +0
-0
arch/x86/net/bpf_jit_comp.c struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) · line 2334
Quoted 6 lines
arch/x86/net/bpf_jit_comp.c +2
-1@@ -2330,8 +2330,12 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)if (proglen <=0 ) { out_image: image =NULL ; -if (header) +if (header) { +/* set header->size for bpf_arch_text_copy */
This comment is confusing. Setting header->size is not for bpf_arch_text_copy. Probably you mean 'by bpf_arch_text_copy? I think this comment is not necessary.
Quoted 12 lines
arch/x86/net/bpf_jit_comp.c +3
-0+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 +0
-0
kernel/bpf/core.c int bpf_jit_binary_pack_finalize(struct bpf_prog *prog, · line 1116
Quoted 7 lines
kernel/bpf/core.c +2
-2@@ -1112,13 +1112,14 @@ 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. +* +* If bpf_jit_binary_pack_free is called before _finalize (jit error),
Do you mean bpf_jit_binary_pack_free() is called before calling bpf_jit_binary_pack_finalize()? This seems not the case.
Quoted 10 lines
kernel/bpf/core.c +2
-1+* it is necessary to set ro_header->size properly before freeing it. */ 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);
Re: [PATCH bpf-next 2/2] bpf, x86: set header->size properly before freeing it
Quoted 30 lines · Yonghong Song
Quoted 8 lines · Song Liu
On
do_jitfailure path, the header is freed bybpf_jit_binary_pack_free. Whilebpf_jit_binary_pack_freedoesn't require properro_header->size,bpf_prog_pack_freestill uses it. Setheader->sizeinbpf_int_jit_compilebefore callingbpf_jit_binary_pack_free.Fixes 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc")Fixes 33c9805860e5 ("bpf: Introduce bpf_jit_binary_pack_[alloc|finalize|free]")Reported-by Kui-Feng Lee <[email protected]>Signed-off-by Song Liu <[email protected]>LGTM with a nit below related to comments.
Acked-by Yonghong Song <[email protected]>Quoted 10 lines
--- arch/x86/net/bpf_jit_comp.c | 6 +++++- kernel/bpf/core.c | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-)arch/x86/net/bpf_jit_comp.c +0
-0@@ -2330,8 +2330,12 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)if (proglen <=0 ) {
Quoted 8 lines
arch/x86/net/bpf_jit_comp.c struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) · line 2334
Quoted 5 lines
arch/x86/net/bpf_jit_comp.c +2
-1out_image: image =NULL ; -if (header) +if (header) { +/* set header->size for bpf_arch_text_copy */ This comment is confusing. Setting
header->sizeis not forbpf_arch_text_copy. Probably you mean 'bybpf_arch_text_copy? I think this comment is not necessary.
I meant to say set header->size for bpf_jit_binary_pack_free(). I guess it is not really necessary. Let me remove it.
Quoted 15 lines
Quoted 15 lines
arch/x86/net/bpf_jit_comp.c +3
-0+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 +0
-0@@ -1112,13 +1112,14 @@ 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).
Quoted 8 lines
kernel/bpf/core.c int bpf_jit_binary_pack_finalize(struct bpf_prog *prog, · line 1116
Quoted 5 lines
kernel/bpf/core.c +2
-2* 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. +* +* If bpf_jit_binary_pack_free is called before _finalize (jit error), Do you mean
bpf_jit_binary_pack_free()is called before callingbpf_jit_binary_pack_finalize()? This seems not the case.
Now I see this is a little confusing. Let me rephrase it in v2.
Thanks,
Song
Quoted 10 lines
Quoted 10 lines
kernel/bpf/core.c +2
-1+* it is necessary to set ro_header->size properly before freeing it. */ 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);