Skip to content

Fixed stack buffer overflow in GetServerLiteral for TLS VAR requests - #6423

Open
Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:getserverliteral-sendbuffer-size
Open

Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:getserverliteral-sendbuffer-size

Conversation

@Dhanu-dynamic

Copy link
Copy Markdown
Contributor

the VAR handler in BusyWithNewProtocol (server_tls.c) declares its sendbuffer as CF_BUFSIZE - CF_INBAND_OFFSET bytes, the most one transaction can carry, but GetServerLiteral in server_common.c zeroes and snprintf()s CF_BUFSIZE bytes into whatever buffer it is given. so any VAR request admitted by the literals ACL writes 8 bytes past the end of that stack buffer in the root cf-serverd; in the community build the ReturnLiteralData stub makes the "BAD: Not found" branch do it on every such request, and in Enterprise a literal of 4088 bytes or more overflows through the snprintf too. the classic caller in BusyWithClassicConnection hands over a full CF_BUFSIZE buffer and is unaffected. pass the buffer size into GetServerLiteral the same way DoExec2 already takes sendbuf_size and bound the writes to it; both callers pass sizeof(sendbuffer). nothing is lost, since SendTransaction refuses anything longer than CF_MSGSIZE anyway. the regression test in protocol_test.c runs GetServerLiteral over a socketpair with a CF_MSGSIZE buffer followed by guard bytes: before the change the guard bytes read 0 instead of 0x5a, after it they are untouched and the reply is still "BAD: Not found". full unit suite passes under AddressSanitizer with -Werror.

GetServerLiteral() zeroed and formatted CF_BUFSIZE bytes into the
sendbuffer it was handed, but BusyWithNewProtocol() allocates that
buffer as CF_BUFSIZE - CF_INBAND_OFFSET bytes (the most a single
transaction can carry). Any VAR request admitted by the literals ACL
therefore wrote 8 bytes past the end of the handler's stack buffer.

Pass the buffer size into GetServerLiteral(), as DoExec2() already
does, and bound the writes to it. Both callers pass sizeof(sendbuffer).

Changelog: Title
Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com>
@cf-bottom

Copy link
Copy Markdown

Thanks for submitting a pull request! Maybe @craigcomstock can review this?

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.

2 participants