Skip to content

fix: use 1ULL instead of 1 in CPU bitmap shift to avoid UB#93

Merged
ForeverYolo merged 1 commit into
mainfrom
fix/cpu-bitmap-int-shift-ub
Jun 9, 2026
Merged

fix: use 1ULL instead of 1 in CPU bitmap shift to avoid UB#93
ForeverYolo merged 1 commit into
mainfrom
fix/cpu-bitmap-int-shift-ub

Conversation

@Inquisitor-201

@Inquisitor-201 Inquisitor-201 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix undefined behavior in CPU bitmap construction when cpu_id >= 31
  • 1 << cpu_id uses a signed int1 << 31 is UB (sign-bit overflow),
    and 1 << 32 is UB on 64-bit (shift >= width of type)
  • Change to 1ULL << cpu_id for a well-defined 64-bit shift
  • Current max platform is 16 CPUs, but this is a latent bug waiting to trigger
    on any platform with 31+ CPUs or with a misconfigured JSON config

…avior

The `1 << cpu_id` expression uses a signed int, which triggers undefined
behavior when cpu_id >= 31 (shift into sign bit) or cpu_id >= 32 (shift
>= width of type). Use `1ULL` for a well-defined 64-bit shift.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@agicy

agicy commented May 26, 2026

Copy link
Copy Markdown
Contributor

Why not use a bitmap? Using 1ull still gets wrong when cpu_id >= 64.

@Inquisitor-201

Copy link
Copy Markdown
Contributor Author

@agicy Good point, but the cpus field is __u64 on both sides, so the interface already caps at 64 CPUs. Switching to a bitmap would require changing struct layouts and the hypercall ABI across both repos — too risky for no real benefit since current platforms max out at 16 CPUs. Happy to revisit if >64 CPU support is needed later.

@agicy agicy self-requested a review May 27, 2026 03:31
@ForeverYolo ForeverYolo merged commit 217ede0 into main Jun 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants