Update for CVE-2021-43860 and CVE-2022-21682

Bug #1957716 reported by Andrew Hayzen
256
This bug affects 1 person
Affects Status Importance Assigned to Milestone
flatpak (Ubuntu)
In Progress
Medium
Andrew Hayzen
Bionic
New
Medium
Unassigned
Focal
New
Medium
Unassigned
Impish
Won't Fix
Medium
Andrew Hayzen

Bug Description

[Links]
https://github.com/flatpak/flatpak/security/advisories/GHSA-qpjc-vq3c-572j ( CVE-2021-43860 )
https://security-tracker.debian.org/tracker/CVE-2021-43860

https://github.com/flatpak/flatpak/security/advisories/GHSA-8ch7-5j3h-g4fx ( CVE-2022-21682 )
https://security-tracker.debian.org/tracker/CVE-2022-21682

[Impact]
Versions in Ubuntu right now:
Jammy: 1.12.2-2
Impish: 1.10.2-3ubuntu0.1
Focal: 1.6.5-0ubuntu0.4
Bionic: 1.0.9-0ubuntu0.4

Affected versions:
    all

Patched versions:
    1.12.4, 1.10.7

[Test Case]
Unknown

[Regression Potential]
Flatpak has a test suite, which is run on build across all relevant architectures and passes.

There is also a manual test plan https://wiki.ubuntu.com/Process/Merges/TestPlan/flatpak .

Flatpak has autopkgtests enabled http://autopkgtest.ubuntu.com/packages/f/flatpak .

Regression potential is low, and upstream is very responsive to any issues raised.

[Patches]
The first CVE has 4 patches (+ 1 test patch), the second CVE has 1 patch (+ 6 doc/test patches).

[Other Information]

For the first advisory with the CVE:

Ryan Gonzalez discovered that Flatpak doesn't properly validate that the permissions displayed to the user for an app at install time match the actual permissions granted to the app at runtime, in the case that there's a null byte in the metadata file of an app. Therefore apps can grant themselves permissions without the consent of the user.

Flatpak shows permissions to the user during install by reading them from the "xa.metadata" key in the commit metadata. This cannot contain a null terminator, because it is an untrusted GVariant. Flatpak compares these permissions to the actual metadata, from the "metadata" file to ensure it wasn't lied to.

However, the actual metadata contents are loaded in several places where they are read as simple C-style strings. That means that, if the metadata file includes a null terminator, only the content of the file from before the terminator gets compared to xa.metadata. Thus, any permissions that appear in the metadata file after a null terminator are applied at runtime but not shown to the user. Maliciously crafted apps can use this to give themselves hidden permissions.

In addition, a similar weakness was discovered, where if the permissions in the summary metadata are invalid, they would not be displayed to the user, but the the actual permissions would be granted, even though it didn't match the invalid version.

For the second advisory:

flatpak-builder applies finish-args last in the build. At this point the build directory will have the full access that is specified in the manifest, so running flatpak build against it will gain that permissions. Normally this will not be done, so this is not problem. However, if --mirror-screenshots-url is specified, then flatpak-builder will launch flatpak build --nofilesystem=host appstream-utils mirror-screenshots after finalization, which can lead to issues even with the --nofilesystem=host protection.

There are two issues:

    --nofilesystem=host only overrides the access to the full host. The app can still request access to a specific directory, like --filesystem=~/some-dir, which is not affected by this.
    If a filesystem is specified like --filesystem=~/foobar:create, then that directory will be created before running the command.

In normal use the only issue is that these empty directories can be created wherever the user has write permissions. However, a malicious application could replace the appstream-util binary and potentially do something more hostile.

CVE References

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Can someone with permission add impish, focal, bionic as affected series? (hirsute i assume we can skip as it's about to EOL).

information type: Public → Public Security
Changed in flatpak (Ubuntu):
assignee: nobody → Andrew Hayzen (ahayzen)
Andrew Hayzen (ahayzen)
Changed in flatpak (Ubuntu):
status: New → In Progress
Revision history for this message
Simon McVittie (smcv) wrote :

The patches for CVE-2021-43860 (aka GHSA-qpjc-vq3c-572j) include some test-cases, which are run during build and as part of the autopkgtest.

There is currently no automated test coverage for GHSA-8ch7-5j3h-g4fx.

If possible I would recommend upgrading to 1.12.3 and 1.10.6, rather than backporting individual commits. The stable-branches are specifically there to be used by downstream distributions that want bugfix-only updates.

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Note that Jammy now has 1.12.3-1 so is fixed.

summary: - Update for CVE-2021-43860 and second github advisory
+ Update for CVE-2021-43860 and CVE-2022-21682
description: updated
Andrew Hayzen (ahayzen)
description: updated
Andrew Hayzen (ahayzen)
description: updated
Andrew Hayzen (ahayzen)
Changed in flatpak (Ubuntu Impish):
status: New → In Progress
assignee: nobody → Andrew Hayzen (ahayzen)
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Please find attached the debdiff for Ubuntu 21.10 impish. I have performed some testing in a VM and built in a PPA.

Mathew Hodson (mhodson)
Changed in flatpak (Ubuntu):
importance: Undecided → Medium
Changed in flatpak (Ubuntu Bionic):
importance: Undecided → Medium
Changed in flatpak (Ubuntu Focal):
importance: Undecided → Medium
Changed in flatpak (Ubuntu Impish):
importance: Undecided → Medium
Revision history for this message
Alex Murray (alexmurray) wrote :

@ahayzen - thanks for the impish debdiff - I was going to sponsor it but I notice you have used a separate set of patches than those linked to by debian and NVD for CVE-2022-21682 - does this also need:

https://github.com/flatpak/flatpak/commit/445bddeee657fdc8d2a0a1f0de12975400d4fc1a ?

Also does this need an update for flatpak-builder too? Thanks.

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

@alexmurray, hey, I believe that commit was reverted later as it caused a behavioural regression? The Github advisory (https://github.com/flatpak/flatpak/security/advisories/GHSA-8ch7-5j3h-g4fx) was changed to point to a different commit (https://github.com/flatpak/flatpak/commit/5709f1aaed6579f0136976e14e7f3cae399134ca).

When creating that debdiff, if i recall correctly I went though the commits in this branch https://github.com/flatpak/flatpak/commits/flatpak-1.10.x combined with referring to the github advisories and then skipped the "Make --nofilesystem=host/home remove access to subdirs of those" (307ee18dd62f65c1319594501d01bbdb10f88ab8) as it was reverted later with "Revert "Make --nofilesystem=host/home remove access to subdirs of those"" (ed91bba615d4e50ccd7de53ca9861e367175bbfb).

Please correct me if you think i've missed something :-)

In the github advisory (https://github.com/flatpak/flatpak/security/advisories/GHSA-8ch7-5j3h-g4fx) there are two commits for flatpak-builder so this could also be done.

Also note I tried looking at focal/bionic but there are a large amount of merge conflicts due to substantial change in the codebase and I'm not familiar enough with GObject/GLib etc to rewrite that code.

Revision history for this message
Brian Murray (brian-murray) wrote :

Ubuntu 21.10 (Impish Indri) has reached end of life, so this bug will not be fixed for that specific release.

Changed in flatpak (Ubuntu Impish):
status: In Progress → Won't Fix
Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

Unsubscribing ubuntu-security-sponsors for now as there is no other debdiff to sponsor. Thanks!

To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.