From patchwork Mon Jul 2 23:59:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 10502719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 271B760284 for ; Mon, 2 Jul 2018 23:59:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0866228BB0 for ; Mon, 2 Jul 2018 23:59:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEDB428BBB; Mon, 2 Jul 2018 23:59:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5967428BB0 for ; Mon, 2 Jul 2018 23:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753118AbeGBX7r (ORCPT ); Mon, 2 Jul 2018 19:59:47 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:45975 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753188AbeGBX7q (ORCPT ); Mon, 2 Jul 2018 19:59:46 -0400 Received: by mail-pg0-f68.google.com with SMTP id z1-v6so69765pgv.12 for ; Mon, 02 Jul 2018 16:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=evF58zRqCwWmnT0aAXmXG229hKCPXbUldLYrasJlK64=; b=vLap2syqO4FsG96RkVXeOg5lt5nVFjrUEqsAcg6mcJZ/QtWg6ikCdtmFn5t7ykC5tz wF6DLG1E8N0WMg9P3/7Bx5y4mJRD15x/cNoKM5yc2EEtJ9cXK+rWySa1ZQHvxhExsN2J wB1DpxRwjsT+I6G5Lfrv9KNEmimf0uv6q4j8YclCaWWEkQXCO+sSQEczXvy/JSFA8qRY iWWtpl3wuBsXAqpt8W0qc5gQsj9tlwRBVktosrgfrDpDlLzljjRra60i3dFYHs7i/6Aa 96YbezbhD5Etyx2E1xEdLxen6UKme0wQinnsSvLnu6wPcjh1zil1IlgCF573k9TKkHrw DbCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=evF58zRqCwWmnT0aAXmXG229hKCPXbUldLYrasJlK64=; b=RSnT+mx76cYGsgvSh14ZAcKk/FWXKnhoJ5Rq7Jv5t7Hg3ZP+b1tsQ/6BlKx7HY6JOJ Du713il81KuiCKYmq7LNdS8Btdf8PPEmLOORPJ9z8rnri9jBR75cYECGjHea7RedHzRe jz8oGeVKicf5VGTiwblRK4QZYBNv77teTV8qKojSFoP1talhTfw9dYYMZLdFibnMT31X +AKGHEheAxUULgYMASh+/ZeJwfCbbjRMFXVa3/8qpwIxw+550G2MhcADCPkMmZQLBljA GFiPVSVT2hdxx4n5rbFlk1S+/tl5e9ZxiABjyfASfL3yqXUp0wYptDF2GAtThS0DRmXx 9VPg== X-Gm-Message-State: APt69E1O7THLvtBX/0wIb8q1Tbt/bMKEEH6cgoXy+MjvLFaQ06Fegxru vuCDWngE/tUQobJZOAtUwojhQg== X-Google-Smtp-Source: ADUXVKLCCFkRMFToziG57JFfysAsSkPpn+2va/df6lVD5YynjZQcQLhoPNN3ciYpGKk0tGG7Ru6fbg== X-Received: by 2002:a65:611a:: with SMTP id z26-v6mr23326154pgu.61.1530575985725; Mon, 02 Jul 2018 16:59:45 -0700 (PDT) Received: from drosen.mtv.corp.google.com ([2620:0:1000:1611:7129:1142:3149:848c]) by smtp.gmail.com with ESMTPSA id k15-v6sm25011486pfi.37.2018.07.02.16.59.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jul 2018 16:59:44 -0700 (PDT) From: Daniel Rosenberg To: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Daniel Rosenberg , stable@vger.kernel.org Subject: [PATCH] HID: debug: check length before copy_to_user() Date: Mon, 2 Jul 2018 16:59:37 -0700 Message-Id: <20180702235937.111619-1-drosen@google.com> X-Mailer: git-send-email 2.18.0.399.gad0ab374a1-goog Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If our length is greater than the size of the buffer, we overflow the buffer Signed-off-by: Daniel Rosenberg Cc: stable@vger.kernel.org Reviewed-by: Benjamin Tissoires --- drivers/hid/hid-debug.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c index 8469b6964ff64..b48100236df89 100644 --- a/drivers/hid/hid-debug.c +++ b/drivers/hid/hid-debug.c @@ -1154,6 +1154,8 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer, goto out; if (list->tail > list->head) { len = list->tail - list->head; + if (len > count) + len = count; if (copy_to_user(buffer + ret, &list->hid_debug_buf[list->head], len)) { ret = -EFAULT; @@ -1163,6 +1165,8 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer, list->head += len; } else { len = HID_DEBUG_BUFSIZE - list->head; + if (len > count) + len = count; if (copy_to_user(buffer, &list->hid_debug_buf[list->head], len)) { ret = -EFAULT; @@ -1170,7 +1174,9 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer, } list->head = 0; ret += len; - goto copy_rest; + count -= len; + if (count > 0) + goto copy_rest; } }