fix: stack-buffer-overflow (#1550), wrong statvfs block_size (#1547), path traversal (#1516)#1559
Open
Hardikrepo wants to merge 1 commit into
Open
fix: stack-buffer-overflow (#1550), wrong statvfs block_size (#1547), path traversal (#1516)#1559Hardikrepo wants to merge 1 commit into
Hardikrepo wants to merge 1 commit into
Conversation
…wrong statvfs block size field (nasa#1547), and path traversal in OS_FileSys_FindVirtMountPoint (nasa#1516) - utassert.c: clamp FormatLen1/FormatLen2 to sizeof(ScrubbedString)-1 before memcpy to prevent stack-buffer-overflow when caller-supplied String1Max/String2Max exceeds the 256-byte scrub buffers - os-impl-filesys.c (posix, qnx, rtems): use f_frsize instead of f_bsize as the block size when reporting statvfs results; f_frsize is the fundamental block size that correctly represents the physical size of storage blocks, while f_bsize is the preferred I/O transfer size and is not guaranteed to equal f_frsize on large drives - osapi-filesys.c: reject any virtual-mount-point path that contains a '..' component before prefix-matching to prevent path traversal attacks that could escape the virtual mount point boundary
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
This PR fixes three bugs found in the
devbranch:Fix #1550 — Stack-buffer-overflow in
UtAssert_StringBufCompare()File:
ut_assert/src/utassert.cRoot cause:
ScrubbedString1[256]andScrubbedString2[256]are fixed 256-byte stack buffers. When a fixed-length buffer longer than 255 bytes contains no NUL within the requested bound,FormatLen1/FormatLen2are set directly from the caller-suppliedString1Max/String2Max. The subsequentmemcpywrites past the end of the stack buffers causing a stack-buffer-overflow.Fix: Clamp
FormatLen1andFormatLen2tosizeof(ScrubbedString) - 1(255) immediately before anymemcpy, ensuring the copy never exceeds the buffer boundary.Fix #1547 —
OS_FileSysStatVolume_Impl()uses wrongstatvfsfield for block sizeFiles:
src/os/posix/src/os-impl-filesys.c,src/os/qnx/src/os-impl-filesys.c,src/os/rtems/src/os-impl-filesys.cRoot cause: After migrating to
statvfs(), the POSIX, QNX, and RTEMS implementations still assignstat_buf.f_bsizetoresult->block_size. Per POSIX,f_bsizeis the preferred I/O transfer block size whilef_frsizeis the fundamental file system block size used to compute actual storage (i.e.total_blocks * f_frsize= total bytes). On large drives these values are not guaranteed to be equal, causing incorrect free/total byte calculations.Fix: Replace
stat_buf.f_bsizewithstat_buf.f_frsizein all three affected OS ports.Fix #1516 — Path traversal via unchecked
..components inOS_FileSys_FindVirtMountPoint()File:
src/os/shared/src/osapi-filesys.cRoot cause:
OS_FileSys_FindVirtMountPoint()performed only a prefix match against the virtual mount point. A path such as/mnt/abc/../secretwould match the/mnt/abcmount point because the prefix check passes andtarget[mplen] == '/'. An attacker could craft a path that traverses outside the virtual mount boundary.Fix: Before performing the prefix match, scan the target path for any
/../or trailing/..sequence and returnfalseimmediately if found. Also rejects paths starting with../.Files Changed
ut_assert/src/utassert.cFormatLenbeforememcpysrc/os/posix/src/os-impl-filesys.cf_bsize→f_frsizesrc/os/qnx/src/os-impl-filesys.cf_bsize→f_frsizesrc/os/rtems/src/os-impl-filesys.cf_bsize→f_frsizesrc/os/shared/src/osapi-filesys.c..componentsTest plan
UtAssert_STRINGBUF_EQ()with buffers longer than 255 bytes no longer causes stack-buffer-overflowOS_FileSysStatVolume()returns correct byte counts on large drives wheref_frsize != f_bsizeOS_FileSys_FindVirtMountPoint()returnsfalsefor paths containing/../or..traversal