From patchwork Tue Mar 26 13:13:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 2336311 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 5A8C4DF264 for ; Tue, 26 Mar 2013 13:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933886Ab3CZNPv (ORCPT ); Tue, 26 Mar 2013 09:15:51 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:35202 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933869Ab3CZNPu (ORCPT ); Tue, 26 Mar 2013 09:15:50 -0400 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r2QDFi7e008775 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Mar 2013 13:15:45 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r2QDFhf6000548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 26 Mar 2013 13:15:44 GMT Received: from abhmt112.oracle.com (abhmt112.oracle.com [141.146.116.64]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r2QDFhh9014349; Tue, 26 Mar 2013 08:15:43 -0500 Received: from longonot.mountain (/41.202.240.4) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 26 Mar 2013 06:15:42 -0700 Date: Tue, 26 Mar 2013 16:13:58 +0300 From: Dan Carpenter To: Alex Williamson Cc: Jiang Liu , Vijay Mohan Pandarathil , kvm@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] vfio-pci: integer overflow in vfio_pci_ioctl() Message-ID: <20130326131358.GA11516@longonot.mountain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The worry here is that a large value of hdr.start would cause a read before the start of the array and a crash in vfio_msi_set_vector_signal(). The check in vfio_msi_set_block() is not enough: if (start + count > vdev->num_ctx) return -EINVAL; A large value of "start" would lead to an integer overflow. The check in vfio_msi_set_vector_signal() doesn't work either: if (vector >= vdev->num_ctx) return -EINVAL; Here "vector" is "count" casted to a signed int so it would be negative and thus smaller than "vdev->num_ctx" which is also a signed int. Signed-off-by: Dan Carpenter --- Static analysis stuff. Untested. This patch is not beautiful. There is probably a better limit to use if I knew the code. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index acfcb1a..de54f69 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -371,6 +371,9 @@ static long vfio_pci_ioctl(void *device_data, hdr.count > vfio_pci_get_irq_count(vdev, hdr.index)) return -EINVAL; + if (hdr.start > INT_MAX - hdr.count) + return -EINVAL; + data = memdup_user((void __user *)(arg + minsz), hdr.count * size); if (IS_ERR(data))