Repository navigation
Fixed stack buffer overflow parsing cifs and panfs mount sources - #6519
Open
Dhanu-dynamic wants to merge 1 commit into
Open
Dhanu-dynamic wants to merge 1 commit into
Dhanu-dynamic wants to merge 1 commit into
Conversation
LoadMountInfo() hands the first field of a mount(8) line to GetHostAndSource() when any word on the line is "cifs" or "panfs". That helper split the field into host[256] and source[1024] with copy loops that had no bounds and no end-of-string check: the cifs/panfs branch copied until it had seen three slashes, the nfs branch until it found a ':', and the source copy ran to the end of the field, which can be 4095 bytes. A long server name overflowed host, a long share path overflowed source, and a field with fewer than three slashes or without a ':' was read past its terminating NUL. The panfs and cifs flags were also never reset between lines (only nfs was), so after the first cifs or panfs mount every later line whose source is not an absolute path, such as a tmpfs mounted afterwards, was parsed this way too. mount(8) prints sources and mountpoints verbatim, so such a line can come from a FUSE mount, whose fsname and mountpoint are chosen by the user who mounts it. LoadMountInfo() runs in the root agent for any storage promise. Measure the host and source parts first and leave both empty when they do not fit, and reset panfs and cifs for every line like nfs. Changelog: Title Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com>
|
Thank you for submitting a pull request! Maybe @larsewi can review this? |
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.
LoadMountInfo() hands the first field of a mount(8) line to GetHostAndSource() when any word on the line is "cifs" or "panfs". That helper split the field into
host[256]andsource[1024]with copy loops that had no bounds and no end-of-string check: the cifs/panfs branch copied until it had seen three slashes, the nfs branch until it found a ':', and the source copy ran to the end of the field, which can be 4095 bytes. A long server name overflowedhost, a long share path overflowedsource, and a field with fewer than three slashes or without a ':' was read past its terminating NUL.The panfs and cifs flags were also never reset between lines (only nfs was), so after the first cifs or panfs mount every later line whose source is not an absolute path, such as a tmpfs mounted afterwards, was parsed this way too.
mount(8) prints sources and mountpoints verbatim, so such a line can come from a FUSE mount, whose fsname and mountpoint are chosen by the user who mounts it. LoadMountInfo() runs in the root agent for any storage promise.
Measure the host and source parts first and leave both empty when they do not fit, and reset panfs and cifs for every line like nfs.
Repro: with an ASan build of cf-agent, mount something as
//<600 x 'A'>/share/diron a directory namedx cifs yand run a policy with a singlestorage:promise (volume => ... freespace). Before: stack-buffer-overflow WRITE in GetHostAndSource(), called from LoadMountInfo() and VerifyStoragePromise(), overflowinghost. With a cifs line followed by a plain tmpfs mount, a debug build trips the assert in GetHostAndSource(). After: both runs are clean and the long source is skipped with a verbose message.The new test_GetHostAndSource in tests/unit/nfs_test.c fails under AddressSanitizer on the old code (read past the end of "//server") and passes after. The rest of the unit suite passes, apart from mon_processes_test, which counts users from ps, does not build nfs.c, and fails inside my container.