Repository navigation
Reject paths with an embedded NUL byte in filesystem containment checks - #119846
Conversation
`pathStartsWith` and `fileOrSymlinkPathStartsWith` compare the whole value of the path, while every syscall that the path is later passed to (`open`, `mkdir`, `stat`) stops at the first NUL byte. A path shaped as `<target>\0/<traversal back into the base directory>` was therefore reported as contained in the base directory, while the kernel addressed `<target>`, which can be anywhere on the filesystem. Both helpers now report such a path as not contained, so that every containment check built on them fails closed - among them `assertLocalPathCorrect`, the `user_files` fence of the local data lake table engines and table functions. `resolvePathRelativelyToBase` rejects it explicitly, because it returns a path that is passed to syscalls directly; `listObjects` already had that check for a reason of its own. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [a6a4be6] Summary: ✅
AI ReviewSummaryThis PR hardens filesystem containment against embedded-NUL paths by making Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit a6a4be6.
Changed lines: Changed C/C++ lines covered: 68/69 (98.55%) · Uncovered code |
`grep -c` counted the error twice, because the client prints the log line of the server next to the exception. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 22 s compile time in total, 9 of them have a recent master baseline. |
The existing regression only exercised `deltaLakeLocal` / `icebergLocal`, whose check ANDs `fileOrSymlinkPathStartsWith` with `pathStartsWith`, so it stayed green if either helper regressed alone and never reached the guard in `resolvePathRelativelyToBase`. Add: - helper-level tests for `pathStartsWith` (both overloads) and `fileOrSymlinkPathStartsWith`, with the escape shape `<prefix>/../probe\0/../<prefix>/file` and the same traversal without a NUL as a positive control; - a direct test of `resolvePathRelativelyToBase`, asserting `BAD_ARGUMENTS` for NUL-bearing paths and keeping the plain-traversal `PATH_ACCESS_DENIED` and accepted-path behaviour as controls; - a functional test for a `fileOrSymlinkPathStartsWith`-only surface (the `file` function) and a `pathStartsWith`-only surface (the `Filesystem` database engine). Each names an existing entry in `user_files` followed by a NUL and a suffix, so a check that ignored the NUL would let the truncated path through and the query would succeed. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…irst filesystem probe `getPathsList` stats the user-supplied path (`fs::is_directory`, `fs::file_size`) and expands its globs on the filesystem before the matched paths are checked for containment in `user_files_path`, and every syscall stops at the first NUL byte. The `file` table function and the `File` engine could therefore still make the server probe a truncated location that the containment check never sees. Reject such a path up front with `BAD_ARGUMENTS`, and do the same in `checkCreationIsAllowedResolvingDotDot`, whose `..` resolver canonicalizes the head of the path on the filesystem. Test `05213_storage_file_embedded_nul` covers the table function (plain, glob, archive syntax, `INSERT`) and the engine, each with an existing entry followed by a NUL and a suffix, so that the truncated path would succeed. Addresses the AI review on #119846 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119846&sha=8ed22a0374c684436783efb7b7c3278d9443e1ff&name_0=PR&name_1=AST%20fuzzer%20(amd_debug,%20targeted,%20old_compatibility) and provide a fix in a separate PR. If the fix is already in progress, link it here. The fuzzer hit The other red, |
|
The fix is in progress: #110020. Verified today against the failing query, on master
The trigger is the #110020 threads the enclosing (sub)query context through both walks, so the arm is judged ineligible and no parallel-replicas plan is attempted. It has been open since 2026-07-10 and has not been reviewed yet. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Primitive, but okay.
Backport #119846 to 26.9: Reject paths with an embedded NUL byte in filesystem containment checks
One conflict, in `StorageFile.cpp`. Upstream puts its new `throwIfPathContainsEmbeddedNul` call in `checkCreationIsAllowedResolvingDotDot`, a wrapper that resolves `..` on the filesystem before the containment check and therefore has to reject the path first. That wrapper, and the `resolveDotDotForContainmentCheck` it is built on, do not exist on this branch: the four sites that call it on master call `checkCreationIsAllowed` directly here. The wrapper is dropped and the call is placed at the top of `checkCreationIsAllowed` instead, which is the function the wrapper delegates to and which has no other callers on this branch, so the four sites are covered exactly as upstream covers them. It runs before the `ApplicationType::SERVER` early return, as upstream's does. The other two hunks of the file, the helper itself and the `getPathsList` call, are taken unchanged, as are `filesystemHelpers.cpp` and `LocalObjectStorage.cpp`. Without this the branch would still fail closed - a NUL path reaches `fileOrSymlinkPathStartsWith`, which the same change teaches to report it as not contained - but with DATABASE_ACCESS_DENIED instead of upstream's BAD_ARGUMENTS. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Cherry pick #119846 to 26.3: Reject paths with an embedded NUL byte in filesystem containment checks
Cherry pick #119846 to 26.7: Reject paths with an embedded NUL byte in filesystem containment checks
One conflict, in `StorageFile.cpp`. Upstream puts its new `throwIfPathContainsEmbeddedNul` call in `checkCreationIsAllowedResolvingDotDot`, a wrapper that resolves `..` on the filesystem before the containment check and therefore has to reject the path first. That wrapper, and the `resolveDotDotForContainmentCheck` it is built on, do not exist on this branch: the four sites that call it on master call `checkCreationIsAllowed` directly here. The wrapper is dropped and the call is placed at the top of `checkCreationIsAllowed` instead, which is the function the wrapper delegates to and which has no other callers on this branch, so the four sites are covered exactly as upstream covers them. It runs before the `ApplicationType::SERVER` early return, as upstream's does. The other two hunks of the file, the helper itself and the `getPathsList` call, are taken unchanged, as are `filesystemHelpers.cpp` and `LocalObjectStorage.cpp`. Without this the branch would still fail closed - a NUL path reaches `fileOrSymlinkPathStartsWith`, which the same change teaches to report it as not contained - but with DATABASE_ACCESS_DENIED instead of upstream's BAD_ARGUMENTS. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Cherry pick #119846 to 26.8: Reject paths with an embedded NUL byte in filesystem containment checks
One conflict, in `StorageFile.cpp`. Upstream puts its new `throwIfPathContainsEmbeddedNul` call in `checkCreationIsAllowedResolvingDotDot`, a wrapper that resolves `..` on the filesystem before the containment check and therefore has to reject the path first. That wrapper, and the `resolveDotDotForContainmentCheck` it is built on, do not exist on this branch: the four sites that call it on master call `checkCreationIsAllowed` directly here. The wrapper is dropped and the call is placed at the top of `checkCreationIsAllowed` instead, which is the function the wrapper delegates to and which has no other callers on this branch, so the four sites are covered exactly as upstream covers them. It runs before the `ApplicationType::SERVER` early return, as upstream's does. The other two hunks of the file, the helper itself and the `getPathsList` call, are taken unchanged, as are `filesystemHelpers.cpp` and `LocalObjectStorage.cpp`. Without this the branch would still fail closed - a NUL path reaches `fileOrSymlinkPathStartsWith`, which the same change teaches to report it as not contained - but with DATABASE_ACCESS_DENIED instead of upstream's BAD_ARGUMENTS. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ilesystem containment checks
…ilesystem containment checks
…ilesystem containment checks
Backport #119846 to 26.8: Reject paths with an embedded NUL byte in filesystem containment checks
Backport #119846 to 26.7: Reject paths with an embedded NUL byte in filesystem containment checks
Backport #119846 to 26.3: Reject paths with an embedded NUL byte in filesystem containment checks
… byte in filesystem containment checks
A path with an embedded NUL byte passed the filesystem containment checks.
pathStartsWithandfileOrSymlinkPathStartsWithcompare the whole value of the path, while every syscall the path is later passed to (open,mkdir,stat) stops at the first NUL byte, so a path shaped as<target>\0/<traversal back into the base directory>was reported as contained in the base directory while the kernel addressed<target>.Both helpers now report such a path as not contained, so that every containment check built on them fails closed - among them the
user_filesfence of the local data lake table engines and table functions.resolvePathRelativelyToBaserejects it explicitly, because it returns a path that is passed to syscalls directly.The
filetable function and theFileengine stat the path and expand its globs on the filesystem before the matched paths are checked for containment, soStorageFilerejects a path with an embedded NUL byte up front, before the first filesystem probe.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed filesystem containment checks accepting a path with an embedded NUL byte. A
DeltaLakeLocalorIcebergLocaltable could be pointed outside ofuser_filesthis way.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119846]
Version info
26.9.1.1604,26.8.8.7,26.7.12.7,26.3.33.111