Repository navigation
compressor/zstd: validate decompression and fix DStream leak - #69584
lumir-sliva wants to merge 1 commit into
Conversation
ZstdCompressor::decompress() ignored the return value of ZSTD_decompressStream() and assumed every input chunk was fully consumed. A corrupt, truncated, or inconsistent frame therefore returned success (0) with silently truncated or garbage output, and callers (BlueStore, RGW, OSD message decompression) had no way to tell good data from bad. The compress() path in the same file already checks every libzstd return; decompress() never received the same treatment. Make decompress() reject bad input: - check ZSTD_createDStream() for NULL (return -ENOMEM) and ZSTD_initDStream() for an error code, matching compress(). - check the ZSTD_decompressStream() return for ZSTD_isError(). - require zstd to consume the whole input chunk; if it stops early the output buffer filled, meaning the decoded-length prefix understated the real size (a corrupt or inconsistent frame). - after the loop, require the frame to have ended (last return == 0) and to have produced exactly the number of bytes promised by the prefix. - free the DStream on the mid-loop early-return path that previously leaked it, and return -EINVAL/-ENOMEM instead of the bare -1. Also guard compress() against a source larger than the uint32_t length prefix can represent, which would otherwise truncate silently and make the data impossible to decompress. Add a unit test that compresses a payload and then feeds truncated, under-/over-sized-prefix, and garbage variants to decompress(), each of which must now fail with a negative error code. Tracker: https://tracker.ceph.com/issues/77334 Signed-off-by: Slíva, Lumír <[email protected]>
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
16 similar comments
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Closing as a duplicate of #69733, which fixes #77334 more completely (RAII on both contexts, hardened compress path, more tests) and is from the reporter's own team. Sorry for the dupe. |
ZstdCompressor::decompress()ignores the return ofZSTD_decompressStream()and assumes every input chunk is fully consumed. So a corrupt, truncated, or inconsistent zstd frame returns success (0) with silently truncated or garbage output, and callers (BlueStore, RGW, OSD message decompression) can't tell good data from bad. Same class of silent-corruption problem as the 2020 lz4 bug. Thecompress()path right above it already checks every libzstd return;decompress()just never got the same treatment. Reported by a user auditing the zstd path before turning it on in production (#77334).What changed in
decompress():ZSTD_createDStream()for NULL (-ENOMEM) andZSTD_initDStream()for an error, matchingcompress()ZSTD_decompressStream()return withZSTD_isError()-EINVAL/-ENOMEMinstead of a bare-1compress()also gets a guard against a source bigger than theuint32_tlength prefix can hold, which would otherwise truncate silently and make the data impossible to decompress.New unit test compresses a payload and feeds truncated, under-sized-prefix, over-sized-prefix, and garbage variants to
decompress(), each has to fail with a negative code now instead of returning 0.unittest_compressionpasses all 92 tests, including every zstd round-trip and the new corruption case.Tracker: https://tracker.ceph.com/issues/77334
Checklist