You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "masaori335 (via GitHub)" <gi...@apache.org> on 2026/10/01 07:54:14 UTC
[PR] cache: reject a Doc longer than the bytes read [trafficserver]
masaori335 opened a new pull request, #13768:
URL: https://github.com/apache/trafficserver/pull/13768
handleReadDone trusts doc->len and doc->hlen, and with STORE_COLLISION it does so before the caller checks the key. A Dir entry whose size is smaller than the Doc at its offset, such as one inserted after the shm directory snapshot at shutdown, lets unmarshal walk past the read buffer and corrupt the IOBuffer freelist.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cache: reject a Doc longer than the bytes read [trafficserver]
Posted by "masaori335 (via GitHub)" <gi...@apache.org>.
masaori335 commented on code in PR #13768:
URL: https://github.com/apache/trafficserver/pull/13768#discussion_r4204506476
##########
src/iocore/cache/CacheVC.cc:
##########
@@ -403,6 +403,15 @@ CacheVC::handleReadDone(int event, Event * /* e ATS_UNUSED */)
goto Ldone;
}
+ // Everything below trusts len and hlen, and STORE_COLLISION lets a doc that is not ours get this far.
+ if (doc->magic == DOC_MAGIC &&
Review Comment:
Good catch. A doc that isn't ours now leaves handleReadDone as DOC_MAGIC without reaching the RAM cache or unmarshal code, so the callers treat it as a collision and keep probing as before. Only our own doc is marked DOC_CORRUPT. Every handleReadDone caller compares the key before using len, so the foreign doc's length is never trusted. A new test case checks that a foreign doc with a bad length stops before unmarshal_http_info. Fixed in [5be75ab](https://github.com/apache/trafficserver/pull/13768/commits/5be75ab63e94b3c717929b83fb05aa13d4dfd97e).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cache: reject a Doc longer than the bytes read [trafficserver]
Posted by "masaori335 (via GitHub)" <gi...@apache.org>.
masaori335 merged PR #13768:
URL: https://github.com/apache/trafficserver/pull/13768
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cache: reject a Doc longer than the bytes read [trafficserver]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13768:
URL: https://github.com/apache/trafficserver/pull/13768#discussion_r4204522092
##########
src/iocore/cache/CacheVC.cc:
##########
@@ -403,6 +403,19 @@ CacheVC::handleReadDone(int event, Event * /* e ATS_UNUSED */)
goto Ldone;
}
+ // Everything below trusts len and hlen, and STORE_COLLISION lets a doc that is not ours get this far.
+ if (doc->magic == DOC_MAGIC &&
+ (doc->len < sizeof(Doc) || doc->len > io.aiocb.aio_nbytes || doc->hlen > doc->len - sizeof(Doc))) {
+ // Callers check the key before trusting len, so a doc that is not ours stays a collision and they keep probing.
+ // Marking it corrupt would fail a read whose own fragment may be further down the chain.
+ if (doc->first_key == *read_key || doc->key == *read_key) {
+ Warning("Doc length %u (hlen %u) does not fit the %zu bytes read - disk %s offset %" PRIu64, doc->len, doc->hlen,
+ static_cast<size_t>(io.aiocb.aio_nbytes), stripe->hash_text.get(), static_cast<uint64_t>(stripe->vol_offset(&dir)));
+ doc->magic = DOC_CORRUPT;
+ }
Review Comment:
A matching malformed document is only marked `DOC_CORRUPT`, but not every caller checks that marker. In particular, `openWriteOverwrite` checks `io.ok()` and `first_key` only (`CacheWrite.cc:639-648`), stores this buffer in `first_buf`, and later trusts its `len`/`hlen`. Therefore the header-update path can still consume the out-of-bounds lengths this guard is intended to reject. Mark the read result failed for matching malformed documents so all existing callers stop before accepting the buffer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cache: reject a Doc longer than the bytes read [trafficserver]
Posted by "cmcfarlen (via GitHub) via github" <gi...@trafficserver.apache.org>.
cmcfarlen commented on PR #13768:
URL: https://github.com/apache/trafficserver/pull/13768#issuecomment-6924688509
Cherry-picked to the 10.2.x branch as 8915080ddf for the 10.2.2 release.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cache: reject a Doc longer than the bytes read [trafficserver]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13768:
URL: https://github.com/apache/trafficserver/pull/13768#discussion_r4153113647
##########
src/iocore/cache/CacheVC.cc:
##########
@@ -403,6 +403,15 @@ CacheVC::handleReadDone(int event, Event * /* e ATS_UNUSED */)
goto Ldone;
}
+ // Everything below trusts len and hlen, and STORE_COLLISION lets a doc that is not ours get this far.
+ if (doc->magic == DOC_MAGIC &&
+ (doc->len < sizeof(Doc) || doc->len > io.aiocb.aio_nbytes || doc->hlen > doc->len - sizeof(Doc))) {
Review Comment:
The new `doc->len < sizeof(Doc)` rejection path is not exercised: every `boundary_cases` row uses a length of at least 3584. This guard also prevents underflow in the following `hlen` bound, so please add a case such as `len = sizeof(Doc) - 1` that expects `DOC_CORRUPT`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cache: reject a Doc longer than the bytes read [trafficserver]
Posted by "masaori335 (via GitHub)" <gi...@apache.org>.
masaori335 commented on code in PR #13768:
URL: https://github.com/apache/trafficserver/pull/13768#discussion_r4204811349
##########
src/iocore/cache/CacheVC.cc:
##########
@@ -403,6 +403,19 @@ CacheVC::handleReadDone(int event, Event * /* e ATS_UNUSED */)
goto Ldone;
}
+ // Everything below trusts len and hlen, and STORE_COLLISION lets a doc that is not ours get this far.
+ if (doc->magic == DOC_MAGIC &&
+ (doc->len < sizeof(Doc) || doc->len > io.aiocb.aio_nbytes || doc->hlen > doc->len - sizeof(Doc))) {
+ // Callers check the key before trusting len, so a doc that is not ours stays a collision and they keep probing.
+ // Marking it corrupt would fail a read whose own fragment may be further down the chain.
+ if (doc->first_key == *read_key || doc->key == *read_key) {
+ Warning("Doc length %u (hlen %u) does not fit the %zu bytes read - disk %s offset %" PRIu64, doc->len, doc->hlen,
+ static_cast<size_t>(io.aiocb.aio_nbytes), stripe->hash_text.get(), static_cast<uint64_t>(stripe->vol_offset(&dir)));
+ doc->magic = DOC_CORRUPT;
+ }
Review Comment:
Fixed in f89d4e3824. openWriteOverwrite never checked DOC_CORRUPT, so this was already possible for future-version and checksum-mismatch docs before this PR. It now leaves first_buf empty for a corrupt doc, so the writer sees it the same as a probe that found nothing. It still sets od->first_dir so the write replaces the bad entry. openWriteStartDone already rejects magic != DOC_MAGIC. I didn't make it an I/O error, because that would change every handleReadDone caller, including the read paths that drop the bad dir and probe again. The new test runs handleReadDone into openWriteOverwrite and checks the corrupt doc stays out of first_buf.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cache: reject a Doc longer than the bytes read [trafficserver]
Posted by "masaori335 (via GitHub)" <gi...@apache.org>.
masaori335 commented on code in PR #13768:
URL: https://github.com/apache/trafficserver/pull/13768#discussion_r4153499501
##########
src/iocore/cache/CacheVC.cc:
##########
@@ -403,6 +403,15 @@ CacheVC::handleReadDone(int event, Event * /* e ATS_UNUSED */)
goto Ldone;
}
+ // Everything below trusts len and hlen, and STORE_COLLISION lets a doc that is not ours get this far.
+ if (doc->magic == DOC_MAGIC &&
+ (doc->len < sizeof(Doc) || doc->len > io.aiocb.aio_nbytes || doc->hlen > doc->len - sizeof(Doc))) {
Review Comment:
Added len = sizeof(Doc) - 1 (corrupt) and len = sizeof(Doc) (valid) rows in 0d19eb14e0. With the len < sizeof(Doc) clause removed, only the new row fails.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cache: reject a Doc longer than the bytes read [trafficserver]
Posted by "masaori335 (via GitHub)" <gi...@apache.org>.
masaori335 commented on PR #13768:
URL: https://github.com/apache/trafficserver/pull/13768#issuecomment-5942431083
[approve ci clang-analyzer]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cache: reject a Doc longer than the bytes read [trafficserver]
Posted by "brbzull0 (via GitHub)" <gi...@apache.org>.
brbzull0 commented on code in PR #13768:
URL: https://github.com/apache/trafficserver/pull/13768#discussion_r4163756117
##########
src/iocore/cache/CacheVC.cc:
##########
@@ -403,6 +403,15 @@ CacheVC::handleReadDone(int event, Event * /* e ATS_UNUSED */)
goto Ldone;
}
+ // Everything below trusts len and hlen, and STORE_COLLISION lets a doc that is not ours get this far.
+ if (doc->magic == DOC_MAGIC &&
Review Comment:
question (non-blocking): This check runs before the key comparison, so it also marks docs whose key doesn't match. Head and Earliest handle that well: they drop the bad dir and probe again. The Middle read path (`CacheRead.cc:485-493`) doesn't: on `DOC_CORRUPT` it goes to `Lerror`. Before this change, a key-mismatched doc there fell through to `directory.probe()` and could still find the right fragment further down the collision chain. Now that same inconsistent dir fails the whole read. It should be rare, since it needs a tag collision plus a size mismatch. Is failing the read intended there, or should the mismatched-key case keep probing?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org