From patchwork Fri Feb 21 16:42:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 322946 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C33D32C0320 for ; Sat, 22 Feb 2014 03:42:52 +1100 (EST) Received: from localhost ([::1]:45618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGtBZ-0004AJ-Lx for incoming@patchwork.ozlabs.org; Fri, 21 Feb 2014 11:42:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGtB1-000439-Mn for qemu-devel@nongnu.org; Fri, 21 Feb 2014 11:42:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGtAv-0002hT-Od for qemu-devel@nongnu.org; Fri, 21 Feb 2014 11:42:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGtAv-0002h4-FY for qemu-devel@nongnu.org; Fri, 21 Feb 2014 11:42:09 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1LGg8ei017370 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Feb 2014 11:42:08 -0500 Received: from blackfin.pond.sub.org (ovpn-116-49.ams2.redhat.com [10.36.116.49]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s1LGg6wM028749 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 21 Feb 2014 11:42:07 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 39518200CE; Fri, 21 Feb 2014 17:42:05 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Feb 2014 17:42:04 +0100 Message-Id: <1393000925-8446-2-git-send-email-armbru@redhat.com> In-Reply-To: <1393000925-8446-1-git-send-email-armbru@redhat.com> References: <1393000925-8446-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: alex.williamson@redhat.com Subject: [Qemu-devel] [PATCH 1/2] vfio: Fix overrun after readlink() fills buffer completely X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Peter Maydell --- 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;