[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH 02/60] qemu-char: BUGFIX, don't call FD_ISSET with
From: |
Michael Tokarev |
Subject: |
[Qemu-stable] [PATCH 02/60] qemu-char: BUGFIX, don't call FD_ISSET with negative fd |
Date: |
Mon, 4 Feb 2013 14:40:12 +0400 |
From: David Gibson <address@hidden>
tcp_chr_connect(), unlike for example udp_chr_update_read_handler() does
not check if the fd it is using is valid (>= 0) before passing it to
qemu_set_fd_handler2(). If using e.g. a TCP serial port, which is not
initially connected, this can result in -1 being passed to FD_ISSET, which
has undefined behaviour. On x86 it seems to harmlessly return 0, but on
PowerPC, it causes a fortify buffer overflow error to be thrown.
This patch fixes this by putting an extra test in tcp_chr_connect(), and
also adds an assert qemu_set_fd_handler2() to catch other such errors on
all platforms, rather than just some.
Signed-off-by: David Gibson <address@hidden>
Signed-off-by: Anthony Liguori <address@hidden>
(cherry picked from commit bbdd2ad0814ea0911076419ea21b7957505cf1cc)
Signed-off-by: Michael Tokarev <address@hidden>
---
iohandler.c | 2 ++
qemu-char.c | 6 ++++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/iohandler.c b/iohandler.c
index dea4355..a2d871b 100644
--- a/iohandler.c
+++ b/iohandler.c
@@ -56,6 +56,8 @@ int qemu_set_fd_handler2(int fd,
{
IOHandlerRecord *ioh;
+ assert(fd >= 0);
+
if (!fd_read && !fd_write) {
QLIST_FOREACH(ioh, &io_handlers, next) {
if (ioh->fd == fd) {
diff --git a/qemu-char.c b/qemu-char.c
index fe1126f..3a68430 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2321,8 +2321,10 @@ static void tcp_chr_connect(void *opaque)
TCPCharDriver *s = chr->opaque;
s->connected = 1;
- qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
- tcp_chr_read, NULL, chr);
+ if (s->fd >= 0) {
+ qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
+ tcp_chr_read, NULL, chr);
+ }
qemu_chr_generic_open(chr);
}
--
1.7.10.4
- [Qemu-stable] Patch queue for qemu-1.1.3 stable release, Michael Tokarev, 2013/02/04
- [Qemu-stable] [PATCH 02/60] qemu-char: BUGFIX, don't call FD_ISSET with negative fd,
Michael Tokarev <=
- [Qemu-stable] [PATCH 03/60] use --libexecdir instead of ignoring it first and reinventing it later, Michael Tokarev, 2013/02/04
- [Qemu-stable] [PATCH 01/60] tcg/s390: fix ld/st with CONFIG_TCG_PASS_AREG0, Michael Tokarev, 2013/02/04
- [Qemu-stable] [PATCH 05/60] fix CONFIG_QEMU_HELPERDIR generation again, Michael Tokarev, 2013/02/04
- [Qemu-stable] [PATCH 04/60] configure: Fix CONFIG_QEMU_HELPERDIR generation, Michael Tokarev, 2013/02/04
- [Qemu-stable] [PATCH 23/60] hw/qxl: qxl_dirty_surfaces: use uintptr_t, Michael Tokarev, 2013/02/04
- [Qemu-stable] [PATCH 54/60] hw/arm_boot.c: Consistently use ram_size from arm_boot_info struct, Michael Tokarev, 2013/02/04
- [Qemu-stable] [PATCH 29/60] usb-storage: fix SYNCHRONIZE_CACHE, Michael Tokarev, 2013/02/04
- [Qemu-stable] [PATCH 41/60] mips/malta: fix CBUS UART interrupt pin, Michael Tokarev, 2013/02/04
- [Qemu-stable] [PATCH 10/60] pcie_aer: clear cmask for Advanced Error Interrupt Message Number, Michael Tokarev, 2013/02/04