Skip to content

ZOOKEEPER-5124 (C client) Chroot path validation fails to isolate namespaces - #2499

Open
apurtell wants to merge 2 commits into
apache:masterfrom
apurtell:ZOOKEEPER-5124
Open

apurtell wants to merge 2 commits into
apache:masterfrom
apurtell:ZOOKEEPER-5124

Conversation

@apurtell

@apurtell apurtell commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

On a chrooted handle, the C client added the chroot to the client path before it validated the path. The check then incorrectly considered the full path, so a path that did not start with "/" would be silently accepted. Also, sub_string removed the chroot from server paths by length only rather than at path component boundaries.

prepend_chroot now returns NULL for a NULL, empty, or relative client path on a chrooted handle. The caller then returns ZBADARGUMENTS, as on a plain handle, or ZSYSTEMERROR if the allocation failed. sub_string removes the chroot path only on a path component boundary and returns other paths unchanged. Sync config reads now use zoo_awgetconfig with a completion to standardize handling on one path.

On a chrooted handle, a sequential create of / used to create a sibling of the chroot node. It now creates a child of the chroot node.

New tests in Zookeeper_simpleSystem: testChrootPathValidation, testChrootGetConfig, and testChrootServerPathMapping. New test TestReconfigServer::testChrootConfigWatch checks a config watch event on a chrooted handle after a reconfig.

@anmolnar

Copy link
Copy Markdown
Contributor

AI-assisted review on behalf of @anmolnar

Thanks for this. I traced the three fixes against zookeeper.c and they look correct to me:

  • prepend_chroot returning NULL is safe at every call site, and the mode reaches it for all create variants, including multi.
  • A sequential create of / now stays under the chroot.
  • The sync config read now matches the async one and the Java client.

I did not build or run the tests.

A few points, none blocking:

  1. Config tests. testChrootGetConfig says it covers synchronous and asynchronous reads, but zoo_getconfig and zoo_wgetconfig are both sync. Could it also call zoo_agetconfig on the chrooted handle? Likewise, the ZOO_CONFIG_NODE exception in sub_string is only exercised by calling sub_string directly. A test that sets a config watch on a chrooted handle and checks the event path would cover the real case.

  2. Sequential create of /. On a chrooted handle this used to create a sibling of the chroot node and now creates a child. I agree with the fix, but it is a visible behaviour change and worth a line in the JIRA. The Java client (Chroot.NotRoot.prepend) still has the old behaviour. Do you plan a follow-up for that?

  3. Multi assertion. The test checks only rc != ZOK. This is the same nonblocking_send remapping I raised on ZOOKEEPER-5125 (C client) zoo_multi error handling crashes, misreads results, and hangs #2500. If that PR ends up returning the real code, this test could assert ZBADARGUMENTS. The two PRs also both touch zookeeper.c, so the second to land will need a rebase.

  4. Minor.

    • prepend_chroot reports an allocation failure as ZBADARGUMENTS rather than ZSYSTEMERROR.
    • zoo_wgetconfig now duplicates the body of zoo_wget; a shared helper would keep them from drifting.
    • With a chroot of /zookeeper, a config watch path would be rewritten to /config, because the chroot match runs before the config exception. A comment is enough.

Andrew Purtell and others added 2 commits November 19, 2026 16:19
…espaces

On a chrooted handle, the C client added the chroot to the client path
before it validated the path. The check then incorrectly considered the
full path, so a path that did not start with "/" would be silently
accepted. Also, sub_string removed the chroot from server paths by
length only rather than at path component boundaries.

prepend_chroot now returns NULL for a NULL, empty, or relative client
path on a chrooted handle. The isValidPath check of the caller then
returns ZBADARGUMENTS, as on a plain handle. sub_string removes the
chroot path only on a path component boundary and returns other paths
unchanged. Sync config reads now use zoo_awgetconfig with a completion
to standardize handling on one path.

New tests in Zookeeper_simpleSystem: testChrootPathValidation,
testChrootGetConfig, and testChrootServerPathMapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ndle

Address review feedback:

- Read the config with zoo_agetconfig in testChrootGetConfig, and check
  that the result matches the sync read.
- Add TestReconfigServer::testChrootConfigWatch. It sets a config watch
  on a chrooted handle, runs a reconfig, and checks the event type and
  path. It also checks that the client logs no chroot path error.
- Return ZSYSTEMERROR when prepend_chroot fails to allocate.
- Share one helper between zoo_wget and zoo_wgetconfig.
- Document the /zookeeper chroot case in sub_string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apurtell

apurtell commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Reply from Claude Code (an AI assistant), on behalf of @apurtell.

@anmolnar Thanks for the review. Addressed in 9637431:

  1. testChrootGetConfig now also reads with zoo_agetconfig and checks it matches the sync read. New TestReconfigServer::testChrootConfigWatch sets a config watch on a chrooted handle, runs a reconfig, and checks the event type, the path, and that no chroot error is logged.
  2. Agreed. The description now notes the sequential create change, and I'll add it to the JIRA. A follow-up JIRA for Chroot.NotRoot.prepend in the Java client makes sense; I'll file one.
  3. ZOOKEEPER-5125 (C client) zoo_multi error handling crashes, misreads results, and hangs #2500 now returns the real call-time code. Whichever of the two lands second will change this assertion to ZBADARGUMENTS during its rebase.
  4. Done: ZSYSTEMERROR on allocation failure, a shared wget_sync helper, and a comment on the /zookeeper chroot case in sub_string.

All C client tests pass on Linux with OpenSSL 3.2+, when #2510 is applied for the test certificates.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants