Skip to content

Fix hash bucket overflow checks for 32-bit arches

Toke Høiland-Jørgensen bpf netdev 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 4 repliesIn review 2 of 3 applied
  2. v22 patches 10 repliesSuperseded
  3. v11 patch 5 repliesSuperseded

Changes in v3 from the cover letter

- 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

Patches in v3 2 of 3 applied

#Subject and filesSizeRepliesApplied
1/3bpf: Fix DEVMAP_HASH overflow check on 32-bit archeskernel/bpf/devmap.c+6 -50 repliesApplied
2/3bpf: Fix hashtab overflow check on 32-bit archeskernel/bpf/hashtab.c+9 -52 replies
3/3bpf: Fix stackmap overflow check on 32-bit archeskernel/bpf/stackmap.c+6 -32 repliesApplied

Reviews trailers per patch

1 of 3 patches has a Reviewed-by or Acked-by.

Patch[email protected]Bui Quang Minh
1/3Reported-and-tested-by
2/3
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

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

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(-)
Signature · 1 line
2.43.2