Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10436624ybi; Wed, 24 Jul 2019 23:11:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqy30+yr+V7g3QHXprXXlrJ5FWkZqG+BClwR2hK0TbI7pskX7TDtgC6SYjEeAN9JBTmEtN/v X-Received: by 2002:a63:c006:: with SMTP id h6mr51130998pgg.290.1564035072023; Wed, 24 Jul 2019 23:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564035072; cv=none; d=google.com; s=arc-20160816; b=is10GnqxUoCJjusVhiN6/NTJZO9g/kmDAgORncAIPx19CzDl6t4YuqjJdCWCvpUYn1 i/nJ7uaMUIa9t27US+CwoewHBFySudyDoKfr15iYQ6ujIgyDEulXpmia/lpYq/NuXZwP 3vb6UPnSbRLs89Hd5S/0eQhAYAOcyFEFFR5kyQMjsfZ/ufok5oAwVnuSuff0qRh2jJXs XYwQf7xUayogGSMaN1oDjwS6W4WMh8ny9qyXx7Ev3zEBWfkB0b+Fk+XFLLacNAMo0a5N irDm7UNOBXvSSZwGWamNFNvhQNIMO7JuuZXEURLHVTz3iXaxjQT2Rf//OSeSmfd6c+ZN 48wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/oEc9wfvrnWieGrnqqknQa481olbhhSzNG2jo03uW9g=; b=k85F0l1kUgDCmlvsgT300uiv/yeeO0wbZHgltOmpLpB5QcLrkyio2VNT29h1H1ZpWQ nVoRM7nfWW1lJPSY5g7YBO4MDBSeSeazx04aBdc6sdRSpUpPiGKe4oGcol0gBxBrNcxo 4H0z1KWmYSXRka88n2zJYwkhpyLf3B1lilEFPxQj7bC7ovJ6ewsaCq3NbcTnGn5HdQKo gbjbaSB3oD8/Aninva2TyqMwO36bmIGthEW1Q/oLP8i/v7ODMEg163E1JqFTNAs8f/eC 9MI+HZati/PStmBjgAWALqLq8eq5dLgntPJPBzVW05A7LN1oKrvOEgHQgAQf8PqIfFhR XSaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ldxotr/H"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si16381579pfl.288.2019.07.24.23.10.57; Wed, 24 Jul 2019 23:11:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ldxotr/H"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729146AbfGYFuX (ORCPT + 99 others); Thu, 25 Jul 2019 01:50:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:58034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404865AbfGYFnE (ORCPT ); Thu, 25 Jul 2019 01:43:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7670B21850; Thu, 25 Jul 2019 05:43:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033384; bh=OgzOyEycRsQ5tZXTbgiVPzNADZxiQiXmkuy7t8sX45E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ldxotr/H4t9mBA7PRPwRpAuZEI9ag9RvTrdWKkgNicVMX0NUGwl965/5YYWyK+Odf UKKIgwSMCrjpIWo+ItDl24E4Imo3OWFX+/sRix91M553UWZLgcu/6T1sxfbu6LMIvI lXT1QMSIWwfpwc2JRRszsWuaUXLTpkycr4Reet6Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Grant Hernandez , Dmitry Torokhov Subject: [PATCH 4.19 189/271] Input: gtco - bounds check collection indent level Date: Wed, 24 Jul 2019 21:20:58 +0200 Message-Id: <20190724191711.317742016@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Grant Hernandez commit 2a017fd82c5402b3c8df5e3d6e5165d9e6147dc1 upstream. The GTCO tablet input driver configures itself from an HID report sent via USB during the initial enumeration process. Some debugging messages are generated during the parsing. A debugging message indentation counter is not bounds checked, leading to the ability for a specially crafted HID report to cause '-' and null bytes be written past the end of the indentation array. As long as the kernel has CONFIG_DYNAMIC_DEBUG enabled, this code will not be optimized out. This was discovered during code review after a previous syzkaller bug was found in this driver. Signed-off-by: Grant Hernandez Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/input/tablet/gtco.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) --- a/drivers/input/tablet/gtco.c +++ b/drivers/input/tablet/gtco.c @@ -78,6 +78,7 @@ Scott Hill shill@gtcocalcomp.com /* Max size of a single report */ #define REPORT_MAX_SIZE 10 +#define MAX_COLLECTION_LEVELS 10 /* Bitmask whether pen is in range */ @@ -223,8 +224,7 @@ static void parse_hid_report_descriptor( char maintype = 'x'; char globtype[12]; int indent = 0; - char indentstr[10] = ""; - + char indentstr[MAX_COLLECTION_LEVELS + 1] = { 0 }; dev_dbg(ddev, "======>>>>>>PARSE<<<<<<======\n"); @@ -350,6 +350,13 @@ static void parse_hid_report_descriptor( case TAG_MAIN_COL_START: maintype = 'S'; + if (indent == MAX_COLLECTION_LEVELS) { + dev_err(ddev, "Collection level %d would exceed limit of %d\n", + indent + 1, + MAX_COLLECTION_LEVELS); + break; + } + if (data == 0) { dev_dbg(ddev, "======>>>>>> Physical\n"); strcpy(globtype, "Physical"); @@ -369,8 +376,15 @@ static void parse_hid_report_descriptor( break; case TAG_MAIN_COL_END: - dev_dbg(ddev, "<<<<<<======\n"); maintype = 'E'; + + if (indent == 0) { + dev_err(ddev, "Collection level already at zero\n"); + break; + } + + dev_dbg(ddev, "<<<<<<======\n"); + indent--; for (x = 0; x < indent; x++) indentstr[x] = '-';