]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
fix log appending to any file
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Tue, 20 Jul 2010 11:45:44 +0000 (13:45 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Tue, 20 Jul 2010 11:45:44 +0000 (13:45 +0200)
With the capabilities, the open of the log file can be done on any
file, making possible to modifify the content of the file.

Let's drop the privilege when opening the file, so we ensure that is
no longer possible.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/log.c

index 596ed990092a26ab2910bbdec68e3c6f88d14d51..0661360a47d149ddc27bc222866e0c0962ed9a5d 100644 (file)
@@ -33,7 +33,8 @@
 #include <fcntl.h>
 #include <stdlib.h>
 
-#include <lxc/log.h>
+#include "log.h"
+#include "caps.h"
 
 #define LXC_LOG_PREFIX_SIZE    32
 #define LXC_LOG_BUFFER_SIZE    512
@@ -127,7 +128,8 @@ static int log_open(const char *name)
        int fd;
        int newfd;
 
-       fd = open(name, O_CREAT | O_WRONLY | O_APPEND | O_CLOEXEC, 0666);
+       fd = lxc_unpriv(open(name, O_CREAT | O_WRONLY |
+                            O_APPEND | O_CLOEXEC, 0666));
        if (fd == -1) {
                ERROR("failed to open log file \"%s\" : %s", name,
                      strerror(errno));