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,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 E172BC3F2C6 for ; Tue, 3 Mar 2020 17:55:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B160D206D5 for ; Tue, 3 Mar 2020 17:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583258122; bh=t+S2XrhfT3pYPEY8Yhnl8TEwlDJoicoGndjBbpEjWXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=InctjeIv878Gd3yZdKqDDG7NUYC6zcAyroMKSGQa0LIdtp1/SO/NdCtcYBTssrgam R6BypdrHWpLIjFZ7+gl3/Kpz5375+ARZxqHSMSGWLcAxio9QIIEuh1jp7nlVmWHVye KlMaDLBdEfeAKI4ouZLwN+QlOE5z2vBt4EwmZ7tc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732691AbgCCRzU (ORCPT ); Tue, 3 Mar 2020 12:55:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:36754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732090AbgCCRzR (ORCPT ); Tue, 3 Mar 2020 12:55:17 -0500 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 1DD34206D5; Tue, 3 Mar 2020 17:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583258116; bh=t+S2XrhfT3pYPEY8Yhnl8TEwlDJoicoGndjBbpEjWXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pQ4yyuf845bBZMGRnQvM4nXkxlIcPEoOsZHFpmF3ICONxSJe1FEGzXLRkbV8usiQ9 c5jwVwoFesjiFWVqx8sJMVQZNH1zAxK7eJujcX5GeDcPHXB8kFPEktC643a3eicqox M7cDMnjH3h8NhmsjHPcwzhuINq6Xp9b0sRVxvlec= 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 5.4 077/152] HID: core: fix off-by-one memset in hid_report_raw_event() Date: Tue, 3 Mar 2020 18:42:55 +0100 Message-Id: <20200303174311.276257020@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303174302.523080016@linuxfoundation.org> References: <20200303174302.523080016@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 @@ -1741,7 +1741,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) {