Skip to content

Commit ebc1415

Browse files
liu-song-6Alexei Starovoitov
authored andcommitted
bpf: Introduce bpf_arch_text_copy
This will be used to copy JITed text to RO protected module memory. On x86, bpf_arch_text_copy is implemented with text_poke_copy. bpf_arch_text_copy returns pointer to dst on success, and ERR_PTR(errno) on errors. Signed-off-by: Song Liu <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0e06b40 commit ebc1415

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

arch/x86/net/bpf_jit_comp.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,3 +2412,10 @@ bool bpf_jit_supports_kfunc_call(void)
24122412
{
24132413
return true;
24142414
}
2415+
2416+
void *bpf_arch_text_copy(void *dst, void *src, size_t len)
2417+
{
2418+
if (text_poke_copy(dst, src, len) == NULL)
2419+
return ERR_PTR(-EINVAL);
2420+
return dst;
2421+
}

include/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,8 @@ enum bpf_text_poke_type {
23622362
int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
23632363
void *addr1, void *addr2);
23642364

2365+
void *bpf_arch_text_copy(void *dst, void *src, size_t len);
2366+
23652367
struct btf_id_set;
23662368
bool btf_id_set_contains(const struct btf_id_set *set, u32 id);
23672369

kernel/bpf/core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,11 @@ int __weak bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
24402440
return -ENOTSUPP;
24412441
}
24422442

2443+
void * __weak bpf_arch_text_copy(void *dst, void *src, size_t len)
2444+
{
2445+
return ERR_PTR(-ENOTSUPP);
2446+
}
2447+
24432448
DEFINE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
24442449
EXPORT_SYMBOL(bpf_stats_enabled_key);
24452450

0 commit comments

Comments
 (0)