bpf: Annotate struct bpf_stack_map with __counted_by
Subsystems (2)
PATCH 1/1 bpf: Annotate struct bpf_stack_map with __counted_by
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
As found with Coccinelle[1], add __counted_by for struct bpf_stack_map.
--- kernel/bpf/stackmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/stackmap.c +1 -1
@@ -28,7 +28,7 @@ struct bpf_stack_map {void *elems;struct pcpu_freelist freelist;u32 n_buckets; -struct stack_map_bucket *buckets[]; + struct stack_map_bucket *buckets[] __counted_by(n_buckets); };static inline bool stack_map_use_build_id (struct bpf_map *map)
Signature · 1 line
2.34.1
Quoted 8 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structbpf_stack_map.
Quoted 16 lines
Cc Song Liu <[email protected]>Cc Jiri Olsa <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Andrii Nakryiko <[email protected]>Cc Martin KaFai Lau <[email protected]>Cc Yonghong Song <[email protected]>Cc John Fastabend <[email protected]>Cc KP Singh <[email protected]>Cc Stanislav Fomichev <[email protected]>Cc Hao Luo <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>
TIL about __counted_by :-)
Quoted 20 lines
--- kernel/bpf/stackmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/stackmap.c +1
-1@@ -28,7 +28,7 @@ struct bpf_stack_map {void *elems;struct pcpu_freelist freelist;u32 n_buckets; -struct stack_map_bucket *buckets[]; + struct stack_map_bucket *buckets[] __counted_by(n_buckets); };static inline bool stack_map_use_build_id (struct bpf_map *map)Signature · 1 line
2.34.1
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 9 lines · On Fri, 6 Oct 2023 13:17:00 -0700 you wrote:
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structbpf_stack_map.[...]
Here is the summary with links:
- bpf: Annotate struct bpf_stack_map with __counted_by
https://git.kernel.org/bpf/bpf-next/c/84cb9cbd911a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 8 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structbpf_stack_map.
Quoted 16 lines
Cc Song Liu <[email protected]>Cc Jiri Olsa <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Andrii Nakryiko <[email protected]>Cc Martin KaFai Lau <[email protected]>Cc Yonghong Song <[email protected]>Cc John Fastabend <[email protected]>Cc KP Singh <[email protected]>Cc Stanislav Fomichev <[email protected]>Cc Hao Luo <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>
Thanks!
Signature · 1 line
Gustavo
Quoted 17 lines
--- kernel/bpf/stackmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/stackmap.c +1
-1@@ -28,7 +28,7 @@ struct bpf_stack_map {void *elems;struct pcpu_freelist freelist;u32 n_buckets; -struct stack_map_bucket *buckets[]; + struct stack_map_bucket *buckets[] __counted_by(n_buckets); };static inline bool stack_map_use_build_id (struct bpf_map *map)