Skip to content

[autobackport: sssd-2-13] kcm: do not hang on empty request message body - #9561

Merged
alexey-tikhonov merged 4 commits into
SSSD:sssd-2-13from
sssd-bot:SSSD-sssd-backport-pr9530-to-sssd-2-13
Oct 26, 2026
Merged

alexey-tikhonov merged 4 commits into
SSSD:sssd-2-13from
sssd-bot:SSSD-sssd-backport-pr9530-to-sssd-2-13

Conversation

@sssd-bot

Copy link
Copy Markdown
Contributor

This is an automatic backport of PR#9530 kcm: do not hang on empty request message body to branch sssd-2-13, created by @pbrezina.

Please make sure this backport is correct.

Note

The commits were cherry-picked without conflicts.

You can push changes to this pull request

git remote add sssd-bot git@github.com:sssd-bot/sssd.git
git fetch sssd-bot refs/heads/SSSD-sssd-backport-pr9530-to-sssd-2-13
git checkout SSSD-sssd-backport-pr9530-to-sssd-2-13
git push sssd-bot SSSD-sssd-backport-pr9530-to-sssd-2-13 --force

Original commits
d5f68d9 - KCM: set the client fd non-blocking to avoid event-loop hangs
2c8f638 - KCM: allocate body buffer only once
4a7e9ac - KCM: reject request bodies smaller than the protocol header
0721b66 - KCM: add kcm_recv_timeout to avoid stuck requests

Backported commits

  • b82c07b - KCM: set the client fd non-blocking to avoid event-loop hangs
  • 280e3a7 - KCM: allocate body buffer only once
  • 3df1256 - KCM: reject request bodies smaller than the protocol header
  • 2ac29da - KCM: add kcm_recv_timeout to avoid stuck requests

Original Pull Request Body

KCM reads body lenght and body in two-step sequence. If a body lenght was send but the body was not, kcm hanged since the file descriptor was not set as non-blocking. When this was fixed, kcm allocated the body buffer again and again on each read interupt, so now we allocate it only once.

Additionally, pre-existing mechanism guarantees that there can only be one running KCM requests per-connection by making the conn fd unreadable. It is set readable again only when we sent the reply. (This was already implemented)

Together this fixes CVE-2026-80048.

As a bonus, I added a simple sanity check for the body.

@alexey-tikhonov
alexey-tikhonov removed the request for review from sumit-bose October 26, 2026 17:10
@alexey-tikhonov alexey-tikhonov added no-backport This should go to target branch only. Accepted labels Oct 26, 2026
The listening socket fd is non-blocking, but accept() does not propagate
that flag to the accepted connection. KCM issues several I/O syscalls
within a single tevent callback (read the length header then the body in
kcm_recv_data(); write the length, retcode and payload in
kcm_send_data()). A tevent event only guarantees the first syscall can
make progress without blocking, so on a blocking fd a client that sends
the 4-byte length header and withholds the body blocks readv() and hangs
the entire single-threaded KCM responder event loop.

Set the accepted fd non-blocking in kcm_connection_setup() so an
incomplete transfer surfaces as EAGAIN and is retried on the next event.

:fixes: CVE-2026-80048

Assisted-By: Claude Code (Opus 4.8)
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit d5f68d9)
Now that kcm_iovec_op() correctly returns EAGAIN on a partial body read,
kcm_recv_data() is re-entered to resume the transfer. It re-allocated the
body buffer on every entry, pointing v_msg.kiov_base at the new allocation
while leaving nprocessed untouched: the previous partially-filled buffer
was orphaned (a per-retry leak) and the already-read prefix of the new
buffer was left uninitialized, corrupting the assembled message.

Allocate the buffer only when kiov_base is still NULL, so re-entries keep
filling the same allocation.

Related to: CVE-2026-80048

Assisted-By: Claude Code (Opus 4.8)
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit 2c8f638)
kcm_recv_data() validated only the upper bound of the attacker-controlled
body length, accepting any value down to zero. A body shorter than the
4-byte protocol header (major, minor, opcode) can never be a valid KCM
message, yet it was allocated, read, and only rejected deep in
kcm_input_parse().

Reject msglen < KCM_MSG_HEADER_SIZE up front, before any allocation.
The SAFEALIGN_*_CHECK macros already prevent out-of-bounds reads, so this
is defense-in-depth and earlier, cheaper rejection.

Assisted-By: Claude Code (Opus 4.8)
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit 4a7e9ac)
This adds a new undocumented kcm "recv_timeout" option (defaults to 5s)
and a timer on incoming request - the request payload must be read
within the given time, otherwise the client connection is killed.

Note that we can not just shorten the client_idle_timeout as that would
prevent client reconnecting on interactive cli applications. See:
00ae18d

Related to: CVE-2026-80048

Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit 0721b66)
@sssd-bot

Copy link
Copy Markdown
Contributor Author

The pull request was accepted by @alexey-tikhonov with the following PR CI status:


🟢 CodeQL (success)
🟢 rpm-build:centos-stream-10-x86_64:upstream (success)
🟢 rpm-build:fedora-44-x86_64:upstream (success)
🟢 testing-farm:centos-stream-10-x86_64:system (success)
🟢 testing-farm:fedora-44-x86_64:system (success)
🟢 Build / freebsd (success)
🟢 Build / make-distcheck (success)
🟢 Static code analysis / codeql (success)
🟢 Static code analysis / files-changed (success)
➖ Static code analysis / polarion (skipped)
🟢 Static code analysis / pre-commit (success)
➖ Static code analysis / python-system-tests (skipped)


There are unsuccessful or unfinished checks. Make sure that the failures are not related to this pull request before merging.

@sssd-bot
sssd-bot force-pushed the SSSD-sssd-backport-pr9530-to-sssd-2-13 branch from 2ac29da to f512c47 Compare October 26, 2026 20:09
@alexey-tikhonov
alexey-tikhonov merged commit 5fcbfe8 into SSSD:sssd-2-13 Oct 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Accepted no-backport This should go to target branch only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants