Skip to content

πŸ”’ Fix out-of-bounds read in realloc#21

Closed
undivisible wants to merge 1 commit into
mainfrom
security/fix-realloc-out-of-bounds-read-8489064097905049913
Closed

πŸ”’ Fix out-of-bounds read in realloc#21
undivisible wants to merge 1 commit into
mainfrom
security/fix-realloc-out-of-bounds-read-8489064097905049913

Conversation

@undivisible

Copy link
Copy Markdown
Contributor

🎯 What: An out-of-bounds read vulnerability in realloc was identified where it forcefully read n bytes from the old pointer regardless of its original allocation size.
⚠️ Risk: This could lead to sensitive data exposure by copying uninitialized or adjacent memory into the new buffer and potentially out-of-bounds memory accesses.
πŸ›‘οΈ Solution: malloc was updated to allocate an extra 8 bytes and store the size of the allocation in a header. realloc now reads this header to properly bound the memcpy to the minimum of the old and new allocation sizes. realloc was also improved to handle p == 0 and n == 0 effectively. Included new automated tests in libc_selftest.


PR created automatically by Jules for task 8489064097905049913 started by @undivisible

Modified `malloc` to prepend an 8-byte header storing the requested
allocation size. `realloc` now utilizes this header to determine
the original size and ensure it only copies up to `min(old_size, new_size)`
bytes. This prevents out-of-bounds reads into uninitialized or adjacent memory.
Added missing assertions in `libc_selftest` to test the new functionality.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

undivisible added a commit that referenced this pull request Jun 29, 2026
- Fix stray brace in kernel-root.in and remove dead thr_exit return
- Add heap/obj_arena bounds checks (PRs #30, #26)
- Harden malloc/calloc/realloc; replace strcpy with strlcpy; remove strcat
  (PRs #20, #18, #21, #28, #15)
- Split nvme_pci_init, restore e1000_rx_poll, use FS_MAX_FILES constants
  (PRs #14, #17, #16)
- Refresh context.md ponytail index after service-wrapper deletion
@undivisible

Copy link
Copy Markdown
Contributor Author

Changes applied directly on main (rebased past shell.in extraction and service-wrapper deletion). Used panic() instead of unreachable()/assert() where the PRs referenced undefined helpers.

@undivisible

Copy link
Copy Markdown
Contributor Author

Merged to main in 22933b8. Changes applied directly on main (rebased past shell.in extraction and service-wrapper deletion). Used panic() instead of unreachable()/assert() where the PRs referenced undefined helpers.

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.

1 participant