Skip to content

Commit

Permalink
[fix] raise swhkd privileges right after reading config
Browse files Browse the repository at this point in the history
As a fix for CVE-2022-27814, root privileges are dropped to the calling user
when (re)loading the config file. Privileges were sometimes dropped but never
raised again, which caused crashes when sending SIGHUP to swhkd multiple times
in a row.

This now always raises privileges after successfully reading the config file.
Fixes #155.
  • Loading branch information
ajanon authored and Shinyzenith committed Oct 6, 2022
1 parent ad687ef commit 36281fe
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions swhkd/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
log::error!("Config Error: {}", e);
exit(1)
}
Ok(out) => out,
Ok(out) => {
// Escalate back to the root user after reading the config file.
perms::raise_privileges();
out
}
}
};

Expand Down Expand Up @@ -135,9 +139,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
};
}

// Escalate back to the root user after reading the config file.
perms::raise_privileges();

let keyboard_devices: Vec<Device> = {
if let Some(arg_devices) = args.values_of("device") {
// for device in arg_devices {
Expand Down

0 comments on commit 36281fe

Please sign in to comment.