Repository navigation
Conversation
DosForceDup() (INT 21h/AH=46h) validated OldHandle via get_sft(), but never checked NewHandle against p->ps_maxfiles and did not short-circuit when OldHandle == NewHandle. 1. For any caller-supplied NewHandle >= p->ps_maxfiles, indexing p->ps_filetab[NewHandle] read out of bounds in the PSP segment and, whenever that byte was 0xFF, wrote the SFT index out of bounds and leaked an SFT reference count while returning SUCCESS instead of DE_INVLDHNDL. 2. When OldHandle == NewHandle on an open handle, DosClose(NewHandle) closed the handle and decremented sft_count, after which the function copied 0xFF back onto itself and incremented sft_count on the closed SFT while returning SUCCESS. Check NewHandle >= p->ps_maxfiles (returning DE_INVLDHNDL) and return SUCCESS immediately when OldHandle == NewHandle (after OldHandle has been validated by get_sft()). Fixes FDOS#261
This branch has not been deployed
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.
Summary
DosForceDup()(INT 21h / AH=46h) inkernel/dosfns.cvalidatedOldHandleviaget_sft(), but never validatedNewHandleagainstp->ps_maxfilesand did not short-circuit whenOldHandle == NewHandle:NewHandle >= p->ps_maxfiles,p->ps_filetab[NewHandle]reads out of bounds in the PSP segment. Whenever that out-of-bounds byte happens to be0xff,DosForceDup()overwrites it withp->ps_filetab[OldHandle], leaks an SFT reference count (Sftp->sft_count += 1), and returnsSUCCESSinstead ofDE_INVLDHNDL.dup2(h, h)closes open handles: WhenOldHandle == NewHandleon an open handle,DosClose(NewHandle)closes the handle (ps_filetab[h] = 0xff, decrementssft_count), after whichDosForceDup()copies0xffback onto itself and incrementsSftp->sft_counton the closed SFT while returningSUCCESS.Fix
if (NewHandle >= p->ps_maxfiles) return DE_INVLDHNDL;(matchingget_sft_idx()and other JFT lookups in the kernel).if (OldHandle == NewHandle) return SUCCESS;afterget_sft(OldHandle)has verified thatOldHandleis a valid open handle.Verification
Tested locally with Open Watcom (
COMPILER=owlinux) and a 16-bit x86 NASM.COMtest program booted underqemu-system-i386:Before fix (
master):After fix:
./test/test.shQEMU boot test:boot wc: successia16-elf-gcc, OpenWatcom Linux, OpenWatcom DOS +./ci_test.sh): passedFixes #261