|
|
5544c1 |
From 04eefabaae59ad624f0baf3b97a1d1d15cf2a23d Mon Sep 17 00:00:00 2001
|
|
|
5544c1 |
From: David Gibson <david@gibson.dropbear.id.au>
|
|
|
5544c1 |
Date: Mon, 10 Sep 2012 12:30:56 +1000
|
|
|
5544c1 |
Subject: [PATCH] qemu-char: BUGFIX, don't call FD_ISSET with negative fd
|
|
|
5544c1 |
|
|
|
5544c1 |
tcp_chr_connect(), unlike for example udp_chr_update_read_handler() does
|
|
|
5544c1 |
not check if the fd it is using is valid (>= 0) before passing it to
|
|
|
5544c1 |
qemu_set_fd_handler2(). If using e.g. a TCP serial port, which is not
|
|
|
5544c1 |
initially connected, this can result in -1 being passed to FD_ISSET, which
|
|
|
5544c1 |
has undefined behaviour. On x86 it seems to harmlessly return 0, but on
|
|
|
5544c1 |
PowerPC, it causes a fortify buffer overflow error to be thrown.
|
|
|
5544c1 |
|
|
|
5544c1 |
This patch fixes this by putting an extra test in tcp_chr_connect(), and
|
|
|
5544c1 |
also adds an assert qemu_set_fd_handler2() to catch other such errors on
|
|
|
5544c1 |
all platforms, rather than just some.
|
|
|
5544c1 |
|
|
|
5544c1 |
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
|
|
|
5544c1 |
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
|
|
|
5544c1 |
(cherry picked from commit bbdd2ad0814ea0911076419ea21b7957505cf1cc)
|
|
|
5544c1 |
|
|
|
5544c1 |
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
|
|
|
5544c1 |
---
|
|
|
5544c1 |
iohandler.c | 2 ++
|
|
|
5544c1 |
qemu-char.c | 6 ++++--
|
|
|
5544c1 |
2 files changed, 6 insertions(+), 2 deletions(-)
|
|
|
5544c1 |
|
|
|
5544c1 |
diff --git a/iohandler.c b/iohandler.c
|
|
|
5544c1 |
index dea4355..a2d871b 100644
|
|
|
5544c1 |
--- a/iohandler.c
|
|
|
5544c1 |
+++ b/iohandler.c
|
|
|
5544c1 |
@@ -56,6 +56,8 @@ int qemu_set_fd_handler2(int fd,
|
|
|
5544c1 |
{
|
|
|
5544c1 |
IOHandlerRecord *ioh;
|
|
|
5544c1 |
|
|
|
5544c1 |
+ assert(fd >= 0);
|
|
|
5544c1 |
+
|
|
|
5544c1 |
if (!fd_read && !fd_write) {
|
|
|
5544c1 |
QLIST_FOREACH(ioh, &io_handlers, next) {
|
|
|
5544c1 |
if (ioh->fd == fd) {
|
|
|
5544c1 |
diff --git a/qemu-char.c b/qemu-char.c
|
|
|
5544c1 |
index 10d1504..7f0f895 100644
|
|
|
5544c1 |
--- a/qemu-char.c
|
|
|
5544c1 |
+++ b/qemu-char.c
|
|
|
5544c1 |
@@ -2329,8 +2329,10 @@ static void tcp_chr_connect(void *opaque)
|
|
|
5544c1 |
TCPCharDriver *s = chr->opaque;
|
|
|
5544c1 |
|
|
|
5544c1 |
s->connected = 1;
|
|
|
5544c1 |
- qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
|
|
|
5544c1 |
- tcp_chr_read, NULL, chr);
|
|
|
5544c1 |
+ if (s->fd >= 0) {
|
|
|
5544c1 |
+ qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
|
|
|
5544c1 |
+ tcp_chr_read, NULL, chr);
|
|
|
5544c1 |
+ }
|
|
|
5544c1 |
qemu_chr_generic_open(chr);
|
|
|
5544c1 |
}
|
|
|
5544c1 |
|
|
|
5544c1 |
--
|
|
|
5544c1 |
1.7.12.1
|
|
|
5544c1 |
|