Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2339995ybz; Thu, 23 Apr 2020 16:19:51 -0700 (PDT) X-Google-Smtp-Source: APiQypJFt5Ubnu5u7Iu5mVsFGEFMvldw8XrSnzPM7eW7p5W/qmHJgEWdjUrLhxiqYcdJ0zA8EIBP X-Received: by 2002:a50:a285:: with SMTP id 5mr4782030edm.360.1587683991143; Thu, 23 Apr 2020 16:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587683991; cv=none; d=google.com; s=arc-20160816; b=NkTJZ8aK4iZyhkBb+j29RKL540VQm2h6O3Zzl9WSFoxHeUuGrvPy0PzT8yBR5jq2xL Mmeio1V8gA5YFenzP4RTkuYP0VWJ4eZ92cVFRzYGbLz0XG7Ds/iTybg0VjdB2SewPt7t YJ9aDZdCfA5l1pZeD+hSS6FtrN7/zwEQk4SDkW7T4MdSJIAgzArqI0mZj95iNo2F+5Vg Fjulcgkxr89vwBRAMKt+svG25Njpljg4h94Xd5m58k8EnyHHFYW0UrmbqiS/AI1TMt31 MjYPY8zS0cS2JVMbtMGbEUZCJAPAEMn8/GrBArUBnUxaxtX0/EuaNI46gedqMdr3RDCD 5tXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=2DH+8Yrg2xOWh6N3LItmaywD8poz9KjrGHyKOmOkGow=; b=FC26gs5jznSUiO8fakQmalx5pOadErp2SpqKdc2H3zPat+MJRinR0K8XUCP4h0SokP tQSATJl1OQHq98iccPw3XiAzUDFg+pq3+AtTAS2ZjWlsntaT2q2xzXs5L5wEQxvjAoQL RPHS7l3kJS1w5j6DymAAhBNBgHZM3ouiGBXPGNAd7QYRoQ0BzLaI3m6isjD5JwFhLN4p a364qf0MrZ92/IltHAc1Dfln/7Btf3IqIeOhpsg3Llld5aPZgO54zFqrWz5umN+OT0/l mnv6cYzjfAWYtaA0M/Iq0PB9v4qx1lBOzij/rZ/iQYfPaoZ05JiVlpolPeqELrME92A4 Iytg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fx19si2103344ejb.39.2020.04.23.16.19.28; Thu, 23 Apr 2020 16:19:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729542AbgDWXPU (ORCPT + 99 others); Thu, 23 Apr 2020 19:15:20 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:49728 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728424AbgDWXGr (ORCPT ); Thu, 23 Apr 2020 19:06:47 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvS-0004hX-3O; Fri, 24 Apr 2020 00:06:34 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvP-00E6nz-QF; Fri, 24 Apr 2020 00:06:31 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Jiri Kosina" , "Benjamin Tissoires" , "Dmitry Torokhov" , syzbot+19340dff067c2d3835c0@syzkaller.appspotmail.com Date: Fri, 24 Apr 2020 00:05:39 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 112/245] HID: hid-input: clear unmapped usages In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ 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] Reported-by: syzbot+19340dff067c2d3835c0@syzkaller.appspotmail.com Signed-off-by: Dmitry Torokhov Tested-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Ben Hutchings --- 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 @@ -947,9 +947,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); @@ -1008,9 +1014,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)