Possible arbitrary file leak
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
imagemagick (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
More details can be found here:
https:/
Affected versions:
Injection via "-authenticate"
- ImageMagick 6: 6.9.8-1 up to 6.9.11-40
Explotation via MSL:
-ImageMagick 6: 6.9.11-35 up to 6.9.11-40
CVE References
information type: | Private Security → Public Security |
Changed in imagemagick (Ubuntu): | |
status: | New → Confirmed |
David Zuelke (dzuelke) wrote : | #1 |
David Zuelke (dzuelke) wrote : | #2 |
Any news here? Marc Deslauriers committed a fix for bionic on Feb 9 (https:/
Debian have classified this as severity "grave": https:/
I agree with this. It's trivially exploited using a crafted PNG. Every Ruby on Rails app, for example, shells out to `convert` out of the box for image resizing. It's a very standard use case.
Debian have also fixed it in bullseye (= same version as on jammy), only buster (= same version as on focal) remains unpatched.
David Zuelke (dzuelke) wrote : | #3 |
The fix committed to bionic applies cleanly to focal:
ubuntu-imagemagick % git checkout origin/
Previous HEAD position was 9d9d88c18 8:6.9.7.
HEAD is now at d5cfbaeb8 8:6.9.10.
ubuntu-imagemagick % git cherry-pick ff63fb0005ef2b9
Auto-merging coders/png.c
[detached HEAD 0d1b05180] [PATCH] possible DoS @ stdin (OCE-2022-70); possible arbitrary file
Author: Marc Deslauriers <email address hidden>
Date: Thu Feb 9 12:11:42 2023 -0500
1 file changed, 13 insertions(+), 2 deletions(-)
For jammy, the upstream commit (https:/
ubuntu-imagemagick % git checkout origin/
Previous HEAD position was d5cfbaeb8 8:6.9.10.
HEAD is now at bc5d3ac18 8:6.9.11.
ubuntu-imagemagick % curl -s https:/
patching file 'magick/property.c'
Reversed (or previously applied) patch detected! Assume -R? [y] n
Apply anyway? [n] y
1 out of 1 hunks failed--saving rejects to 'magick/
patching file 'wand/mogrify.c'
David Zuelke (dzuelke) wrote : | #4 |
Jammy needs a few more commits from upstream for a clean apply:
ubuntu-imagemagick % git checkout origin/
Previous HEAD position was d5cfbaeb8 8:6.9.10.
HEAD is now at bc5d3ac18 8:6.9.11.
ubuntu-imagemagick % curl -s https:/
patching file 'magick/property.c'
patching file 'magick/property.c'
patching file 'magick/property.c'
patching file 'magick/property.c'
patching file 'wand/mogrify.c'
This then also includes https:/
At this point I am not sure if the fix applied to bionic (https:/
It appears like https:/
David Zuelke (dzuelke) wrote : | #5 |
So I think this was originally (for OCE-2022-77) fixed with these commits:
https:/
https:/
And then, probably more fully, with these commits, of which I've seen d77...763 referenced in various places that discuss CVE-2022-44267 and CVE-2022-44268:
https:/
https:/
https:/
https:/
https:/
Could also just be a refactor, but e.g. Debian seems to have applied both fix chunks.
Seth Arnold (seth-arnold) wrote : Re: [Bug 2004580] Re: Possible arbitrary file leak | #6 |
On Mon, Feb 27, 2023 at 12:52:15PM -0000, David Zuelke wrote:
> I agree with this. It's trivially exploited using a crafted PNG. Every
> Ruby on Rails app, for example, shells out to `convert` out of the box
> for image resizing. It's a very standard use case.
Unfortunately this is not a new situation for ImageMagick:
https:/
"Total number of vulnerabilities : 630"
If you've built your applications to accept untrusted inputs from users
and then hand it to ImageMagick for processing, I strongly recommend that
you take steps to secure your environment:
- confine the application with an AppArmor profile
- confine the application with a seccomp profile
- run it as a user with very limited write permissions
- configure rlimits or cgroups on the service to prevent it from consuming
excessive resources
- configure the networking stack to limit what network resources can be
reached
ImageMagick is incredibly powerful software but it's also got a long
history of not being suitable for untrusted inputs.
I expect we'll address these CVEs sooner or later but it's important
that everyone who builds applications with ImageMagick understand the
risks and take appropriate actions to mitigate against exploits. This
is true of all software but especially important for ImageMagick.
Thanks
David Zuelke (dzuelke) wrote : | #7 |
You're of course correct in principle, but the trouble here is that this is a vulnerability that's very hard to counter using OS limits/profiles or ImageMagick profiles, because you need to write user input to some location on the file system in order to process it, and so at least that file system location is automatically vulnerable to exfiltration, because the ImageMagick process must be allowed to read it to load the uploaded image.
On top of that, I for instance work for a platform provider where we can't even know ahead of time what filesystem location a customer's code (or the library/framework they're using) will use for e.g. uploaded file storage - is it /tmp, is it somewhere else - so it's not feasible to lock down paths using an ImageMagick policy in a way that doesn't break countless existing customers.
Launchpad Janitor (janitor) wrote : | #8 |
This bug was fixed in the package imagemagick - 8:6.9.11.
---------------
imagemagick (8:6.9.
* SECURITY UPDATE: Denial of Service
- debian/
2022-70); possible arbitrary file leak (OCE-2022-72) (LP: #2004580)
- CVE-2022-44267
* SECURITY UPDATE: Information Disclosure
- debian/
- CVE-2022-44268
-- Paulo Flabiano Smorigo <email address hidden> Fri, 24 Feb 2023 11:21:38 -0300
Changed in imagemagick (Ubuntu): | |
status: | Confirmed → Fix Released |
Launchpad Janitor (janitor) wrote : | #9 |
This bug was fixed in the package imagemagick - 8:6.9.11.
---------------
imagemagick (8:6.9.
* SECURITY UPDATE: Denial of Service
- debian/
2022-70); possible arbitrary file leak (OCE-2022-72) (LP: #2004580)
- CVE-2022-44267
* SECURITY UPDATE: Information Disclosure
- debian/
- CVE-2022-44268
-- Paulo Flabiano Smorigo <email address hidden> Fri, 24 Feb 2023 11:40:25 -0300
Changed in imagemagick (Ubuntu): | |
status: | Confirmed → Fix Released |
Launchpad Janitor (janitor) wrote : | #10 |
This bug was fixed in the package imagemagick - 8:6.9.10.
---------------
imagemagick (8:6.9.
* SECURITY UPDATE: Information Disclosure
- debian/
(LP: #2004580)
- CVE-2022-44268
-- Paulo Flabiano Smorigo <email address hidden> Fri, 24 Feb 2023 11:47:55 -0300
Changed in imagemagick (Ubuntu): | |
status: | Confirmed → Fix Released |
Paulo Flabiano Smorigo (pfsmorigo) wrote : | #11 |
Hello David Zuelke (dzuelke), I saw your updates in the LP only today after I published the new release. I think I backported all required fixes for both CVE-2022-44267 and CVE-2022-44268. Can you check if everything was fixed correctly? I'm ok to add new fixes if necessary.
David Zuelke (dzuelke) wrote : | #12 |
Hi Paulo Flabiano Smorigo (pfsmorigo),
alright so, I looked at it for jammy, focal and bionic.
First, jammy (I guess kinetic too?) has missing commits. The contents of CVE-44267.patch should be undone by CVE-44268.patch; this line remains in the source but has been removed upstream in the improved/refactored fix for the vulnerability:
+ (LocaleCompare(
And at least one code formatting commit (e.g. the last one in the list below) is also not there, might be useful for the future, as it would allow patches for the same piece of code to apply more cleanly, should there be the need for another backport.
If you take the jammy sources and apply all the existing patches except the last two CVE-2022-*, you can then simply apply all the commits from upstream in sequence:
(original fix)
https:/
https:/
(improved or refactored fix)
https:/
https:/
https:/
https:/
https:/
They apply cleanly:
curl -s https:/
I'd either put them into two patch files (first two commits in one, the rest in the others), or all into one. Right now, CVE-44267.patch contains just one of the two commits necessary for the original mitigation, so applying only that results in half-fixed and possibly broken code until CVE-44268.patch is also applied.
Second, focal, there is now an anomaly in the code that makes it behave differently. The bionic and jammy versions, when fed an exploiting PNG, will just ignore the exploit.
Focal however, while no longer vulnerable in that it exfiltrates the file to the headers, now returns the "profile" field with the value that the attacker fed in:
# convert exfiltrate-
…
png:text: 3 tEXt/zTXt/iTXt chunks were found
png:tIME: 2023-02-
png:tRNS: chunk was found
profile: /etc/hosts
signature: e7e2dcff542de95
Paulo Flabiano Smorigo (pfsmorigo) wrote : | #13 |
For jammy and kinetic, I renamed the patch files as a sequence and added an additional mitigation from Debian. There is no patch missing from your list, I did a diff after applying all changes and the result is the same of your command. No missing patch left.
For focal I also rename the patch, changed as you suggested, and add the additional mitigation too.
The new packages are available at:
https:/
Can you check if it's ok? About the POC, please send to my email that it's included in the changelog, please? I'll add it to the integrated tests we do for the package.
Greg Whiteley (greg-whiteley) wrote : | #14 |
On focal the patch for this (or the repackaging thereof) in 8:6.9.10.
David Zuelke (dzuelke) wrote : | #15 |
Okay, this needs immediate reverting, Paulo - CVE-2022-
See bug https:/
This "mitigation" should not have been added. My PoC PNG file exfiltrated /etc/hosts, but it could just as well have been /var/log/syslog, or /usr/local/
I am attaching corrected and cleaned up patches for focal and jammy, split into two parts the way I initially proposed.
(Your focal patch files are named ..._1.patch and ...-2.patch, FYI).
David Zuelke (dzuelke) wrote : | #16 |
David Zuelke (dzuelke) wrote : | #17 |
David Zuelke (dzuelke) wrote : | #18 |
David Zuelke (dzuelke) wrote : | #19 |
David Zuelke (dzuelke) wrote : | #20 |
(You can of course also combine the two patch files into one; up to you)
Paulo Flabiano Smorigo (pfsmorigo) wrote : | #21 |
Thanks for the heads up!
So I removed the additional mitigation for all affected releases and compare your patches with the ones in the package.
For focal, there were no changes, just indentations and line breaks as you can see here:
https:/
For jammy and kinetic, there were two lines that I modified to be exactly as yours.
The new releases are building in proposed and will be published after some testing:
https:/
David Zuelke (dzuelke) wrote : | #22 |
Cool, thanks.
Yeah I ported the newline and indentation changes as well, to potentially allow future patches to apply more cleanly, but it's a detail (you also have some tab-based indentation mixed with spaces).
Thanks for addressing this quickly!
This affects 20.04 and 22.04. It's fixed in 18.04 already, as https:/ /ubuntu. com/security/ CVE-2022- 44268 mentions.