From patchwork Tue Dec 15 11:00:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 7853311 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DA1D99F350 for ; Tue, 15 Dec 2015 11:01:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4EE9A20377 for ; Tue, 15 Dec 2015 11:01:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C7BF20304 for ; Tue, 15 Dec 2015 11:01:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964927AbbLOLBA (ORCPT ); Tue, 15 Dec 2015 06:01:00 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:40580 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964903AbbLOLA7 (ORCPT ); Tue, 15 Dec 2015 06:00:59 -0500 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id tBFB0uO3009978 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 15 Dec 2015 11:00:57 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id tBFB0t3U006037 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 15 Dec 2015 11:00:56 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.13.8/8.13.8) with ESMTP id tBFB0tu2029591; Tue, 15 Dec 2015 11:00:55 GMT Received: from mwanda (/154.0.139.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 15 Dec 2015 03:00:55 -0800 Date: Tue, 15 Dec 2015 14:00:40 +0300 From: Dan Carpenter To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] [media] media-device: copy_to/from_user() returns positive Message-ID: <20151215110040.GA9594@mwanda> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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/from_user() functions return the number of bytes *not* copied. They don't return error codes. Fixes: 4f6b3f363475 ('media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl') Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe linux-media" 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/media/media-device.c b/drivers/media/media-device.c index c12481c..96ed207 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -376,18 +376,17 @@ static long media_device_get_topology(struct media_device *mdev, struct media_v2_topology ktopo; int ret; - ret = copy_from_user(&ktopo, utopo, sizeof(ktopo)); - - if (ret < 0) - return ret; + if (copy_from_user(&ktopo, utopo, sizeof(ktopo))) + return -EFAULT; ret = __media_device_get_topology(mdev, &ktopo); if (ret < 0) return ret; - ret = copy_to_user(utopo, &ktopo, sizeof(*utopo)); + if (copy_to_user(utopo, &ktopo, sizeof(*utopo))) + return -EFAULT; - return ret; + return 0; } static long media_device_ioctl(struct file *filp, unsigned int cmd,