Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp681281ybh; Tue, 10 Mar 2020 06:23:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtFYgN2ejPIfmQRy1n1nWqna22Jkegi5MB9FgqZGbtAxMLD3VNhifDMZs1fFxpasY7af3h6 X-Received: by 2002:a9d:178:: with SMTP id 111mr17628181otu.238.1583846580782; Tue, 10 Mar 2020 06:23:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583846580; cv=none; d=google.com; s=arc-20160816; b=U72i6hbGiYbdnSVzY+5TLfm8+/sUceVguANYwt5bM06l96UDHuja6o4Z0v/Bt0rcvL AphCdXc6EwlLZXToRWVyxupWhGRerwbVKdosUNNQ8k0I0Co3ZXh+4dfZlSNtXA4KlEbl 9ewbJAinr8IVnKoHLWBRJ+euJiN3jfB/2x+rQKXU/V12t888nQmPUmaecoIt477rnBb6 QO4z40vMucpofl8NtEUIKX7Ey6zCgMBQI41wdQF+VEVedmbD2RoFbjzSA3UFnuhlo2G6 Tnvap8hRUlHSpjEnSqDhr+3qC2nCh5VTKi3HGTUcTfzn1coEtcvn+zqB6l8C+1LjaIjA 8hOQ== 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=8Kf2sRPpwAdbXq4VuRsHiT7i9xkjJHEX0f5qoHeboBk=; b=TkyIaE90mMNi80p3mBIEf6xlltnH5JAVbcNBOJJ3yRY8X5DT0pH8ap+WitNKNQstzW bXEoi/CZpw7Zl1h4oq3C08G/q+b1M4I0BVn0Cskvqld+uoOddIHpyy7iRLJbvJOkvwc1 4BYNzQGrEWgUzTrPIQdxUK7llBB7Nj5ucvuhSsImeFwhikGVhnynotVkTTygqZRXG04v uQz5QRD49dOvLxKXn1t3rx9gSSPKCq8lKu1hANUaCC11qIh9+DuRX9tAO54HNQyx1abs ZaDw9yW+P26EyVh/jx2r4m2ozC1lGDrmOIbWhbmjG6bNmeHY4qp22bkaVLFXKqE8AEII by3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=snBbgZPV; 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 l65si3038995oig.156.2020.03.10.06.22.48; Tue, 10 Mar 2020 06:23:00 -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=snBbgZPV; 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 S1729644AbgCJNUm (ORCPT + 99 others); Tue, 10 Mar 2020 09:20:42 -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) {