Skip to content
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

system-helper: Validate ref arg in RemoveLocalRef method #5048

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mwleeds
Copy link
Collaborator

@mwleeds mwleeds commented Aug 23, 2022

This patch could be important in case the ref arg was maliciously
crafted to try to convince flatpak-system-helper to delete an arbitrary
file on the filesystem. However, in practice (a) recent versions of
libostree will not accept such a ref name which has e.g. "../" in it
thanks to ostreedev/ostree#1286, and (b) even on
ancient versions of Flatpak that use a version of libostree without the
aforementioned patch, the exploit does not appear to be successful, at
least on Debian 9.

See GHSA-45jq-5658-v38x

This patch could be important in case the ref arg was maliciously
crafted to try to convince flatpak-system-helper to delete an arbitrary
file on the filesystem. However, in practice (a) recent versions of
libostree will not accept such a ref name which has e.g. "../" in it
thanks to ostreedev/ostree#1286, and (b) even on
ancient versions of Flatpak that use a version of libostree without the
aforementioned patch, the exploit does not appear to be successful, at
least on Debian 9.

See GHSA-45jq-5658-v38x
@mwleeds mwleeds added this to the 1.14.0 milestone Aug 23, 2022
@@ -1299,6 +1300,13 @@ handle_remove_local_ref (FlatpakSystemHelper *object,
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

ref = flatpak_decomposed_new_from_ref (arg_ref, &error);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately upon looking at this patch again a month later I think it's wrong, because it makes the RemoveLocalRef method error out when arg_ref does not begin with app/ or runtime/, but there's a note on the ref arg of flatpak_dir_remove_ref() which says /* NOTE: Not necessarily a app/runtime ref */, and that's because we sometimes remove other refs, e.g. appstream2/x86_64 or ostree-metadata.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flatpak_is_app_runtime_or_appstream_ref() helper would cover the cases where the ref has the prefix app/, runtime/, appstream/, or appstream2/. The only other possible refs I can think of are the deploy/ ones and ostree-metadata.

We could, instead of trying to make an exhaustive list of Flatpak ref patterns, use libostree's ostree_validate_rev, which would give us a little more flexibility to add ref patterns in the future without needing to update the list here.

In any case, I guess this patch needs to miss the boat for 1.14.0, since I'm trying to get that release out in time for Fedora 37 which has beta freeze tomorrow.

@mwleeds mwleeds modified the milestones: 1.14.0, 1.16.0 Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant