Skip to content

Commit d243553

Browse files
liu-song-6Nobody
authored and
Nobody
committed
bpf: bpf_prog_pack: set proper size before freeing ro_header
bpf_prog_pack_free() uses header->size to decide whether the header should be freed with module_memfree() or the bpf_prog_pack logic. However, in kvmalloc() failure path of bpf_jit_binary_pack_alloc(), header->size is not set yet. As a result, bpf_prog_pack_free() may treat a slice of a pack as a standalone kvmalloc'd header and call module_memfree() on the whole pack. This in turn causes use-after-free by other users of the pack. Fix this by setting ro_header->size before freeing ro_header. Fixes: 33c9805 ("bpf: Introduce bpf_jit_binary_pack_[alloc|finalize|free]") Reported-by: [email protected] Reported-by: [email protected] Reported-by: [email protected] Signed-off-by: Song Liu <[email protected]>
1 parent a77be30 commit d243553

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

kernel/bpf/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ bpf_jit_binary_pack_alloc(unsigned int proglen, u8 **image_ptr,
10691069

10701070
*rw_header = kvmalloc(size, GFP_KERNEL);
10711071
if (!*rw_header) {
1072+
bpf_arch_text_copy(&ro_header->size, &size, sizeof(size));
10721073
bpf_prog_pack_free(ro_header);
10731074
bpf_jit_uncharge_modmem(size);
10741075
return NULL;

0 commit comments

Comments
 (0)