From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2AEAC10F27 for ; Tue, 10 Mar 2020 13:20:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE3CF20409 for ; Tue, 10 Mar 2020 13:20:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583846444; bh=xRxiI4t2Qr/gZNDM7gl9OWbxuB94b6WvyIqXb8uJ7v0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lu5P6wDBB+g1dNeOk/fj0e7nvRdkLLf9swDyMGnqpeomWOIihYqXPt8G53fDSuTWU 5SyXxJgKdfJTxx3QYMz33g+jJQ551RopS+eKtZQ72c4f4OT1qFnzTfqjD9XnHM3RjJ 14ZDQCXKp3Qdqz/RqFFA5a1JUkp6UurJIZ6uvKOk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729835AbgCJNUn (ORCPT ); Tue, 10 Mar 2020 09:20:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:52700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730688AbgCJNHE (ORCPT ); Tue, 10 Mar 2020 09:07: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 9BBE4208E4; Tue, 10 Mar 2020 13:07:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583845624; bh=xRxiI4t2Qr/gZNDM7gl9OWbxuB94b6WvyIqXb8uJ7v0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=snBbgZPVZmUcPmzbh2quGcG2TqzXEDMJhs7eiunFtG7ynhH85du2kpAy0Rtx8MwLU AXA0pDzd1MsTSrxz0LJB0IsDjw2+WaDcbJXopREbJu3oZZqPrilBzv6UF58SuDE4Mm MjSyntJIRHi1WFTRm5Ucy83CW0Wpp05pCbnABNPk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Korsnes , Armando Visconti , Jiri Kosina , Alan Stern Subject: [PATCH 4.14 040/126] HID: core: fix off-by-one memset in hid_report_raw_event() Date: Tue, 10 Mar 2020 13:41:01 +0100 Message-Id: <20200310124206.910690493@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310124203.704193207@linuxfoundation.org> References: <20200310124203.704193207@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: Johan Korsnes commit 5ebdffd25098898aff1249ae2f7dbfddd76d8f8f upstream. In case a report is greater than HID_MAX_BUFFER_SIZE, it is truncated, but the report-number byte is not correctly handled. This results in a off-by-one in the following memset, causing a kernel Oops and ensuing system crash. Note: With commit 8ec321e96e05 ("HID: Fix slab-out-of-bounds read in hid_field_extract") I no longer hit the kernel Oops as we instead fail "controlled" at probe if there is a report too long in the HID report-descriptor. hid_report_raw_event() is an exported symbol, so presumabely we cannot always rely on this being the case. Fixes: 966922f26c7f ("HID: fix a crash in hid_report_raw_event() function.") Signed-off-by: Johan Korsnes Cc: Armando Visconti Cc: Jiri Kosina Cc: Alan Stern Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1567,7 +1567,9 @@ int hid_report_raw_event(struct hid_devi rsize = ((report->size - 1) >> 3) + 1; - if (rsize > HID_MAX_BUFFER_SIZE) + if (report_enum->numbered && rsize >= HID_MAX_BUFFER_SIZE) + rsize = HID_MAX_BUFFER_SIZE - 1; + else if (rsize > HID_MAX_BUFFER_SIZE) rsize = HID_MAX_BUFFER_SIZE; if (csize < rsize) {