summaryrefslogtreecommitdiffstats
path: root/io
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2015-12-21 11:58:51 +0000
committerTimothy Pearson <tpearson@raptorengineering.com>2019-11-29 19:28:21 -0600
commit6dc8aed9e483b04e176eedd7a04b059eb2da618a (patch)
tree744c5760f089438e530ba89643dfdc296c184dcc /io
parentba8a4d3e51ceed17acef75fae5ce95f68d7717a1 (diff)
downloadhqemu-6dc8aed9e483b04e176eedd7a04b059eb2da618a.zip
hqemu-6dc8aed9e483b04e176eedd7a04b059eb2da618a.tar.gz
io: fix stack allocation when sending of file descriptors
When sending file descriptors over a socket, we have to allocate a data buffer to hold the FDs in the scmsghdr. Unfortunately we allocated the buffer on the stack inside an if () {} block, but called sendmsg() outside the block. So the stack bytes holding the FDs were liable to be overwritten with other data. By luck this was not a problem when sending 1 FD, but if sending 2 or more then it would fail. The fix is to simply move the variables outside the nested 'if' block. To keep valgrind quiet we also zero-initialize the 'control' buffer. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'io')
-rw-r--r--io/channel-socket.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/io/channel-socket.c b/io/channel-socket.c
index eed2ff5..10a5b31 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -493,15 +493,14 @@ static ssize_t qio_channel_socket_writev(QIOChannel *ioc,
QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc);
ssize_t ret;
struct msghdr msg = { NULL, };
+ char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 };
+ size_t fdsize = sizeof(int) * nfds;
+ struct cmsghdr *cmsg;
msg.msg_iov = (struct iovec *)iov;
msg.msg_iovlen = niov;
if (nfds) {
- char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)];
- size_t fdsize = sizeof(int) * nfds;
- struct cmsghdr *cmsg;
-
if (nfds > SOCKET_MAX_FDS) {
error_setg_errno(errp, -EINVAL,
"Only %d FDs can be sent, got %zu",
OpenPOWER on IntegriCloud