From 85afeae88c59ce3e6fb534facbcc6fc819f95a0f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 29 Dec 2017 18:13:38 +0100 Subject: [PATCH] pager,agent: insist that we are called from the main thread We maintain static process-wide variables in these subsystems without locking, hence let's refuse operation unless we are called from the main thread (which we do anyway) just as a safety precaution. --- src/shared/pager.c | 3 +++ src/shared/spawn-ask-password-agent.c | 3 +++ src/shared/spawn-polkit-agent.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/shared/pager.c b/src/shared/pager.c index 18c8f6c18c3..d26fa0e6fbe 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -73,6 +73,9 @@ int pager_open(bool no_pager, bool jump_to_end) { if (terminal_is_dumb()) return 0; + if (!is_main_thread()) + return -EPERM; + pager = getenv("SYSTEMD_PAGER"); if (!pager) pager = getenv("PAGER"); diff --git a/src/shared/spawn-ask-password-agent.c b/src/shared/spawn-ask-password-agent.c index 17785fd1537..f78167c25c9 100644 --- a/src/shared/spawn-ask-password-agent.c +++ b/src/shared/spawn-ask-password-agent.c @@ -40,6 +40,9 @@ int ask_password_agent_open(void) { if (!isatty(STDIN_FILENO)) return 0; + if (!is_main_thread()) + return -EPERM; + r = fork_agent("(sd-askpwagent)", NULL, 0, &agent_pid, diff --git a/src/shared/spawn-polkit-agent.c b/src/shared/spawn-polkit-agent.c index 886248b9f97..3c93c79cebd 100644 --- a/src/shared/spawn-polkit-agent.c +++ b/src/shared/spawn-polkit-agent.c @@ -52,6 +52,9 @@ int polkit_agent_open(void) { if (!isatty(STDIN_FILENO)) return 0; + if (!is_main_thread()) + return -EPERM; + if (pipe2(pipe_fd, 0) < 0) return -errno; -- 2.47.3