From: Zbigniew Jędrzejewski-Szmek Date: Sun, 8 May 2022 15:21:09 +0000 (+0200) Subject: logind: fix crash in logind on user-specified message string X-Git-Tag: v251-rc3~14^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0cb09bcb825ab86ba4ca70be4e6322eaf9baee95;p=thirdparty%2Fsystemd.git logind: fix crash in logind on user-specified message string This is trivially exploitable (in the sense of causing a crash from SEGV) e.g. by 'shutdown now "Message %s %s %n"'. The message is settable through polkit, but is limited to auth_admin: Set a wall message Authentication is required to set a wall message auth_admin_keep auth_admin_keep auth_admin_keep Bug introduced in 9ef15026c0e7e6600372056c43442c99ec53746e ('logind/systemctl: introduce SetWallMessage and --message', 2015-09-15). --- diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 914e56bd776..5c17d4ec042 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1515,32 +1515,20 @@ static int have_multiple_sessions( static int bus_manager_log_shutdown( Manager *m, const HandleActionData *a) { - - const char *message, *log_message; - assert(m); assert(a); - message = a->message; - log_message = a->log_message; - - if (message) - message = strjoina("MESSAGE=", message); - else - message = "MESSAGE=System is shutting down"; - - if (isempty(m->wall_message)) - message = strjoina(message, "."); - else - message = strjoina(message, " (", m->wall_message, ")."); - - if (log_message) - log_message = strjoina("SHUTDOWN=", log_message); + const char *message = a->message ?: "System is shutting down"; + const char *log_message = a->log_message ? strjoina("SHUTDOWN=", a->log_message) : NULL; return log_struct(LOG_NOTICE, - "MESSAGE_ID=%s", a->message_id ? a->message_id : SD_MESSAGE_SHUTDOWN_STR, - message, - log_message); + "MESSAGE_ID=%s", a->message_id ?: SD_MESSAGE_SHUTDOWN_STR, + LOG_MESSAGE("%s%s%s%s.", + message, + m->wall_message ? " (" : "", + strempty(m->wall_message), + m->wall_message ? ")" : ""), + log_message); } static int lid_switch_ignore_handler(sd_event_source *e, uint64_t usec, void *userdata) {