Skip to content

glib: fix UB in VariantStrIter::impl_get#1343

Merged
sdroege merged 1 commit intogtk-rs:masterfrom
decathorpe:master
Mar 30, 2024
Merged

glib: fix UB in VariantStrIter::impl_get#1343
sdroege merged 1 commit intogtk-rs:masterfrom
decathorpe:master

Conversation

@decathorpe
Copy link
Copy Markdown
Contributor

Passing an immutable reference (&p) to a function that mutates the data behind the pointer violates Rust's invariants.

This causes multiple tests in the test suite to crash when compiling it with optimizations (either --release mode or with opt-level of 2 or 3) with recent Rust versions, which is easy to reproduce, especially with nightly Rust:

$ cargo +nightly test --release --package glib
(...)
error: test failed, to rerun pass `--lib`
Caused by:
  process didn't exit successfully: (...) (signal: 11, SIGSEGV: invalid memory reference)

Looks like this wasn't caught earlier because the wrapped C function is variadic and there's less type checking happening because of that.

Passing an immutable reference (&p) to a function that mutates the
data behind the pointer violates Rust's invariants.
@sdroege sdroege merged commit 05dff0e into gtk-rs:master Mar 30, 2024
@sdroege sdroege added the needs-backport PR needs backporting to the current stable branch label Mar 30, 2024
@sdroege
Copy link
Copy Markdown
Member

sdroege commented Mar 30, 2024

Thanks!

@pbor pbor added backported PR was backported to the current stable branch and removed needs-backport PR needs backporting to the current stable branch labels Jun 17, 2024
ggrossman added a commit to Quickture/gtk-rs-core that referenced this pull request Jan 18, 2026
Change impl_get to use mutable reference for pointer parameter.

The g_variant_get_child C function mutates the pointer passed as an
out-parameter. Passing an immutable reference (&p) is unsound because
it violates Rust's aliasing rules. With recent compiler optimizations,
these unsound writes were being ignored, causing NULL pointer
dereferences when the iterator was used.

Fix: Change 'let p' to 'let mut p' and pass '&mut p' instead of '&p'
to g_variant_get_child.

This backports the fix from gtk-rs-core PR gtk-rs#1343 to the 0.18 branch.

Fixes: https://rustsec.org/advisories/RUSTSEC-2024-0429
Upstream-Fix: gtk-rs#1343
ggrossman added a commit to Quickture/gtk-rs-core that referenced this pull request Jan 18, 2026
The RUSTSEC advisory specifies that patched versions are >= 0.20.0.
While this is based on glib 0.18.5, it includes the fix from PR gtk-rs#1343
backported from 0.20.0. Bumping the version number allows vulnerability
scanners to correctly identify this as patched.

This is a Quickture-specific change to satisfy Oneleet's version-based
vulnerability scanning.
doublegate added a commit to doublegate/SPECTRE that referenced this pull request Feb 6, 2026
Add comprehensive documentation for glib unsoundness vulnerability affecting
Linux GUI builds. This is an accepted risk due to upstream Tauri dependencies.

Changes:
- SECURITY.md: Added "Known Limitations" section with detailed analysis
- CHANGELOG.md: Documented the security advisory in [Unreleased] section

Advisory Details:
- ID: GHSA-wrw7-89jp-8q8g / RUSTSEC-2024-0429
- Severity: Medium (CVSS 6.9)
- Component: glib v0.18.5 (via Tauri 2.10.2 → GTK3)
- Platform: Linux only (macOS/Windows unaffected)
- Impact: LOW exploitability - crashes rather than RCE

Root Cause:
- Tauri 2.10.2 depends on webkit2gtk v2.0.2
- webkit2gtk v2.0.2 requires GTK3 (gtk v0.18.2, UNMAINTAINED)
- GTK3 bindings locked to glib v0.18.x (vulnerable versions: 0.15.0-0.19.x)
- Fix requires glib v0.20.0+ which needs GTK4 migration

Fix Status:
- Cannot upgrade glib without breaking GTK3 dependencies
- GTK4 migration requires Tauri v3 (in development)
- Monitoring: tauri-apps/tauri#7335

Mitigation:
- CLI/TUI interfaces unaffected (no GTK dependencies)
- GUI code path doesn't directly use vulnerable VariantStrIter
- Users advised to use CLI/TUI for mission-critical operations

References:
- GitHub Advisory: GHSA-wrw7-89jp-8q8g
- RustSec: https://rustsec.org/advisories/RUSTSEC-2024-0429
- Fix PR: gtk-rs/gtk-rs-core#1343
- Tauri Issue: tauri-apps/tauri#12048

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
bb111189 added a commit to jiayaoqijia/ClawSecurity that referenced this pull request Feb 12, 2026
…nsoundness)

Use [patch.crates-io] to redirect glib to alt-research/gtk-rs-core
0.18-patched branch, which backports the fix from gtk-rs/gtk-rs-core#1343.

Upstream only patched glib >= 0.20.0, but Tauri 2.x depends on the
gtk-rs 0.18.x ecosystem. The fix is a two-line change (immutable to
mutable reference in VariantStrIter::impl_get).
tidynest added a commit to tidynest/gtk-rs-core that referenced this pull request Apr 7, 2026
Pass pointer as &mut p instead of &p to g_variant_get_child to fix
undefined behaviour that causes NULL pointer dereferences with
optimized builds on recent Rust compilers.

Backport of gtk-rs#1343 to the 0.18 branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported PR was backported to the current stable branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants