From 136a5196266d03d537f822c4e67d2fde2ed59505 Mon Sep 17 00:00:00 2001 From: Sergiy Kibrik Date: Tue, 18 Aug 2015 09:28:39 +0300 Subject: [PATCH] ulog: avoid accidental /dev/kmsg creation Race is possible in ulog_kmsg(): if no /dev/kmsg exists (e.g. while /dev gets re-mounted) regular file created instead. >From this point system goes without kernel logger: special character file can't be created anymore, all clients keep overwriting single message in regular file. To avoid this we open file in "r+" mode which doesn't create file if it's not found. Signed-off-by: Sergiy Kibrik Cc: John Crispin --- ulog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ulog.c b/ulog.c index 66aad90..296605d 100644 --- a/ulog.c +++ b/ulog.c @@ -90,7 +90,7 @@ static void ulog_kmsg(int priority, const char *fmt, va_list ap) { FILE *kmsg; - if ((kmsg = fopen("/dev/kmsg", "w")) != NULL) { + if ((kmsg = fopen("/dev/kmsg", "r+")) != NULL) { fprintf(kmsg, "<%u>", priority); if (_ulog_ident) -- 2.11.0