[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
Related show

Commit Message

H.J. Lu via Libc-alpha April 12, 2021, 9:11 p.m.
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(-)

-- 
2.27.0

Comments

Andreas Schwab April 14, 2021, 3 p.m. | #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.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

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);