diff --git a/BUILDING.md b/BUILDING.md index e5ec3c78..57ce45f2 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -149,6 +149,14 @@ meson setup -Dprofile=development build ninja -C build ``` +credentialsd-ui disables core dumps for itself, because it handles the PINs +that users type. To debug a crash in the UI, turn core dumps back on: + +``` +meson configure -Denable_core_dumps=true build +ninja -C build +``` + ## Building patched xdg-desktop-portal For more context on the patch, see the [instructions above](#installing-credentialsd-and-credentialsd-ui). @@ -209,6 +217,10 @@ cargo_locked false [True, False] Whether cargo_offline false [True, False] Whether to perform an offline build with Cargo. Defaults to false to download crates from registries. +enable_core_dumps false [True, False] Allow credentialsd-ui to write core dumps, + for debugging crashes. Defaults to false + because the UI handles PINs typed by the + user. feature_daemon enabled [enabled, disabled, Whether to build the credentialsd daemon auto] feature_demo_client auto [enabled, disabled, Whether to build the demo client diff --git a/CHANGELOG.md b/CHANGELOG.md index 76488bcd..491d652c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - daemon: Build the list of devices offered to the user from libwebauthn's `available_transports()`, the same source discovery uses (#32) - ui: Pass the caller's activation token to the compositor when showing the dialog, so it can take focus when the requesting window is in the background (#152) +- ui: Disable core dumps for the UI process, which handles typed PINs. Build with `-Denable_core_dumps=true` to allow them for debugging (#209) # 0.4.0 [2026-11-05] diff --git a/Cargo.lock b/Cargo.lock index eb5bdd6e..c28837ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -841,6 +841,7 @@ dependencies = [ "gettext-rs", "gio-unix", "gtk4", + "libc", "qrcode", "serde", "tracing", diff --git a/credentialsd-ui/Cargo.toml b/credentialsd-ui/Cargo.toml index 333464a6..b6d47a3f 100644 --- a/credentialsd-ui/Cargo.toml +++ b/credentialsd-ui/Cargo.toml @@ -13,6 +13,7 @@ wayland = ["gdk-wayland"] credentialsd-common = { path = "../credentialsd-common" } futures-lite.workspace = true +libc.workspace = true serde.workspace = true tracing.workspace = true tracing-subscriber.workspace = true diff --git a/credentialsd-ui/src/config.rs.in b/credentialsd-ui/src/config.rs.in index 699897f0..e5cd3669 100644 --- a/credentialsd-ui/src/config.rs.in +++ b/credentialsd-ui/src/config.rs.in @@ -1,4 +1,5 @@ pub const APP_ID: &str = @APP_ID@; +pub const ENABLE_CORE_DUMPS: bool = @ENABLE_CORE_DUMPS@; pub const GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@; pub const LOCALEDIR: &str = @LOCALEDIR@; pub const PKGDATADIR: &str = @PKGDATADIR@; diff --git a/credentialsd-ui/src/hardening.rs b/credentialsd-ui/src/hardening.rs new file mode 100644 index 00000000..d06ab854 --- /dev/null +++ b/credentialsd-ui/src/hardening.rs @@ -0,0 +1,39 @@ +//! Process-level protections for the UI, which handles PINs typed by the user. + +use std::io; + +/// Sets the core dump size limit to zero, both soft and hard, so the kernel +/// and systemd-coredump write no core dump for this process. +/// +/// `prctl(PR_SET_DUMPABLE, 0)` would additionally block same-user ptrace, but +/// it also makes `/proc//root` unreadable to xdg-desktop-portal, which +/// then rejects every portal call from this process, including the Settings +/// portal GTK uses for the colour scheme. Ptrace protection is left to Yama. +pub(crate) fn disable_core_dumps() -> io::Result<()> { + let limit = libc::rlimit { + rlim_cur: 0, + rlim_max: 0, + }; + // SAFETY: `limit` is a valid rlimit that outlives the call. + if unsafe { libc::setrlimit(libc::RLIMIT_CORE, &limit) } != 0 { + return Err(io::Error::last_os_error()); + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn core_limit_is_zero_afterwards() { + disable_core_dumps().unwrap(); + let mut limit = libc::rlimit { + rlim_cur: 1, + rlim_max: 1, + }; + // SAFETY: `limit` is a valid, writable rlimit. + assert_eq!(unsafe { libc::getrlimit(libc::RLIMIT_CORE, &mut limit) }, 0); + assert_eq!((limit.rlim_cur, limit.rlim_max), (0, 0)); + } +} diff --git a/credentialsd-ui/src/main.rs b/credentialsd-ui/src/main.rs index 2abe091c..ed1fb4da 100644 --- a/credentialsd-ui/src/main.rs +++ b/credentialsd-ui/src/main.rs @@ -3,6 +3,7 @@ mod client; mod config; mod dbus; mod gui; +mod hardening; use std::error::Error; @@ -13,6 +14,12 @@ use crate::dbus::CredentialPortalBackend; fn main() -> Result<(), Box> { tracing_subscriber::fmt::init(); + // Keep typed PINs out of core dumps. + if config::ENABLE_CORE_DUMPS { + tracing::info!("Core dumps are enabled by the enable_core_dumps build option"); + } else if let Err(err) = hardening::disable_core_dumps() { + tracing::warn!(%err, "Failed to disable core dumps"); + } tracing::debug!("Starting credentials UI service"); async_std::task::block_on(run()) } diff --git a/credentialsd-ui/src/meson.build b/credentialsd-ui/src/meson.build index f6a0a448..ac7d984f 100644 --- a/credentialsd-ui/src/meson.build +++ b/credentialsd-ui/src/meson.build @@ -19,6 +19,7 @@ endif global_conf.set_quoted('PROFILE', profile) global_conf.set_quoted('VERSION', version + version_suffix) global_conf.set_quoted('GETTEXT_PACKAGE', gettext_package) +global_conf.set('ENABLE_CORE_DUMPS', get_option('enable_core_dumps').to_string()) configure_file(input: 'config.rs.in', output: 'config.rs', configuration: global_conf) # Copy the config.rs output to the source directory. diff --git a/meson.options b/meson.options index 8eb15023..b6d6c226 100644 --- a/meson.options +++ b/meson.options @@ -24,6 +24,12 @@ option( value: false, description: 'Whether to perform an offline build with Cargo. Defaults to false to download crates from registries.', ) +option( + 'enable_core_dumps', + type: 'boolean', + value: false, + description: 'Allow credentialsd-ui to write core dumps, for debugging crashes. Defaults to false because the UI handles PINs typed by the user.', +) # Features option(