]> git.proxmox.com Git - mirror_lxc.git/commitdiff
fixup i/o handler return values
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 27 Mar 2020 13:15:12 +0000 (14:15 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Mar 2020 14:45:11 +0000 (15:45 +0100)
Particularly important for lxc_cmd_handler() handles client
input and should not be capable of canceling the main loop,
some syscall return values leaked through overlapping with
LXC_MAINLOOP_ERROR, causing unauthorized clients connecting
to the command socket to shutdown the main loop.

In turn, signal_handler() receiving unexpected
`signalfd_siginfo` struct sizes seems like a reason to bail
(since it's a kernel interface).

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/commands.c
src/lxc/seccomp.c
src/lxc/start.c

index 20890a719a46f2abcc04ef6c854c495d424a6f9a..8b2d0e0b7ab1fc020379bd377546b4af72fb30c7 100644 (file)
@@ -1450,7 +1450,7 @@ static int lxc_cmd_handler(int fd, uint32_t events, void *data,
                if (errno == EACCES) {
                        /* We don't care for the peer, just send and close. */
                        struct lxc_cmd_rsp rsp = {
-                               .ret = ret,
+                               .ret = -EPERM,
                        };
 
                        lxc_cmd_rsp_send(fd, &rsp);
@@ -1464,14 +1464,11 @@ static int lxc_cmd_handler(int fd, uint32_t events, void *data,
 
        if (ret != sizeof(req)) {
                WARN("Failed to receive full command request. Ignoring request for \"%s\"", lxc_cmd_str(req.cmd));
-               ret = -1;
                goto out_close;
        }
 
        if ((req.datalen > LXC_CMD_DATA_MAX) && (req.cmd != LXC_CMD_CONSOLE_LOG)) {
                ERROR("Received command data length %d is too large for command \"%s\"", req.datalen, lxc_cmd_str(req.cmd));
-               errno = EFBIG;
-               ret = -EFBIG;
                goto out_close;
        }
 
@@ -1480,7 +1477,6 @@ static int lxc_cmd_handler(int fd, uint32_t events, void *data,
                ret = lxc_recv_nointr(fd, reqdata, req.datalen, 0);
                if (ret != req.datalen) {
                        WARN("Failed to receive full command request. Ignoring request for \"%s\"", lxc_cmd_str(req.cmd));
-                       ret = LXC_MAINLOOP_ERROR;
                        goto out_close;
                }
 
@@ -1490,12 +1486,11 @@ static int lxc_cmd_handler(int fd, uint32_t events, void *data,
        ret = lxc_cmd_process(fd, &req, handler, descr);
        if (ret) {
                /* This is not an error, but only a request to close fd. */
-               ret = LXC_MAINLOOP_CONTINUE;
                goto out_close;
        }
 
 out:
-       return ret;
+       return LXC_MAINLOOP_CONTINUE;
 
 out_close:
        lxc_cmd_fd_cleanup(fd, handler, descr, req.cmd);
index 916b1aa1a8be9c0c01dcc70e9b675ea081c0a541..081d315ab53e1d776af2a92d4569ef5806b254d5 100644 (file)
@@ -1478,10 +1478,8 @@ retry:
                SYSERROR("Failed to send seccomp notification");
 
 out:
-       return 0;
-#else
-       return -ENOSYS;
 #endif
+       return LXC_MAINLOOP_CONTINUE;
 }
 
 void seccomp_conf_init(struct lxc_conf *conf)
index 62152a6f6049b238e89eea1c972d108191802abd..c8ebe77265e9e2f6c6c8cb568b4faddd678ea7ce 100644 (file)
@@ -335,7 +335,7 @@ static int signal_handler(int fd, uint32_t events, void *data,
                return log_error(LXC_MAINLOOP_ERROR, "Failed to read signal info from signal file descriptor %d", fd);
 
        if (ret != sizeof(siginfo))
-               return log_error(-EINVAL, "Unexpected size for struct signalfd_siginfo");
+               return log_error(LXC_MAINLOOP_ERROR, "Unexpected size for struct signalfd_siginfo");
 
        /* Check whether init is running. */
        info.si_pid = 0;