Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5026111ybl; Tue, 14 Jan 2020 02:11:53 -0800 (PST) X-Google-Smtp-Source: APXvYqyWAAQwMlUYhdshbmLE3iOaCSGNqO9p+RqFK3xPwBK48kYIHIBhVpqhk+EzbXWxiPRPH2tJ X-Received: by 2002:a05:6808:8f5:: with SMTP id d21mr16524497oic.58.1578996712951; Tue, 14 Jan 2020 02:11:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578996712; cv=none; d=google.com; s=arc-20160816; b=dsPvQbpl5fibRQAdncda8s/HlSwECPe1yLky9V/nVe85LlMFdgyBTt/gpdxkP3OSoj 69FdYug2HsI9QWhJ6aJzQjsmOtgsNV+7HYVcaWXR20GppVaaA+RDiCLFHBrPr84djFL7 BbOhuzK/sX7x5+MfSlULSrcZ/d2HHQufjRAQH4UgfyEfEkZQZZjt3v3+Dzs6YZogzfcj rNIKeYssAMVJmtGe7Fd6DNQmKCq5w50gPCxYCkAjF1p5G6Vn4GViiWhz6TJaMAI2D6Fj 5qBNae+ji0AihCFBlyUc5iLvv8px/QpGNEOUibxNEAJPnjkr2pETCbT3DL189auWfpcL Ksdg== 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=6fOAQaEAChriqYMTX20pUAGSzpTLkI1RNDPGD6jbfZ4=; b=SPsDOTFjIeSxQZ6hFWp0pVEVJaRKLYVhDhL6swGL/VogwHnNhzfX74p1fJ314pKsYl 1Nq3r4rBvupt/LLNW8aAmkCuNp75g4qJKcDefcIllL0Tqiq6xG28H47Nl+OSidHAHjZR e+Xnf0Qmo6czPk7d4Pnl2KPUGS0/Q4hHU2zfsgFxmNAqtVk9jX9DuDiI545loTRaPI/8 TnWSr5FbJ3f1zb6uGZJjECP8PDwk3Igvmp0KrR0tU3K7Khlfjwy3pMJejnSLpHtJ6ULh S/vc4cucYi+cARe5ELyOYBigEZh7YBNus2k1MjWXaxP1yZgWKyM6/GnwKg4pcaNP71NE VXzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vjXvUy2e; 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 m9si7263602oie.148.2020.01.14.02.11.42; Tue, 14 Jan 2020 02:11:52 -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=vjXvUy2e; 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 S1731455AbgANKJs (ORCPT + 99 others); Tue, 14 Jan 2020 05:09:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:42948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731015AbgANKJp (ORCPT ); Tue, 14 Jan 2020 05:09:45 -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 4F37520678; Tue, 14 Jan 2020 10:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578996584; bh=i9XHjjTBZozC+H537XEIoVLL6Sfq7UH+oCXKnUHsGxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vjXvUy2e1iZo3zS3JSRLva/HsSQzI3OerFBxJUw2whNPXJ/TZF0TeTgv4s9O3c0MF ZVzKQ93BACgwxCqH4XB8tlP4q+A9rFSlB75aoLQkGlOfyWZF19XIw9XzcRPfh+kSDk pV0zgVckDAEJW+/9qFb5pEl0RsmQUKxFY7sHJ+8c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+19340dff067c2d3835c0@syzkaller.appspotmail.com, Dmitry Torokhov , Benjamin Tissoires , Jiri Kosina Subject: [PATCH 4.14 21/39] HID: hid-input: clear unmapped usages Date: Tue, 14 Jan 2020 11:01:55 +0100 Message-Id: <20200114094343.740254763@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114094336.210038037@linuxfoundation.org> References: <20200114094336.210038037@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: Dmitry Torokhov commit 4f3882177240a1f55e45a3d241d3121341bead78 upstream. We should not be leaving half-mapped usages with potentially invalid keycodes, as that may confuse hidinput_find_key() when the key is located by index, which may end up feeding way too large keycode into the VT keyboard handler and cause OOB write there: BUG: KASAN: global-out-of-bounds in clear_bit include/asm-generic/bitops-instrumented.h:56 [inline] BUG: KASAN: global-out-of-bounds in kbd_keycode drivers/tty/vt/keyboard.c:1411 [inline] BUG: KASAN: global-out-of-bounds in kbd_event+0xe6b/0x3790 drivers/tty/vt/keyboard.c:1495 Write of size 8 at addr ffffffff89a1b2d8 by task syz-executor108/1722 ... kbd_keycode drivers/tty/vt/keyboard.c:1411 [inline] kbd_event+0xe6b/0x3790 drivers/tty/vt/keyboard.c:1495 input_to_handler+0x3b6/0x4c0 drivers/input/input.c:118 input_pass_values.part.0+0x2e3/0x720 drivers/input/input.c:145 input_pass_values drivers/input/input.c:949 [inline] input_set_keycode+0x290/0x320 drivers/input/input.c:954 evdev_handle_set_keycode_v2+0xc4/0x120 drivers/input/evdev.c:882 evdev_do_ioctl drivers/input/evdev.c:1150 [inline] Cc: stable@vger.kernel.org Reported-by: syzbot+19340dff067c2d3835c0@syzkaller.appspotmail.com Signed-off-by: Dmitry Torokhov Tested-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-input.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1116,9 +1116,15 @@ static void hidinput_configure_usage(str } mapped: - if (device->driver->input_mapped && device->driver->input_mapped(device, - hidinput, field, usage, &bit, &max) < 0) - goto ignore; + if (device->driver->input_mapped && + device->driver->input_mapped(device, hidinput, field, usage, + &bit, &max) < 0) { + /* + * The driver indicated that no further generic handling + * of the usage is desired. + */ + return; + } set_bit(usage->type, input->evbit); @@ -1176,9 +1182,11 @@ mapped: set_bit(MSC_SCAN, input->mscbit); } -ignore: return; +ignore: + usage->type = 0; + usage->code = 0; } void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)