* [PATCH] bpf: Check for integer overflow when using roundup_pow_of_two()
@ 2021-01-27 6:36 Bui Quang Minh
2021-02-03 20:50 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Bui Quang Minh @ 2021-01-27 6:36 UTC (permalink / raw)
To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend,
kpsingh, davem
Cc: netdev, bpf, linux-kernel, minhquangbui99
On 32-bit architecture, roundup_pow_of_two() can return 0 when the argument
has upper most bit set due to resulting 1UL << 32. Add a check for this
case.
Fixes: d5a3b1f ("bpf: introduce BPF_MAP_TYPE_STACK_TRACE")
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
---
kernel/bpf/stackmap.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
index aea96b638473..bfafbf115bf3 100644
--- a/kernel/bpf/stackmap.c
+++ b/kernel/bpf/stackmap.c
@@ -115,6 +115,8 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
/* hash table size must be power of 2 */
n_buckets = roundup_pow_of_two(attr->max_entries);
+ if (!n_buckets)
+ return ERR_PTR(-E2BIG);
cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap);
cost += n_buckets * (value_size + sizeof(struct stack_map_bucket));
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] bpf: Check for integer overflow when using roundup_pow_of_two()
2021-01-27 6:36 [PATCH] bpf: Check for integer overflow when using roundup_pow_of_two() Bui Quang Minh
@ 2021-02-03 20:50 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-02-03 20:50 UTC (permalink / raw)
To: Bui Quang Minh
Cc: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend,
kpsingh, davem, netdev, bpf, linux-kernel
Hello:
This patch was applied to bpf/bpf.git (refs/heads/master):
On Wed, 27 Jan 2021 06:36:53 +0000 you wrote:
> On 32-bit architecture, roundup_pow_of_two() can return 0 when the argument
> has upper most bit set due to resulting 1UL << 32. Add a check for this
> case.
>
> Fixes: d5a3b1f ("bpf: introduce BPF_MAP_TYPE_STACK_TRACE")
> Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
>
> [...]
Here is the summary with links:
- bpf: Check for integer overflow when using roundup_pow_of_two()
https://git.kernel.org/bpf/bpf/c/6183f4d3a0a2
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] 2+ messages in thread
end of thread, other threads:[~2021-02-03 20:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-27 6:36 [PATCH] bpf: Check for integer overflow when using roundup_pow_of_two() Bui Quang Minh
2021-02-03 20:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).