Received: from eggs.gnu.org ([2001:4830:134:3::10]:56642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WHwHX-00036R-88 for qemu-devel@nongnu.org; Mon, 24 Feb 2014 09:13:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WHwHR-0005Zn-8E for qemu-devel@nongnu.org; Mon, 24 Feb 2014 09:13:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WHwHQ-0005ZX-VR for qemu-devel@nongnu.org; Mon, 24 Feb 2014 09:13:13 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1OEDBqE015513 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 24 Feb 2014 09:13:11 -0500 From: Markus Armbruster References: <1393000925-8446-1-git-send-email-armbru@redhat.com> <1393000925-8446-2-git-send-email-armbru@redhat.com> <1393003052.9111.81.camel@ul30vt.home> Date: Mon, 24 Feb 2014 15:04:37 +0100 In-Reply-To: <1393003052.9111.81.camel@ul30vt.home> (Alex Williamson's message of "Fri, 21 Feb 2014 10:17:32 -0700") Message-ID: <871tyszjwq.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 1/2] vfio: Fix overrun after readlink() fills buffer completely List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: qemu-devel@nongnu.org Alex Williamson writes: > On Fri, 2014-02-21 at 17:42 +0100, Markus Armbruster wrote: >> readlink() returns the number of bytes written to the buffer, and it >> doesn't write a terminating null byte. vfio_init() writes it itself. >> Overruns the buffer when readlink() filled it completely. >> >> Fix by reserving space for the null byte when calling readlink(), like >> we do elsewhere. >> >> Spotted by Coverity. >> >> Signed-off-by: Markus Armbruster >> --- >> hw/misc/vfio.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c >> index 8db182f..8e56785 100644 >> --- a/hw/misc/vfio.c >> +++ b/hw/misc/vfio.c >> @@ -3681,7 +3681,7 @@ static int vfio_initfn(PCIDevice *pdev) >> >> strncat(path, "iommu_group", sizeof(path) - strlen(path) - 1); >> >> - len = readlink(path, iommu_group_path, PATH_MAX); >> + len = readlink(path, iommu_group_path, PATH_MAX - 1); >> if (len <= 0) { >> error_report("vfio: error no iommu_group for device"); >> return -errno; > > I'm not sure why we wouldn't follow the same logic as pci-assign here. > If we fill to the length provided we have no idea if we have the full > path. We certainly expect it to fit well within PATH_MAX, so let's > handle it as an error if we reach PATH_MAX. Thanks, Fair point. v2 sent.