bpf: Add __bpfcall attribute to bpf_task_work_callback()
PATCH 1/1 bpf: Add __bpfcall attribute to bpf_task_work_callback()
BPF kCFI support is optional for architectures which support kCFI. If an architecture provides bpf kCFI support it must override the default __bpfcall define (which translates to __nocfi).
Add the missing __bpfcall attribute to bpf_task_work_callback() which calls bpf programs indirectly to avoid CFI checks for such cases.
--- kernel/bpf/helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/helpers.c +1 -1
@@ -4447,7 +4447,7 @@ static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx)bpf_task_work_ctx_put (ctx); } -static void bpf_task_work_callback (struct callback_head *cb) +static __bpfcall void bpf_task_work_callback(struct callback_head *cb) { struct bpf_task_work_ctx *ctx = container_of(cb, struct bpf_task_work_ctx, work);enum bpf_task_work_state state;
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Incomplete Fix / Missing kCFI Annotations for BPF indirect calls --
--- Patch [1]: [PATCH bpf-next] bpf: Add __bpfcall attribute to bpf_task_work_callback() --- commit 96f705949126224922cfe1979dd000057319d199
Author: Heiko Carstens <[email protected]>
bpf: Add __bpfcall attribute to bpf_task_work_callback()
This commit adds the __bpfcall attribute to bpf_task_work_callback() to avoid CFI checks for indirect calls to BPF programs. This addresses kCFI issues on architectures that do not provide default BPF kCFI support.
kernel/bpf/helpers.c static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx) · line 4451
Quoted 11 lines
kernel/bpf/helpers.c +1
-1@@ -4447,7 +4447,7 @@ static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx)bpf_task_work_ctx_put (ctx); } -static void bpf_task_work_callback (struct callback_head *cb) +static __bpfcall void bpf_task_work_callback(struct callback_head *cb) {
[Severity: Critical]
This isn't a bug introduced by this patch, but are there other BPF indirect calls that also need the __bpfcall attribute to prevent kCFI panics?
For example, bpf_timer_cb() and bpf_wq_work() in kernel/bpf/helpers.c also perform indirect calls to callback_fn().
Other locations like bpf_for_each_array_elem() in kernel/bpf/arraymap.c and bpf_find_vma() in kernel/bpf/task_iter.c appear to have the same pattern.
Could unprivileged users loading BPF programs that use timers, workqueues, or map iterators trigger the same kCFI violation on architectures lacking BPF kCFI support?
Quoted 2 lines
kernel/bpf/helpers.c +0
-0struct bpf_task_work_ctx *ctx = container_of(cb, struct bpf_task_work_ctx, work);enum bpf_task_work_state state;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 18 lines · Heiko Carstens
BPF kCFI support is optional for architectures which support kCFI. If an architecture provides bpf kCFI support it must override the default
__bpfcalldefine (which translates to__nocfi).Add the missing
__bpfcallattribute tobpf_task_work_callback()which calls bpf programs indirectly to avoid CFI checks for such cases.Fixes 38aa7003e369 ("bpf: task work scheduling kfuncs")Signed-off-by Heiko Carstens <[email protected]>--- kernel/bpf/helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/helpers.c +0
-0
kernel/bpf/helpers.c static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx) · line 4450
Quoted 5 lines
kernel/bpf/helpers.c +1
-1@@ -4447,7 +4447,7 @@ static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx)bpf_task_work_ctx_put (ctx); } -static void bpf_task_work_callback (struct callback_head *cb) +static __bpfcall void bpf_task_work_callback(struct callback_head *cb)
Thanks for the patch, I've already sent another fix:
https://lore.kernel.org/all/[email protected]/
Is __bpfcall still needed?
Quoted 3 lines
kernel/bpf/helpers.c +0
-0{ struct bpf_task_work_ctx *ctx = container_of(cb, struct bpf_task_work_ctx, work);enum bpf_task_work_state state;
Quoted 22 lines · Mykyta Yatsenko
Quoted 21 lines · Heiko Carstens
BPF kCFI support is optional for architectures which support kCFI. If an architecture provides bpf kCFI support it must override the default
__bpfcalldefine (which translates to__nocfi).Add the missing
__bpfcallattribute tobpf_task_work_callback()which calls bpf programs indirectly to avoid CFI checks for such cases.Fixes 38aa7003e369 ("bpf: task work scheduling kfuncs")Signed-off-by Heiko Carstens <[email protected]>--- kernel/bpf/helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/helpers.c +0
-0@@ -4447,7 +4447,7 @@ static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx)bpf_task_work_ctx_put (ctx); }
Quoted 6 lines
kernel/bpf/helpers.c static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx) · line 4450
Quoted 2 lines
kernel/bpf/helpers.c +1
-1-static void bpf_task_work_callback (struct callback_head *cb) +static __bpfcall void bpf_task_work_callback(struct callback_head *cb)Thanks for the patch, I've already sent another fix:
https://lore.kernel.org/all/[email protected]/
Is__bpfcallstill needed?
Yes, it is needed for architectures which select ARCH_SUPPORTS_CFI, and which in addition support bpf, but do not provide CFI support for bpf programs.
As of now it looks like this is only the case for arm, at least as far as I understand the code. It might be easier to implement bpf/cfi support for arm, then drop the __bpfcall macro entirely, and require from future architectures to provde bpf/cfi support whenever they select ARCH_SUPPORTS_CFI.
I'm writing the above, since due to AI feedback to this patch, there seem to be more bpf functions which call bpf programs indirectly and which miss the __bpfcall attribute.
Kumar Kartikeya Dwivedi
maintainerQuoted 33 lines · Heiko Carstens
Quoted 22 lines · Mykyta Yatsenko
Quoted 21 lines · Heiko Carstens
BPF kCFI support is optional for architectures which support kCFI. If an architecture provides bpf kCFI support it must override the default
__bpfcalldefine (which translates to__nocfi).Add the missing
__bpfcallattribute tobpf_task_work_callback()which calls bpf programs indirectly to avoid CFI checks for such cases.Fixes 38aa7003e369 ("bpf: task work scheduling kfuncs")Signed-off-by Heiko Carstens <[email protected]>--- kernel/bpf/helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/helpers.c +0
-0@@ -4447,7 +4447,7 @@ static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx)bpf_task_work_ctx_put (ctx); }Quoted 6 lines
kernel/bpf/helpers.c static void bpf_task_work_cancel(struct bpf_task_work_ctx *ctx) · line 4450
Quoted 2 lines
kernel/bpf/helpers.c +1
-1-static void bpf_task_work_callback (struct callback_head *cb) +static __bpfcall void bpf_task_work_callback(struct callback_head *cb)Thanks for the patch, I've already sent another fix:
https://lore.kernel.org/all/[email protected]/
Is__bpfcallstill needed?Yes, it is needed for architectures which select
ARCH_SUPPORTS_CFI, and which in addition support bpf, but do not provide CFI support for bpf programs.
Quoted 8 lines
As of now it looks like this is only the case for arm, at least as far as I understand the code. It might be easier to implement bpf/cfi support for arm, then drop the
__bpfcallmacro entirely, and require from future architectures to provde bpf/cfi support whenever they selectARCH_SUPPORTS_CFI.I'm writing the above, since due to AI feedback to this patch, there seem to be more bpf functions which call bpf programs indirectly and which miss the
__bpfcallattribute.
I think letting arm JIT folks figure out CFI support is a better path.
pw-bot: cr