Skip to content

cf-serverd: Fixed off-by-one stack overflow in acl_CheckPath() - #6518

Open
Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:acl-checkpath-mangled-path-bound
Open

Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:acl-checkpath-mangled-path-bound

Conversation

@Dhanu-dynamic

Copy link
Copy Markdown
Contributor

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.

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 🚀 The commit message is rather long and confusing for such a small and trivial fix. Please shorten it.

@larsewi

larsewi commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@cf-bottom Jenkins please :)

@cf-bottom

Copy link
Copy Markdown

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
Dhanu-dynamic force-pushed the acl-checkpath-mangled-path-bound branch from 70996a2 to 0e657ae Compare November 20, 2026 17:53
@Dhanu-dynamic

Copy link
Copy Markdown
Contributor Author

Fair enough, trimmed the commit message down to three lines. Code is unchanged.

@larsewi

larsewi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@cf-bottom Jenkins please :)

@larsewi larsewi added the cherry-pick? Fixes which may need to be cherry-picked to LTS branches label Nov 23, 2026
@cf-bottom

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick? Fixes which may need to be cherry-picked to LTS branches

Development

Successfully merging this pull request may close these issues.

3 participants