Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp3947849pjo; Tue, 3 Mar 2020 09:56:02 -0800 (PST) X-Google-Smtp-Source: ADFU+vuxKKKk4YG4UQ0mGwKICiNikg/iUA76i210xn7C+tQrhXq7x9IYsKjvFlLi/xr42LpUjqy1 X-Received: by 2002:a9d:480c:: with SMTP id c12mr4205210otf.336.1583258162165; Tue, 03 Mar 2020 09:56:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583258162; cv=none; d=google.com; s=arc-20160816; b=SrOZZLP0EgpxKgyRKIHjYENTxH+u13whhtt5lJlTo537gjYp8ddjZA0huViDWyQKz2 QXUDvk9ivedqW9Ew3P8T7ATP6IiIvRkOm2ByUhZMNyFHlcv5kYsSfBybxBdy8jd/xODF k+TrMQfMFRuWD1XcPngUeOu1nowDqwYC7PpvjQQVoCwUjzXMdVxh5sUzD8sJFzak2buK tPkHaSHgByANiawbCnwzKl+6efZO7/hPaZwruKPCK3jf4fUsmCpLGTTlBHl3I3OX16Rs VPwZPgACAKkxBlZ74Z9aGpUbYOwfx5GcTL+cPGKFg3oj4EXOaPZApX9jDbf5GcFvEAQ/ C8/w== 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=mHXleVweAxdBdzf7LybZ2vSH0pDvvUxeRts8EPN8ADo=; b=N/waJPNKWtWyDdkrzX/XVJlwb0PQtMxc51ORaCHrJUhhQvx22hnlhfzbmXhuJxyQF4 jLggmmUxxZxMue55Glyo9XrWiMa329USuPdCoxZCuf/Ih8smd+Dsshqy7IK+yRZBlbJe OGyF6v81g6/AOG+0k7GU3oTiwDt/NGOW86U1dCOjUwk+aYTJ161t1LGGtPGYdoYKskrc LRtqk0sKSL+/L3EWAkm8AwX8tP/PQcvT5x39SA1AbUxhmYRJMJt5lpER/GrtiAsT14ep vkH8ismGKyB3dlPCrHtsbexB+UMv8h22BokoSavqAgo6CSEoDp+bt3R8qyYmucxt7Y+m MkBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pQ4yyuf8; 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 d15si728635oic.38.2020.03.03.09.55.50; Tue, 03 Mar 2020 09:56:02 -0800 (PST) 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=pQ4yyuf8; 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 S1732687AbgCCRzT (ORCPT + 99 others); Tue, 3 Mar 2020 12:55:19 -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) {