Skip to content

Commit 8bbe98b

Browse files
author
Alexei Starovoitov
committed
Merge branch 'fixes for bpf_prog_pack'
Song Liu says: ==================== Changes v1 => v2: 1. Rephrase comments in 2/2. (Yonghong) Two fixes for bpf_prog_pack. ==================== Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 530e214 + 676b2da commit 8bbe98b

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ config X86
158158
select HAVE_ALIGNED_STRUCT_PAGE if SLUB
159159
select HAVE_ARCH_AUDITSYSCALL
160160
select HAVE_ARCH_HUGE_VMAP if X86_64 || X86_PAE
161-
select HAVE_ARCH_HUGE_VMALLOC if HAVE_ARCH_HUGE_VMAP
161+
select HAVE_ARCH_HUGE_VMALLOC if X86_64
162162
select HAVE_ARCH_JUMP_LABEL
163163
select HAVE_ARCH_JUMP_LABEL_RELATIVE
164164
select HAVE_ARCH_KASAN if X86_64

arch/x86/net/bpf_jit_comp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,8 +2330,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
23302330
if (proglen <= 0) {
23312331
out_image:
23322332
image = NULL;
2333-
if (header)
2333+
if (header) {
2334+
bpf_arch_text_copy(&header->size, &rw_header->size,
2335+
sizeof(rw_header->size));
23342336
bpf_jit_binary_pack_free(header, rw_header);
2337+
}
23352338
prog = orig_prog;
23362339
goto out_addrs;
23372340
}

kernel/bpf/core.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,13 +1112,16 @@ int bpf_jit_binary_pack_finalize(struct bpf_prog *prog,
11121112
* 1) when the program is freed after;
11131113
* 2) when the JIT engine fails (before bpf_jit_binary_pack_finalize).
11141114
* For case 2), we need to free both the RO memory and the RW buffer.
1115-
* Also, ro_header->size in 2) is not properly set yet, so rw_header->size
1116-
* is used for uncharge.
1115+
*
1116+
* bpf_jit_binary_pack_free requires proper ro_header->size. However,
1117+
* bpf_jit_binary_pack_alloc does not set it. Therefore, ro_header->size
1118+
* must be set with either bpf_jit_binary_pack_finalize (normal path) or
1119+
* bpf_arch_text_copy (when jit fails).
11171120
*/
11181121
void bpf_jit_binary_pack_free(struct bpf_binary_header *ro_header,
11191122
struct bpf_binary_header *rw_header)
11201123
{
1121-
u32 size = rw_header ? rw_header->size : ro_header->size;
1124+
u32 size = ro_header->size;
11221125

11231126
bpf_prog_pack_free(ro_header);
11241127
kvfree(rw_header);

0 commit comments

Comments
 (0)