From patchwork Tue Oct 24 05:28:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10023485 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 2B6A4601E8 for ; Tue, 24 Oct 2017 05:28:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 140132896C for ; Tue, 24 Oct 2017 05:28:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0752C28973; Tue, 24 Oct 2017 05:28:32 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 A5B012896C for ; Tue, 24 Oct 2017 05:28:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751405AbdJXF21 (ORCPT ); Tue, 24 Oct 2017 01:28:27 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:45657 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751399AbdJXF21 (ORCPT ); Tue, 24 Oct 2017 01:28:27 -0400 Received: by mail-io0-f196.google.com with SMTP id i38so22555291iod.2; Mon, 23 Oct 2017 22:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=KYlp3eLGRCqXrftc1+3Odea2gkf0tw1wwpgSOs2wvmg=; b=ovWPKKzVvKbofy84EZ0twLiut7rLiqsyBRCpozEf0gm6f1pLgf2I5kXVl0ijepCHE7 3bD0n5clxYO9C1qNKIWFBqypgVV5Ifzbb4dsjRA59ywR6qXcJJLAEgylOpAZs0suKD6i t1ptj8Asl2jLQadU2vUg/XU2XJ7+5Tu4b9ly+2uiKsfZceSg74881JxD/b7laXbifojn 9OU2m2SqWtZcFE0+J2uY96a+fjzCqbxiJvVWh95WL+oy+/RE2xNqznmm2k6TAQUvSv/P KfRXfXS+ueIOPzAWdAdbF6MgW+KE0g2S2PUxEtJaK8UAOL3lCS4x6AKH04S7+73qB3qv 6TEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=KYlp3eLGRCqXrftc1+3Odea2gkf0tw1wwpgSOs2wvmg=; b=eqMZYSLMSAeHKxqYO2O949dJIAP/DbY0Hh2y6jqP0fWsHLnI/0Gm8RMA3D87TpnfBR zEQwqS+DnIgeN177aDn7+GpDGGdpp3vmGHJKHzrwio8zSbyFpvAJgynr4hQu5jl3sqWD 3YrgQTm4WCs8GqpUQICn6l/2rrP45MJjnNcC2M+MeYq5s/RAC5pL9Pl+I6idc8mbehBl x+ZvbrvchDJQIOhzIJyZAVInTX9WDwj7YdlLD7xGreEiUZxXGsTsbkIcXKrym7EWWXfX pgOFFVCsZaoNmyH03Z+Htu6hvSJ0l7uO7K1426A2M8lZcaTlIrDocvl2OExSfWsvz22L D7Sw== X-Gm-Message-State: AMCzsaXn+TfBWxybjSjYBuImIW3fUBIK/z+JPM6953tfiMPtTz+qKeZN m4b2UbsT67m8DSxq7TNMIVUUU38q X-Google-Smtp-Source: ABhQp+TNK9WiSithYfzG3qvI179URN1nZEOuh8A4SrzUBggOaXWx5yaZOKF4+PBxCvjghUDtIGaGhQ== X-Received: by 10.107.37.143 with SMTP id l137mr19423091iol.104.1508822906057; Mon, 23 Oct 2017 22:28:26 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1611:da80:8749:c06f:9515]) by smtp.gmail.com with ESMTPSA id m141sm329686itm.12.2017.10.23.22.28.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 22:28:25 -0700 (PDT) Date: Mon, 23 Oct 2017 22:28:23 -0700 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Andrey Konovalov , linux-kernel@vger.kernel.org Subject: [PATCH] Input: gtco - fix potential out-of-bound access Message-ID: <20171024052823.jpetpk2bfazfvfah@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170609 (1.8.3) 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 parse_hid_report_descriptor() has a while (i < length) loop, which only guarantees that there's at least 1 byte in the buffer, but the loop body can read multiple bytes which causes out-of-bounds access. Reported-by: Andrey Konovalov Signed-off-by: Dmitry Torokhov --- drivers/input/tablet/gtco.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/input/tablet/gtco.c b/drivers/input/tablet/gtco.c index b796e891e2ee..0351203b8c24 100644 --- a/drivers/input/tablet/gtco.c +++ b/drivers/input/tablet/gtco.c @@ -230,13 +230,24 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, /* Walk this report and pull out the info we need */ while (i < length) { - prefix = report[i]; - - /* Skip over prefix */ - i++; + prefix = report[i++]; /* Determine data size and save the data in the proper variable */ - size = PREF_SIZE(prefix); + if (PREF_SIZE(prefix) < 1) { + dev_err(ddev, + "Invalid size %d in element at offset %d\n", + PREF_SIZE(prefix), i); + break; + } + + size = 1U << (PREF_SIZE(prefix) - 1); + if (i + size >= length) { + dev_err(ddev, + "Not enough data (need %d, have %d)\n", + i + size, length); + break; + } + switch (size) { case 1: data = report[i]; @@ -244,8 +255,7 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, case 2: data16 = get_unaligned_le16(&report[i]); break; - case 3: - size = 4; + case 4: data32 = get_unaligned_le32(&report[i]); break; }