Repository navigation
Fix heap buffer overflow in CLibrary.ioctl(int, long, int[]) (CVE-2026-8484) - #323
Closed
levpachmanov wants to merge 1 commit into
Closed
levpachmanov wants to merge 1 commit into
levpachmanov wants to merge 1 commit into
Conversation
…6-8484) The int[] overload passed the Java array's elements straight to ioctl(). The kernel writes as many bytes as the request defines (e.g. TCGETS writes a 36-byte struct termios on Linux x86-64), regardless of the array length, so a short array overflowed the native heap and could crash the JVM. The call now goes through a zeroed scratch buffer that is at least as large as the array, the argument size encoded in the request (_IOC_SIZE / IOCPARM_LEN), and 4096 bytes for legacy requests that encode no size. Only the array's length is copied back, so correctly sized callers see the same results as before and every request is still accepted. Adds CLibraryIoctlTest covering short arrays, oversized arrays and other requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes the heap buffer overflow reported as CVE-2026-8484 (see #319).
The problem
The
int[]overload ofCLibrary.ioctl(ioctl__IJ_3Iinsrc/main/native/jansi.c) passes the Java array's elements straight toioctl(). The kernel writes as many bytes as the request defines, not as many as the array holds. For example, on LinuxTCGETSwrites a 36-bytestruct termioson x86-64, soioctl(fd, TCGETS, new int[1])writes 32 bytes past the end of the buffer on every call, corrupting the native heap and eventually crashing the JVM.The fix
Rejecting requests the wrapper cannot size would break callers, so the wrapper keeps accepting every request but no longer hands the array's buffer to the kernel:
ioctl()now writes into a zeroed scratch buffer that is at least as large as the array, the argument size encoded in the request (_IOC_SIZEon Linux,IOCPARM_LENon macOS and FreeBSD), and 4096 bytes. The floor covers legacy terminal requests such asTCGETSthat encode no size.GetIntArrayRegion/SetIntArrayRegion), so callers that pass a correctly sized array see exactly the same results as before.WinSizeoverload, which Jansi itself uses, is unchanged.Tests
Adds
CLibraryIoctlTest, which opens a pty and checks:TIOCGWINSZinto a 1-element array (struct is 8 bytes), in a loopTIOCGWINSZinto an oversized array: the extra elements are left untouchedTCGETSinto a 1-element array, in a loop (Linux only). Against the current native library this crashes the test JVM.FIONREAD) still worksThe test passes locally on macOS. The same change, built with the project's native targets, has been run with the full test suite plus these tests on Linux, macOS and Windows across Java 8, 11 and 17.
Note on binaries
This PR changes the C source only. The prebuilt native libraries under
src/main/resourcesneed to be rebuilt (all non-Windows targets; the Windows DLLs don't contain this wrapper) for the fix to take effect in a release.🤖 Generated with Claude Code