Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HHOaw-0002RA-SO for qemu-devel@nongnu.org; Wed, 14 Feb 2007 13:11:06 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HHOav-0002QR-7J for qemu-devel@nongnu.org; Wed, 14 Feb 2007 13:11:06 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HHOav-0002QL-4G for qemu-devel@nongnu.org; Wed, 14 Feb 2007 13:11:05 -0500 Received: from ug-out-1314.google.com ([66.249.92.168]) by monty-python.gnu.org with esmtp (Exim 4.52) id 1HHOas-0001eG-Pz for qemu-devel@nongnu.org; Wed, 14 Feb 2007 13:11:03 -0500 Received: by ug-out-1314.google.com with SMTP id j40so278977ugd for ; Wed, 14 Feb 2007 10:11:00 -0800 (PST) Message-ID: Date: Wed, 14 Feb 2007 10:11:00 -0800 From: "Ed Swierk" Sender: eswierk@gmail.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_125536_13867110.1171476660654" Subject: [Qemu-devel] [PATCH] Fix crash after char device read returns 0 Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org ------=_Part_125536_13867110.1171476660654 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline qemu 0.9.0 on Linux crashes with SIGSEGV after read() on a char device returns 0, which occurs if the char device is a fifo and the writer closes the file. In this case, fd_chr_read() and stdio_read() react by removing the IO handler and freeing it. Unfortunately main_loop_wait() is unprepared to deal with this (as the comment "XXX: better handling of removal" suggests) and attempts to access the freed handler. Even if main_loop_wait() were improved, it is not correct to remove the IO handler just because read() returns 0: if the char device is a fifo, a process may well reopen the fifo for writing at a later point. The attached patch is a naive fix; feedback is welcome. --Ed ------=_Part_125536_13867110.1171476660654 Content-Type: text/x-patch; name=qemu-chr-read-zero.patch; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: base64 X-Attachment-Id: f_ey62w7i3 Content-Disposition: attachment; filename="qemu-chr-read-zero.patch" SW5kZXg6IHFlbXUtc25hcHNob3QtMjAwNy0wMi0wOV8wNS92bC5jCj09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIHFl bXUtc25hcHNob3QtMjAwNy0wMi0wOV8wNS5vcmlnL3ZsLmMKKysrIHFlbXUtc25hcHNob3QtMjAw Ny0wMi0wOV8wNS92bC5jCkBAIC0xMzQ2LDExICsxMzQ2LDEzIEBAIHN0YXRpYyB2b2lkIGZkX2No cl9yZWFkKHZvaWQgKm9wYXF1ZSkKICAgICBpZiAobGVuID09IDApCiAgICAgICAgIHJldHVybjsK ICAgICBzaXplID0gcmVhZChzLT5mZF9pbiwgYnVmLCBsZW4pOworI2lmIDAKICAgICBpZiAoc2l6 ZSA9PSAwKSB7CiAgICAgICAgIC8qIEZEIGhhcyBiZWVuIGNsb3NlZC4gUmVtb3ZlIGl0IGZyb20g dGhlIGFjdGl2ZSBsaXN0LiAgKi8KICAgICAgICAgcWVtdV9zZXRfZmRfaGFuZGxlcjIocy0+ZmRf aW4sIE5VTEwsIE5VTEwsIE5VTEwsIE5VTEwpOwogICAgICAgICByZXR1cm47CiAgICAgfQorI2Vu ZGlmCiAgICAgaWYgKHNpemUgPiAwKSB7CiAgICAgICAgIHFlbXVfY2hyX3JlYWQoY2hyLCBidWYs IHNpemUpOwogICAgIH0KQEAgLTE1NDYsMTEgKzE1NDgsMTMgQEAgc3RhdGljIHZvaWQgc3RkaW9f cmVhZCh2b2lkICpvcGFxdWUpCiAgICAgdWludDhfdCBidWZbMV07CiAgICAgCiAgICAgc2l6ZSA9 IHJlYWQoMCwgYnVmLCAxKTsKKyNpZiAwCiAgICAgaWYgKHNpemUgPT0gMCkgewogICAgICAgICAv KiBzdGRpbiBoYXMgYmVlbiBjbG9zZWQuIFJlbW92ZSBpdCBmcm9tIHRoZSBhY3RpdmUgbGlzdC4g ICovCiAgICAgICAgIHFlbXVfc2V0X2ZkX2hhbmRsZXIyKDAsIE5VTEwsIE5VTEwsIE5VTEwsIE5V TEwpOwogICAgICAgICByZXR1cm47CiAgICAgfQorI2VuZGlmCiAgICAgaWYgKHNpemUgPiAwKQog ICAgICAgICBzdGRpb19yZWNlaXZlZF9ieXRlKGJ1ZlswXSk7CiB9Cg== ------=_Part_125536_13867110.1171476660654--