From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Williamson Subject: [PATCH 6/6] pci-assign: Harden I/O port test Date: Wed, 16 Nov 2011 13:46:45 -0700 Message-ID: <20111116204628.23506.92105.stgit@bling.home> References: <20111116203834.23506.21535.stgit@bling.home> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: jan.kiszka@siemens.com, alex.williamson@redhat.com, yongjie.ren@intel.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:11032 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753631Ab1KPUqv (ORCPT ); Wed, 16 Nov 2011 15:46:51 -0500 In-Reply-To: <20111116203834.23506.21535.stgit@bling.home> Sender: kvm-owner@vger.kernel.org List-ID: Markus Armbruster points out that we're missing a < 0 check from pread while trying to probe for pci-sysfs io-port resource support. We don't expect a short read, but we should harden the test to abort if we get one so we're not potentially looking at a stale errno. Signed-off-by: Alex Williamson --- hw/device-assignment.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 0160de7..7e6f972 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -434,8 +434,9 @@ static int assigned_dev_register_regions(PCIRegion *io_regions, * kernels return EIO. New kernels only allow 1/2/4 byte reads * so should return EINVAL for a 3 byte read */ ret = pread(pci_dev->v_addrs[i].region->resource_fd, &val, 3, 0); - if (ret == 3) { - fprintf(stderr, "I/O port resource supports 3 byte read?!\n"); + if (ret >= 0) { + fprintf(stderr, "Unexpected return from I/O port read: %d\n", + ret); abort(); } else if (errno != EINVAL) { fprintf(stderr, "Using raw in/out ioport access (sysfs - %s)\n",