mbox series

[bpf,v3,0/3] Fix hash bucket overflow checks for 32-bit arches

Message ID 20240307120340.99577-1-toke@redhat.com (mailing list archive)
Headers show
Series Fix hash bucket overflow checks for 32-bit arches | expand

Message

Toke Høiland-Jørgensen March 7, 2024, 12:03 p.m. UTC
Syzbot managed to trigger a crash by creating a DEVMAP_HASH map with a
large number of buckets because the overflow check relies on
well-defined behaviour that is only correct on 64-bit arches.

Fix the overflow checks to happen before values are rounded up in all
the affected map types.

v3:
- Keep the htab->n_buckets > U32_MAX / sizeof(struct bucket) check
- Use 1UL << 31 instead of U32_MAX / 2 + 1 as the constant to check
  against
- Add patch to fix stackmap.c
v2:
- Fix off-by-one error in overflow check
- Apply the same fix to hashtab, where the devmap_hash code was copied
  from (John)

Toke Høiland-Jørgensen (3):
  bpf: Fix DEVMAP_HASH overflow check on 32-bit arches
  bpf: Fix hashtab overflow check on 32-bit arches
  bpf: Fix stackmap overflow check on 32-bit arches

 kernel/bpf/devmap.c   | 11 ++++++-----
 kernel/bpf/hashtab.c  | 14 +++++++++-----
 kernel/bpf/stackmap.c |  9 ++++++---
 3 files changed, 21 insertions(+), 13 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org March 8, 2024, 4:10 a.m. UTC | #1
Hello:

This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Thu,  7 Mar 2024 13:03:34 +0100 you wrote:
> Syzbot managed to trigger a crash by creating a DEVMAP_HASH map with a
> large number of buckets because the overflow check relies on
> well-defined behaviour that is only correct on 64-bit arches.
> 
> Fix the overflow checks to happen before values are rounded up in all
> the affected map types.
> 
> [...]

Here is the summary with links:
  - [bpf,v3,1/3] bpf: Fix DEVMAP_HASH overflow check on 32-bit arches
    https://git.kernel.org/bpf/bpf-next/c/281d464a34f5
  - [bpf,v3,2/3] bpf: Fix hashtab overflow check on 32-bit arches
    (no matching commit)
  - [bpf,v3,3/3] bpf: Fix stackmap overflow check on 32-bit arches
    https://git.kernel.org/bpf/bpf-next/c/7a4b21250bf7

You are awesome, thank you!