History

bpf: Introduce bpf_arch_text_invalidate for bpf_prog_pack

Introduce bpf_arch_text_invalidate and use it to fill unused part of the bpf_prog_pack with illegal instructions when a BPF program is freed.

Song Liu committed 4 years ago

Commit fe736561 parent aadd1b63 files · +14 −0Browse files

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

Unified · Split

kernel/bpf/core.c+8−0
@@ -968,6 +968,9 @@ static void bpf_prog_pack_free(struct bpf_binary_header *hdr) · 967 unmodified lines
968 nbits = BPF_PROG_SIZE_TO_NBITS(hdr->size);968 nbits = BPF_PROG_SIZE_TO_NBITS(hdr->size);
969 pos = ((unsigned long)hdr - (unsigned long)pack_ptr) >> BPF_PROG_CHUNK_SHIFT;969 pos = ((unsigned long)hdr - (unsigned long)pack_ptr) >> BPF_PROG_CHUNK_SHIFT;
970 970
971 WARN_ONCE(bpf_arch_text_invalidate(hdr, hdr->size),
972 "bpf_prog_pack bug: missing bpf_arch_text_invalidate?\n");
973
971 bitmap_clear(pack->bitmap, pos, nbits);974 bitmap_clear(pack->bitmap, pos, nbits);
972 if (bitmap_find_next_zero_area(pack->bitmap, bpf_prog_chunk_count(), 0,975 if (bitmap_find_next_zero_area(pack->bitmap, bpf_prog_chunk_count(), 0,
973 bpf_prog_chunk_count(), 0) == 0) {976 bpf_prog_chunk_count(), 0) == 0) {
@@ -2740,6 +2743,11 @@ void * __weak bpf_arch_text_copy(void *dst, void *src, size_t len) · 1766 unmodified lines
2740 return ERR_PTR(-ENOTSUPP);2743 return ERR_PTR(-ENOTSUPP);
2741}2744}
2742 2745
2746int __weak bpf_arch_text_invalidate(void *dst, size_t len)
2747{
2748 return -ENOTSUPP;
2749}
2750
2743DEFINE_STATIC_KEY_FALSE(bpf_stats_enabled_key);2751DEFINE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
2744EXPORT_SYMBOL(bpf_stats_enabled_key);2752EXPORT_SYMBOL(bpf_stats_enabled_key);
2745 2753

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