* Re: [PATCH] bpf: Annotate struct bpf_stack_map with __counted_by
2023-10-06 20:17 [PATCH] bpf: Annotate struct bpf_stack_map with __counted_by Kees Cook
@ 2023-10-06 20:50 ` Gustavo A. R. Silva
2023-10-06 21:17 ` Stanislav Fomichev
2023-10-06 21:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-06 20:50 UTC (permalink / raw)
To: Kees Cook, Song Liu
Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Yonghong Song, John Fastabend, KP Singh,
Stanislav Fomichev, Hao Luo, Gustavo A. R. Silva, bpf,
linux-hardening, Nathan Chancellor, Nick Desaulniers, Tom Rix,
linux-kernel, llvm
On 10/6/23 22:17, Kees Cook wrote:
> 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.
>
> Cc: Song Liu <song@kernel.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Andrii Nakryiko <andrii@kernel.org>
> Cc: Martin KaFai Lau <martin.lau@linux.dev>
> Cc: Yonghong Song <yonghong.song@linux.dev>
> Cc: John Fastabend <john.fastabend@gmail.com>
> Cc: KP Singh <kpsingh@kernel.org>
> Cc: Stanislav Fomichev <sdf@google.com>
> Cc: Hao Luo <haoluo@google.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: bpf@vger.kernel.org
> Cc: linux-hardening@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks!
--
Gustavo
> ---
> kernel/bpf/stackmap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
> index 458bb80b14d5..d6b277482085 100644
> --- a/kernel/bpf/stackmap.c
> +++ b/kernel/bpf/stackmap.c
> @@ -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)
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] bpf: Annotate struct bpf_stack_map with __counted_by
2023-10-06 20:17 [PATCH] bpf: Annotate struct bpf_stack_map with __counted_by Kees Cook
2023-10-06 20:50 ` Gustavo A. R. Silva
@ 2023-10-06 21:17 ` Stanislav Fomichev
2023-10-06 21:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Stanislav Fomichev @ 2023-10-06 21:17 UTC (permalink / raw)
To: Kees Cook
Cc: Song Liu, Jiri Olsa, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Yonghong Song, John Fastabend,
KP Singh, Hao Luo, Gustavo A. R. Silva, bpf, linux-hardening,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm
On 10/06, Kees Cook wrote:
> 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.
>
> Cc: Song Liu <song@kernel.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Andrii Nakryiko <andrii@kernel.org>
> Cc: Martin KaFai Lau <martin.lau@linux.dev>
> Cc: Yonghong Song <yonghong.song@linux.dev>
> Cc: John Fastabend <john.fastabend@gmail.com>
> Cc: KP Singh <kpsingh@kernel.org>
> Cc: Stanislav Fomichev <sdf@google.com>
> Cc: Hao Luo <haoluo@google.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: bpf@vger.kernel.org
> Cc: linux-hardening@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>
TIL about __counted_by :-)
Acked-by: Stanislav Fomichev <sdf@google.com>
> ---
> kernel/bpf/stackmap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
> index 458bb80b14d5..d6b277482085 100644
> --- a/kernel/bpf/stackmap.c
> +++ b/kernel/bpf/stackmap.c
> @@ -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)
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] bpf: Annotate struct bpf_stack_map with __counted_by
2023-10-06 20:17 [PATCH] bpf: Annotate struct bpf_stack_map with __counted_by Kees Cook
2023-10-06 20:50 ` Gustavo A. R. Silva
2023-10-06 21:17 ` Stanislav Fomichev
@ 2023-10-06 21:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-06 21:50 UTC (permalink / raw)
To: Kees Cook
Cc: song, jolsa, ast, daniel, andrii, martin.lau, yonghong.song,
john.fastabend, kpsingh, sdf, haoluo, gustavoars, bpf,
linux-hardening, nathan, ndesaulniers, trix, linux-kernel, llvm
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Fri, 6 Oct 2023 13:17:00 -0700 you wrote:
> 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.
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread