Skip to content

Fixed stack buffer overflow parsing cifs and panfs mount sources - #6519

Open
Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:nfs-mount-source-bounds
Open

Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:nfs-mount-source-bounds

Conversation

@Dhanu-dynamic

Copy link
Copy Markdown
Contributor

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.

Repro: with an ASan build of cf-agent, mount something as //<600 x 'A'>/share/dir on a directory named x cifs y and run a policy with a single storage: promise (volume => ... freespace). Before: stack-buffer-overflow WRITE in GetHostAndSource(), called from LoadMountInfo() and VerifyStoragePromise(), overflowing host. 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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant