Repository navigation
cf-serverd: Fixed off-by-one stack overflow in acl_CheckPath() - #6518
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
larsewi
requested changes
Nov 20, 2026
larsewi
left a comment
Contributor
There was a problem hiding this comment.
Thanks 🚀 The commit message is rather long and confusing for such a small and trivial fix. Please shorten it.
Contributor
|
@cf-bottom Jenkins please :) |
|
Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/15159/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-15159/ |
A 4096 character request path (OPENDIR/STAT on a directory with a PATH_MAX - 1 canonical path) wrote the NUL one byte past mangled_path. Skip the special variable check when the path does not fit. Changelog: Title Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com>
Dhanu-dynamic
force-pushed
the
acl-checkpath-mangled-path-bound
branch
from
November 20, 2026 17:53
70996a2 to
0e657ae
Compare
Contributor
Author
|
Fair enough, trimmed the commit message down to three lines. Code is unchanged. |
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.
acl_CheckPath() copies the requested path, reqpath_len + 1 bytes, into
char mangled_path[PATH_MAX] before substituting the $(connection.*)
variables, without checking that it fits. The TLS OPENDIR handler, and
STAT when the target is a directory, append a trailing slash to the
PreprocessRequestPath() result before calling acl_CheckPath(). That
result lives in filename[CF_BUFSIZE + 1] and realpath() returns up to
PATH_MAX - 1 characters, so a directory whose canonical path is 4095
characters reaches acl_CheckPath() as a 4096 character string, and the
memcpy() writes the terminating NUL one byte past mangled_path on the
stack of cf-serverd.
This happens before any access decision, so a client that completed
the TLS handshake can trigger it with an OPENDIR or STAT naming such a
directory, for example through a short symlink to a deep directory that
any local user can create under /tmp.
A path that long cannot hold the expanded variables either, so skip the
special variable check for it, the same as when ReplaceSpecialVariables()
overflows. Paths shorter than PATH_MAX are unchanged.
Checked with an AddressSanitizer build of acl_CheckPath(), ReplaceSpecialVariables(), PathAppendTrailingSlash() and StringReplace() taken from the tree, fed a 4095 character canonical path the way the OPENDIR handler does: stack-buffer-overflow WRITE of size 4097 into the 4096 byte mangled_path before the change, clean after.