Skip to content

Commit e4c0033

Browse files
Peter ZijlstraAlexei Starovoitov
authored andcommitted
bpf: Fix dtor CFI
Ensure the various dtor functions match their prototype and retain their CFI signatures, since they don't have their address taken, they are prone to not getting CFI, making them impossible to call indirectly. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent e9d13b9 commit e4c0033

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

kernel/bpf/cpumask.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ __bpf_kfunc void bpf_cpumask_release(struct bpf_cpumask *cpumask)
9696
migrate_enable();
9797
}
9898

99+
__bpf_kfunc void bpf_cpumask_release_dtor(void *cpumask)
100+
{
101+
bpf_cpumask_release(cpumask);
102+
}
103+
CFI_NOSEAL(bpf_cpumask_release_dtor);
104+
99105
/**
100106
* bpf_cpumask_first() - Get the index of the first nonzero bit in the cpumask.
101107
* @cpumask: The cpumask being queried.
@@ -453,7 +459,7 @@ static const struct btf_kfunc_id_set cpumask_kfunc_set = {
453459

454460
BTF_ID_LIST(cpumask_dtor_ids)
455461
BTF_ID(struct, bpf_cpumask)
456-
BTF_ID(func, bpf_cpumask_release)
462+
BTF_ID(func, bpf_cpumask_release_dtor)
457463

458464
static int __init cpumask_kfunc_init(void)
459465
{

kernel/bpf/helpers.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,12 @@ __bpf_kfunc void bpf_task_release(struct task_struct *p)
21502150
put_task_struct_rcu_user(p);
21512151
}
21522152

2153+
__bpf_kfunc void bpf_task_release_dtor(void *p)
2154+
{
2155+
put_task_struct_rcu_user(p);
2156+
}
2157+
CFI_NOSEAL(bpf_task_release_dtor);
2158+
21532159
#ifdef CONFIG_CGROUPS
21542160
/**
21552161
* bpf_cgroup_acquire - Acquire a reference to a cgroup. A cgroup acquired by
@@ -2174,6 +2180,12 @@ __bpf_kfunc void bpf_cgroup_release(struct cgroup *cgrp)
21742180
cgroup_put(cgrp);
21752181
}
21762182

2183+
__bpf_kfunc void bpf_cgroup_release_dtor(void *cgrp)
2184+
{
2185+
cgroup_put(cgrp);
2186+
}
2187+
CFI_NOSEAL(bpf_cgroup_release_dtor);
2188+
21772189
/**
21782190
* bpf_cgroup_ancestor - Perform a lookup on an entry in a cgroup's ancestor
21792191
* array. A cgroup returned by this kfunc which is not subsequently stored in a
@@ -2570,10 +2582,10 @@ static const struct btf_kfunc_id_set generic_kfunc_set = {
25702582

25712583
BTF_ID_LIST(generic_dtor_ids)
25722584
BTF_ID(struct, task_struct)
2573-
BTF_ID(func, bpf_task_release)
2585+
BTF_ID(func, bpf_task_release_dtor)
25742586
#ifdef CONFIG_CGROUPS
25752587
BTF_ID(struct, cgroup)
2576-
BTF_ID(func, bpf_cgroup_release)
2588+
BTF_ID(func, bpf_cgroup_release_dtor)
25772589
#endif
25782590

25792591
BTF_SET8_START(common_btf_ids)

net/bpf/test_run.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,21 @@ __bpf_kfunc void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p)
600600
refcount_dec(&p->cnt);
601601
}
602602

603+
__bpf_kfunc void bpf_kfunc_call_test_release_dtor(void *p)
604+
{
605+
bpf_kfunc_call_test_release(p);
606+
}
607+
CFI_NOSEAL(bpf_kfunc_call_test_release_dtor);
608+
603609
__bpf_kfunc void bpf_kfunc_call_memb_release(struct prog_test_member *p)
604610
{
605611
}
606612

613+
__bpf_kfunc void bpf_kfunc_call_memb_release_dtor(void *p)
614+
{
615+
}
616+
CFI_NOSEAL(bpf_kfunc_call_memb_release_dtor);
617+
607618
__bpf_kfunc_end_defs();
608619

609620
BTF_SET8_START(bpf_test_modify_return_ids)
@@ -1671,9 +1682,9 @@ static const struct btf_kfunc_id_set bpf_prog_test_kfunc_set = {
16711682

16721683
BTF_ID_LIST(bpf_prog_test_dtor_kfunc_ids)
16731684
BTF_ID(struct, prog_test_ref_kfunc)
1674-
BTF_ID(func, bpf_kfunc_call_test_release)
1685+
BTF_ID(func, bpf_kfunc_call_test_release_dtor)
16751686
BTF_ID(struct, prog_test_member)
1676-
BTF_ID(func, bpf_kfunc_call_memb_release)
1687+
BTF_ID(func, bpf_kfunc_call_memb_release_dtor)
16771688

16781689
static int __init bpf_prog_test_run_init(void)
16791690
{

0 commit comments

Comments
 (0)