History

bpf, x86: Set header->size properly before freeing it

On 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.

Song Liu committed 4 years ago

Commit 676b2da1 parent eed1fce2 files · +10 −4Browse files

Showing the changes to kernel (1 of 2 files). Show all

Unified · Split

kernel/bpf/core.c+6−3
@@ -1112,13 +1112,16 @@ int bpf_jit_binary_pack_finalize(struct bpf_prog *prog, · 1111 unmodified lines
1112 * 1) when the program is freed after;1112 * 1) when the program is freed after;
1113 * 2) when the JIT engine fails (before bpf_jit_binary_pack_finalize).1113 * 2) when the JIT engine fails (before bpf_jit_binary_pack_finalize).
1114 * For case 2), we need to free both the RO memory and the RW buffer.1114 * 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->size1115 *
1116 * is used for uncharge.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).
1117 */1120 */
1118void bpf_jit_binary_pack_free(struct bpf_binary_header *ro_header,1121void bpf_jit_binary_pack_free(struct bpf_binary_header *ro_header,
1119 struct bpf_binary_header *rw_header)1122 struct bpf_binary_header *rw_header)
1120{1123{
1121 u32 size = rw_header ? rw_header->size : ro_header->size;1124 u32 size = ro_header->size;
1122 1125
1123 bpf_prog_pack_free(ro_header);1126 bpf_prog_pack_free(ro_header);
1124 kvfree(rw_header);1127 kvfree(rw_header);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t