From: Lennart Poettering Date: Thu, 9 Jun 2016 08:01:16 +0000 (+0200) Subject: execute: check whether the specified fd is a tty before chowning/chmoding it (#3457) X-Git-Tag: v231~199 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1ff74fb6e3243a2ade9ac38aa5effccb25432ad1;p=thirdparty%2Fsystemd.git execute: check whether the specified fd is a tty before chowning/chmoding it (#3457) Let's add an extra safety check before we chmod/chown a TTY to the right user, as we might end up having connected something to STDIN/STDOUT that is actually not a TTY, even though this might have been requested, due to permissive StandardInput= settings or transient service activation with fds passed in. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=85255 --- diff --git a/src/core/execute.c b/src/core/execute.c index 2cef70e6683..e718c43df9e 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -552,6 +552,10 @@ static int chown_terminal(int fd, uid_t uid) { assert(fd >= 0); + /* Before we chown/chmod the TTY, let's ensure this is actually a tty */ + if (isatty(fd) < 1) + return 0; + /* This might fail. What matters are the results. */ (void) fchown(fd, uid, -1); (void) fchmod(fd, TTY_MODE);