-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CVE-2018-25032 (zlib memory corruption on deflate) #605
Comments
This bug was reported by Danilo Ramos of Eideticom, Inc. It has lain in wait 13 years before being found! The bug was introduced in zlib 1.2.2.2, with the addition of the Z_FIXED option. That option forces the use of fixed Huffman codes. For rare inputs with a large number of distant matches, the pending buffer into which the compressed data is written can overwrite the distance symbol table which it overlays. That results in corrupted output due to invalid distances, and can result in out-of-bound accesses, crashing the application. The fix here combines the distance buffer and literal/length buffers into a single symbol buffer. Now three bytes of pending buffer space are opened up for each literal or length/distance pair consumed, instead of the previous two bytes. This assures that the pending buffer cannot overwrite the symbol table, since the maximum fixed code compressed length/distance is 31 bits, and since there are four bytes of pending space for every three bytes of symbol space.
PR to fix in nixpkgs from @twz123 NixOS/nixpkgs#165642 |
PR to fix in Alpine aports from @ncopa https://git.alpinelinux.org/aports/commit/?id=361df5902aa1e81594b17f06a13e10527dfb8aed and alpinelinux/aports@361df59 |
Fixed in OpenWrt down to 19.07 release with openwrt/openwrt@b3aa290 |
Fixed in Debian, the relevant bug is https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1008265 and the version with the fix is zlib/1:1.2.11.dfsg-4 |
Ubuntu has tracked this as https://ubuntu.com/security/CVE-2018-25032 and has a proposed patch which will bring the version to 1:1.2.11.dfsg-2ubuntu9, details are up to date at https://launchpad.net/ubuntu/+source/zlib . Ubuntu notes that "rsync" is also affected and is fixed in 3.1.3-6. |
Fedora and Red Hat are tracking this bug at https://bugzilla.redhat.com/show_bug.cgi?id=2067945 and there is no "fixed in" version as of this writing. It's also marked as affecting the packages "mingw-zlib" and "rsync". |
@briangreenery It looks like this Ubuntu patch at https://launchpad.net/ubuntu/+source/zlib/1:1.2.11.dfsg-2ubuntu9 also picks up the deflatePrime() validation check you reference at 4346a16 . |
@taviso posts a reproducer at https://www.openwall.com/lists/oss-security/2022/03/26/1 with a sample input file that triggers the bug when run against a minimal compressor that uses zlib. |
In https://twitter.com/OpenBSD_src/status/1507325285665968130 there is a reference to a (forthcoming) errata for OpenBSD with the name "errata/7.0/018_zlib.patch.sig". From the looks of it this hasn't been published just yet, but when it does I expect it to be at https://ftp.openbsd.org/pub/OpenBSD/patches/7.0/common/ The reference acknowledges mbuhl and millert of the OpenBSD project. From the looks of it, @bluhm is also doing work for OpenBSD on zlib, see e.g. |
In zlib-ng/zlib-ng#1208 @nmoinvaz adds a unit test for CVE-2018-25032 using test/CVE-2018-25032/test.txt which is a file beginning with AAABAACAA that was contributed by @taviso . zlib-ng passes the unit test for that file, whereas zlib (master) does not. |
So much excitement! I will release the develop branch to master. Note that this bug is only when |
not really, because of this condition: https://github.com/madler/zlib/blob/master/trees.c#L976
|
I don't understand your comment rurban. |
When cherry-picking it to Alpine Linux I saw that there was a second commit (4346a16) that was done the same day as the commit that fixes the CVE. It happens that security fixes introduces regressions or are incomplete so I often look at commits that happens directly before and after security fixes. I also thought that it looked like 4346a16 commit could have security implication, but I have no idea if its does. I included it just in case, and because the change was done at the same time as the security fix. |
Note, this is also reproducible with |
@ebiggers Can you provide an example? |
zlib 1.2.12 is now live on the master branch here, which includes the remedy from 2018. |
@madler Eric posted a reproducer that does work with Z_DEFAULT_STRATEGY to oss-security. The file is here: https://www.openwall.com/lists/oss-security/2022/03/28/1 IMHO, that makes this bug far more critical. |
For Chromium (and AOSP since it uses Chromium's zlib starting with Android R), we actively backported the fix from 'develop' all the way back in 2018: Plus, we have fuzzers covering Z_FIXED: |
A unit test stressing the bug can be found at: |
Bump zlib to 1.2.12 Fixes: [CVE-2018-25032](https://nvd.nist.gov/vuln/detail/CVE-2018-25032) Refs: - GHSA-jc36-42cf-vqwj - madler/zlib#605 Signed-off-by: Noel Georgi <git@frezbo.dev>
Summary: Zlib (https://www.zlib.net/) has been updated to 1.2.12 due to CVE-2018-25032 - https://nvd.nist.gov/vuln/detail/CVE-2018-25032 - madler/zlib#605 The source .tar.gz is no longer available, and the Makefile for rocksdb now fails as a result. This PR updates the dependency to the newer (and available) version, 1.2.12 Pull Request resolved: #9764 Reviewed By: ajkr Differential Revision: D35220367 Pulled By: jay-zhuang fbshipit-source-id: 1f68ff8f048a6dba42077f048ac143468f0e2478
does the new 1.2.12 release fixes this problem too, or will there be a followup issue? |
I just saw this CVE using Snyk to scan a container image. Glad the bug has a patch! Thanks for the fix! |
Could anyone please give me some guidance regarding the reproducer? Then I saw, that I should you the zpipe utility, but that's where the problem arrives. I would be so grateful for any kind of help with this. How I've used the zpipe: |
It is an out-of-bounds memory read, which is undefined behavior, so a crash is not guaranteed. You can compile both zlib and the program using gcc's
The point is that if |
This was essentially the same problem, so it was fixed by the same commit and thus is fixed in 1.2.12. |
And did someone (if you know of anything that could be used in this test) create the inflate() already so I don't invent the wheel again? |
@ljavorsk this commit in @zlib-ng zlib-ng/zlib-ng#1208 from @nmoinvaz adds a unit test and a "minideflate.c" and an "inflate.c" which I think is what you are looking for. No need to reinvent this particular wheel. |
Summary: Zlib (https://www.zlib.net/) has been updated to 1.2.12 due to CVE-2018-25032 - https://nvd.nist.gov/vuln/detail/CVE-2018-25032 - madler/zlib#605 The source .tar.gz is no longer available, and the Makefile for rocksdb now fails as a result. This PR updates the dependency to the newer (and available) version, 1.2.12 Pull Request resolved: #9764 Reviewed By: ajkr Differential Revision: D35220367 Pulled By: jay-zhuang fbshipit-source-id: 1f68ff8f048a6dba42077f048ac143468f0e2478
…#9764) Summary: Zlib (https://www.zlib.net/) has been updated to 1.2.12 due to CVE-2018-25032 - https://nvd.nist.gov/vuln/detail/CVE-2018-25032 - madler/zlib#605 The source .tar.gz is no longer available, and the Makefile for rocksdb now fails as a result. This PR updates the dependency to the newer (and available) version, 1.2.12 Pull Request resolved: facebook#9764 Reviewed By: ajkr Differential Revision: D35220367 Pulled By: jay-zhuang fbshipit-source-id: 1f68ff8f048a6dba42077f048ac143468f0e2478
Summary: Zlib (https://www.zlib.net/) has been updated to 1.2.12 due to CVE-2018-25032 - https://nvd.nist.gov/vuln/detail/CVE-2018-25032 - madler/zlib#605 The source .tar.gz is no longer available, and the Makefile for rocksdb now fails as a result. This PR updates the dependency to the newer (and available) version, 1.2.12 Pull Request resolved: facebook/rocksdb#9764 Reviewed By: ajkr Differential Revision: D35220367 Pulled By: jay-zhuang fbshipit-source-id: 1f68ff8f048a6dba42077f048ac143468f0e2478
Summary: Zlib (https://www.zlib.net/) has been updated to 1.2.12 due to CVE-2018-25032 - https://nvd.nist.gov/vuln/detail/CVE-2018-25032 - madler/zlib#605 The source .tar.gz is no longer available, and the Makefile for rocksdb now fails as a result. This PR updates the dependency to the newer (and available) version, 1.2.12 Pull Request resolved: facebook/rocksdb#9764 Reviewed By: ajkr Differential Revision: D35220367 Pulled By: jay-zhuang fbshipit-source-id: 1f68ff8f048a6dba42077f048ac143468f0e2478
CVE-2018-25032 tracks a bug in zlib 1.2.11 which allows memory corruption when deflating (i.e., when compressing) if the input has many distant matches.
There is a fix from @madler at 5c44459
@taviso reports at https://www.openwall.com/lists/oss-security/2022/03/24/1 that this patch never made it into a release, and at the time of writing no distros had picked it up as a fix.
The text was updated successfully, but these errors were encountered: