From patchwork Wed Mar 16 23:59:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 8606171 Return-Path: X-Original-To: patchwork-linux-input@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 26300C0553 for ; Wed, 16 Mar 2016 23:59:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5366820435 for ; Wed, 16 Mar 2016 23:59:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F345B2041D for ; Wed, 16 Mar 2016 23:59:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935337AbcCPX7n (ORCPT ); Wed, 16 Mar 2016 19:59:43 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:35897 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935267AbcCPX7n (ORCPT ); Wed, 16 Mar 2016 19:59:43 -0400 Received: by mail-pf0-f177.google.com with SMTP id u190so94455472pfb.3; Wed, 16 Mar 2016 16:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=zzeMk++fELwUS8dEpehIbmyodXsqaSvj0fdNRIU1+YA=; b=gfFGIaJyWUVEzXxALDd7qyviaftoI1N9ZYQaNSWN/PbHZOlit7Ya+fd8mRWVHkjE6P siVyKllWB2VZaR0wtYhpNneTZpBRd0Xq0AkC224cG5iSr7IntBYQhwewO7XD7++vbay8 WCKD5vCeRN+/EkI6ju8UG18WGXmUWlr0WfFuMUygvtWfmkiHg0r4vkDcEtBam58dlDok JuwcSJGFv9KEL+NZCZBKbt/c9jAuWMO94ftmURMpfnRf6uM44EaVA6YzsytFQpV4ATJt 03G4G9FD94rWFIx8pWTv70tSc3E1iZtWGbVAJ+mtkwSTUKpZqxD6c0P1MZikorzyheYQ xI9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=zzeMk++fELwUS8dEpehIbmyodXsqaSvj0fdNRIU1+YA=; b=iB4yjWrVR/ANaAJ7r/+srgY0T/kOYTGuDjc61vWhrE5HIpWbm/bTJI5RFgt2FuzWQy lXBkcjANaHX3kDh+bwTzog8AGLNXHm1UBMrzQ9Sb+PP6xbgot4b/ckqkzrpz1qLlnX4F OitMFRkf+CptiAyWYdrDob6+kXyySV3ZrnAz8FTxjymMmnmbsNL8f0LblnR95Yqe6uT7 FDJw7Gqpm0slcNq6a1YOqln4Bml3cqTd1e/bhMbvMiigvVu4eSqvFZFigaIlgKqxDYFK BvTqcH1FSootgFlZ6Wh/sgIY5TRG3eoaXoTFlb8XftZVf/6MYUsK4Q9lZoW9HNcY51j2 zcaw== X-Gm-Message-State: AD7BkJJFmkKkKpZIo7tg+Gw0C2vlHXw94jTY1gtMQ4Chlt1aiYANlxYlJ2xrZevNbYl9AA== X-Received: by 10.67.1.237 with SMTP id bj13mr10371542pad.130.1458172781826; Wed, 16 Mar 2016 16:59:41 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1301:cd3e:ea10:fa40:1af3]) by smtp.gmail.com with ESMTPSA id n11sm8247620pfb.74.2016.03.16.16.59.40 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 16 Mar 2016 16:59:41 -0700 (PDT) Date: Wed, 16 Mar 2016 16:59:38 -0700 From: Dmitry Torokhov To: Jiri Kosina Cc: Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: hidraw: switch to using memdup_user Message-ID: <20160316235938.GA23827@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 Instead of open-coding memory allocation and copying form user memory sequence let's use memdup_user(). Signed-off-by: Dmitry Torokhov Reviewed-by: Benjamin Tissoires --- drivers/hid/hidraw.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index 9c2d7c2..b9a76e3 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -123,7 +124,6 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, dev = hidraw_table[minor]->hid; - if (count > HID_MAX_BUFFER_SIZE) { hid_warn(dev, "pid %d passed too large report\n", task_pid_nr(current)); @@ -138,17 +138,12 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, goto out; } - buf = kmalloc(count * sizeof(__u8), GFP_KERNEL); - if (!buf) { - ret = -ENOMEM; + buf = memdup_user(buffer, count); + if (IS_ERR(buf)) { + ret = PTR_ERR(buf); goto out; } - if (copy_from_user(buf, buffer, count)) { - ret = -EFAULT; - goto out_free; - } - if ((report_type == HID_OUTPUT_REPORT) && !(dev->quirks & HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP)) { ret = hid_hw_output_report(dev, buf, count);