From patchwork Thu Feb 25 07:52:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 8420261 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 88907C0553 for ; Thu, 25 Feb 2016 07:52:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CEB8D20266 for ; Thu, 25 Feb 2016 07:52:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 047B7202E9 for ; Thu, 25 Feb 2016 07:52:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759754AbcBYHwZ (ORCPT ); Thu, 25 Feb 2016 02:52:25 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:48806 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759241AbcBYHwX (ORCPT ); Thu, 25 Feb 2016 02:52:23 -0500 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u1P7qKFR011701 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Feb 2016 07:52:21 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u1P7qKid028385 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 25 Feb 2016 07:52:20 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u1P7qKws028043; Thu, 25 Feb 2016 07:52:20 GMT Received: from mwanda (/154.0.139.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 24 Feb 2016 23:52:19 -0800 Date: Thu, 25 Feb 2016 10:52:12 +0300 From: Dan Carpenter To: Alex Williamson Cc: Eric Auger , "Michael S. Tsirkin" , Baptiste Reynal , Antonios Motakis , kvm@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] vfio/pci: return -EFAULT if copy_to_user fails Message-ID: <20160225075212.GD7333@mwanda> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The copy_to_user() function returns the number of bytes that were not copied but we want to return -EFAULT on error here. Fixes: 188ad9d6cbbc ('vfio/pci: Include sparse mmap capability for MSI-X table regions') Signed-off-by: Dan Carpenter Acked-by: Michael S. Tsirkin --- 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 1ce1d36..98059df 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -664,12 +664,11 @@ static long vfio_pci_ioctl(void *device_data, info.cap_offset = 0; } else { vfio_info_cap_shift(&caps, sizeof(info)); - ret = copy_to_user((void __user *)arg + - sizeof(info), caps.buf, - caps.size); - if (ret) { + if (copy_to_user((void __user *)arg + + sizeof(info), caps.buf, + caps.size)) { kfree(caps.buf); - return ret; + return -EFAULT; } info.cap_offset = sizeof(info); }