Skip to content

Various fixes - #6722

Merged
swick merged 46 commits into
flatpak:mainfrom
swick:wip/various-fixes-novuln
Jul 27, 2026
Merged

swick merged 46 commits into
flatpak:mainfrom
swick:wip/various-fixes-novuln

Conversation

@swick

@swick swick commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

All of those issues fell out of an LLM. I analyzed each issue, discarded a bunch, and either worked on, or at least verified the fixes.

swick added 16 commits June 30, 2026 16:33
This should be the case anyway right now and makes it easier to ensure
the code using it is correct.
It was accidentally parsed into the product union member but because it
has the same layout as the vendor one, this didn't turn into a bug in
practice, but it probably is UB.
Copy and paste error which results in the default and explicit usage of
--clear-env to be inverted.

Fixes: f760f1b ("run: Add --clear-env option for clearing the outside environment")
It also adds autofd cleanup and simplifies the control flow a bit.
This doesn't seem to happen in practice, but the API says it's possible,
so we better abort than run into weird states.
The code checked the wrong flags. struct_props is the array of child
properties, so struct_props->flags is the flags of the first child
property. What we need to chech is the flags of the current property,
and if it contains FLATPAK_JSON_PROP_FLAGS_STRICT.
We specifically have to avoid holding the lock while calling
flatpak_installation_get_dir_maybe_no_repo, so we just double check if
it is unset.
_ostree_object_name_equal() derived both refs from parameter a,
so any two objects in the same hash bucket were considered equal.
This caused g_hash_table_add() to evict previously inserted objects
on hash collision, shrinking the reachable set below its true size
and potentially pruning objects that are still in use.
@swick

swick commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

Not really sure who to ping for this. It's small changes all over the place. /cc @smcv @owtaylor @AdrianVovk @alexlarsson

@swick
swick force-pushed the wip/various-fixes-novuln branch 2 times, most recently from 99a8a60 to ce1b392 Compare June 30, 2026 22:01

@owtaylor owtaylor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's quite a pile of fixes!

Generally everything looks solid to me. Just a few places noted here where the fix isn't quite right (and a few more where a change seems unnecessary but harmless.)

Comment thread common/flatpak-repo-utils.c Outdated
Comment thread common/flatpak-image-collection.c Outdated
Comment thread common/flatpak-image-collection.c Outdated
Comment thread common/flatpak-run-wayland.c Outdated
Comment thread common/flatpak-dir.c
Comment thread common/flatpak-run.c Outdated
Comment thread common/flatpak-transaction.h
Comment thread common/flatpak-prune.c
Comment thread common/flatpak-xml-utils.c
Comment thread common/flatpak-exports.c
swick added 10 commits July 3, 2026 14:03
If max_len is 0, either data1_len or data2_len is 0, which means we
would add -1 to either data1 or data2, making them point one byte before
the object which is UB.

This commit just changes match_bytes_at_end and match_bytes_at_start to
use index based comparisons which makes the code easier and less likely
to invoke UB.
glib-mkenums fails to generate proper nicks and strips away th non- and
no-. Fix those cases manually.

Also fix the header guard while at it.

Technically this is an API break, but the API does exactly the opposite
of what it promises, so if anyone depended on this, we probably would
have received a bug report. Let's take the risk and just change it.
If we created an instance and we failed to get the PID of the instance,
we would still succeed. If one later calls flatpak_instance_is_running
or uses the result of flatpak_instance_get_pid with kill, it's possible
to terminate the entire process group (kill 0).

Let's just error out as early as possible to avoid those weird
half-initialized cases.

That unfortunately means we have to adjust a bunch of callers as well,
but fortunately, this only affects internal API.
If a negated true conditional (e.g. `!true`) is evaludated, it should
always be considered false. However, the code would not do that
(continue to the next conditional), but instead falls through to the
evaluator which grants the permission, because

    evaluator (condition) == !negated

... and the evaluator evaluates unknown conditions as false.
We would abort when the first conditional was already in the merged set
of conditionals.
If validation failed, we fall back to wayland-0, but we passed the
unvalidated name to flatpak_run_create_wayland_security_context.
swick added 20 commits July 3, 2026 14:19
The check tests sandbox_flags but the error message formatted
arg_flags, showing unrelated spawn flags instead of the actual
unsupported sandbox flags.
Both pid file writes silently ignored errors by passing NULL for
the GError. Log a warning so the failure is at least observable.
A symlink loop on the host filesystem would cause infinite recursion
and a stack overflow. Limit to 40 levels, matching the kernel's ELOOP
limit and the existing check in _exports_path_expose.
st_size is a 64-bit off_t but was truncated to gsize which is
32-bit on 32-bit platforms. A file larger than G_MAXSIZE - 1 would
cause size + 1 to overflow to 0, leading to a zero-size allocation
followed by an oversized read.
The setter used "summary-history-length" but the getter used
"sumary-history-length", so the configured value was never read
and the default was always used.
branch, commit, and app_path are read from the instance info key
file and could be NULL if the keys are missing. This would lead to
NULL dereferences in g_file_new_for_path, g_variant_new_string,
or printf %s. Fail early with an error instead.
g_subprocess_new can return NULL if the fusermount binary is not
found. The NULL was passed directly to g_subprocess_wait_check,
causing a NULL dereference.
Add the same early remote name validation (reject empty or containing
'/') that other D-Bus handlers already perform, for consistency. The
validation is not required for correctness or security but rejects
obviously invalid input at the entry point.
The warning for a failed g_file_monitor_file call used error->message
but the error was stored in local_error. If polkit succeeded, error
is NULL, causing a NULL dereference.
g_file_replace can return NULL on failure (e.g. disk full). The
result was passed to g_converter_output_stream_new before the NULL
check. Move the check before use.
g_file_equal returns TRUE when paths are equal, so the != 0 check
was triggering a reload when the path was unchanged and keeping the
stale cache when the path changed to a different file.
Handle NULL from g_key_file_get_string when a desktop file has no
Icon key, and from flatpak_dir_get_origin when deploy metadata is
missing or corrupted.
When bundle metadata validation fails after commit, the ref cleanup
via ostree_repo_set_ref_immediate could set error, then
flatpak_fail_error would try to set it again. Pass NULL for the
cleanup call since it's best-effort.
@swick
swick force-pushed the wip/various-fixes-novuln branch from ce1b392 to 80ec289 Compare July 3, 2026 12:21
@swick swick mentioned this pull request Jul 27, 2026
1 of 2 tasks
@swick
swick added this pull request to the merge queue Jul 27, 2026
Merged via the queue into flatpak:main with commit a6afa04 Jul 27, 2026
11 checks passed
@swick
swick deleted the wip/various-fixes-novuln branch July 27, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants