diff mbox series

[08/11] misc: syslog: Use CLOC_EXEC with _PATH_CONSOLE (BZ #17145)

Message ID 20210412211113.393120-8-adhemerval.zanella@linaro.org
State New
Headers show
Series [01/11] support: Add xmkfifo | expand

Commit Message

Adhemerval Zanella Netto April 12, 2021, 9:11 p.m. UTC
The syslog open the '/dev/console' for LOG_CONS without O_CLOEXEC,
which might leak in multithread programs that call fork.

Checked on x86_64-linux-gnu.
---
 misc/syslog.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Andreas Schwab April 14, 2021, 3 p.m. UTC | #1
On Apr 12 2021, Adhemerval Zanella via Libc-alpha wrote:

> The syslog open the '/dev/console' for LOG_CONS without O_CLOEXEC,
> which might leak in multithread programs that call fork.

Ok.

Andreas.
diff mbox series

Patch

diff --git a/misc/syslog.c b/misc/syslog.c
index a310eba476..b595889e1c 100644
--- a/misc/syslog.c
+++ b/misc/syslog.c
@@ -250,7 +250,8 @@  __vsyslog_internal (int pri, const char *fmt, va_list ap,
            */
           int fd;
           if (LogStat & LOG_CONS &&
-              (fd = __open (_PATH_CONSOLE, O_WRONLY | O_NOCTTY, 0)) >= 0)
+              (fd = __open (_PATH_CONSOLE, O_WRONLY | O_NOCTTY | O_CLOEXEC,
+                            0)) >= 0)
             {
               __dprintf (fd, "%s\r\n", buf + msgoff);
               __close (fd);