fix: bound nest counter in bsdkm vecreg save#10874
Draft
MarkAtwood wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds an overflow guard to the per-CPU nest counter in wolfkmod_vecreg_save() to prevent wraparound from causing premature fpu_kern_leave() and potential FPU/SIMD state corruption.
Changes:
- Check
nestagainstUINT_MAXbefore incrementing (both increment sites). - On saturation, emit an error and return
EINVALto stop further nesting.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| td_tid, curthread->td_tid); | ||
| return (EINVAL); | ||
| } | ||
| if (fpu_states[PCPU_GET(cpuid)].nest == UINT_MAX) { |
Comment on lines
+169
to
+170
| printf("error: wolfkmod_vecreg_save: nest overflow\n"); | ||
| return (EINVAL); |
Comment on lines
+168
to
172
| if (fpu_states[PCPU_GET(cpuid)].nest == UINT_MAX) { | ||
| printf("error: wolfkmod_vecreg_save: nest overflow\n"); | ||
| return (EINVAL); | ||
| } | ||
| fpu_states[PCPU_GET(cpuid)].nest++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug: In
bsdkm/x86_vecreg.c,wolfkmod_vecreg_save()increments the per-CPUnestcounter (volatile u_int, line 33) with no upper bound. The re-entrant KERNFPU-active path (was line 168) incrementsneston every nestedSAVE_VECTOR_REGISTERS(). If it ever wrappedUINT_MAX -> 0,wolfkmod_vecreg_restore()would treatnest == 0as the last level and callfpu_kern_leave()prematurely, releasing kernel FPU context while outer logical nesting frames still hold it — corrupting FPU/SIMD state or leaking kernel register state to userspace.Fix: Add a bound check before each increment in
wolfkmod_vecreg_save(); on saturation, print an error and returnEINVAL(theRESTORE_VECTOR_REGISTERS()path already tolerates a failed save). No behavioral change on the normal path.UINT_MAXis available via<sys/param.h>-><sys/limits.h>, already included bywolfkmod.c:25.Severity is low (defense-in-depth): reaching the wrap requires 2^32 unmatched save calls, which would itself be a runaway calling-code bug. The second increment site is already guarded by the preceding
nest != 0check, so it cannot overflow in practice; the guard is added there too for symmetry.How verified: BSD/amd64 kernel module — not buildable on Linux. Source- and preprocessor-analyzed against master
4c68523; the edited guard construct was compiled clean withgcc -Wall -Wextra -Werror -fsyntax-only, and<sys/param.h>inclusion atwolfkmod.c:25was confirmed to supplyUINT_MAX.Reported by static analysis (Fenrir finding 655).
[fenrir-sweep:held]