Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5020360ybl; Tue, 14 Jan 2020 02:06:13 -0800 (PST) X-Google-Smtp-Source: APXvYqzDWwtHGauCjgnz0xQxE4cdauT1r3gTn6wMw7j//qHQVWBGdHU0so0GsXjns0VMIM/BNT6D X-Received: by 2002:a9d:6b91:: with SMTP id b17mr16757735otq.321.1578996372975; Tue, 14 Jan 2020 02:06:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578996372; cv=none; d=google.com; s=arc-20160816; b=iPzBbnAZO0JVDes9lUMOVQd3Q+UtJ1BApNmda44+6PED28qIVHh5vz/fVqkctiWB92 02hOtZYKK6mw9EJ3sM85d2RFzzdZoJUvUWHc4OJosMG9s7eRNalYqRiDhBzgnXJWqMNW 5j0hXS8TXCt7LbWyie1FXWgD55iouZLPC2uEcJKmbPf0171y1LzfKiJw8WneWhbJ7Zyt 3mfCQXoyZHiooLcG+zbP1CWKvfKO4HJQTY+dJY2TREFsiNDvNV3LI1GWZK91W2GeUCIn puIVarEdDXryYfQrVu3TiRifs2G+KgHMo3ZS+CXtVI5rcazk1SrWSS98soQNaRg9nu7l 8raA== 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=OUJWlKJyHKBucoUJfv8E+KU91CRcpuv3aPBNs3MeSLs=; b=eKwjXW5g5Gi2QzgUIAs4xLDu4acqeGEc0nipgAtJ4tr3U7YkosU2+fVzJbOXXJ53Gh Rcbtw6fPImm+p9vB2IRttgSOmB23wkeYqkVrT5PPwf8P7shdl+qUXA3zEkn6OKEUXLLv ZpCmxYHS5Iu68uCacEBAt/4/vRoGFtiTDQGJFWNlFxI2mNCpD0pCp1eGGc6PCoEP5ESS a0FcHuCRWPeAA6WMbj9FgXjswgVBiZiS3S64Xd49BLeTOyJI/l/vmJX4OMjOBalo1zmh B4Y/gp4DQ99VhqNb+OEU1tyUASfR6gZuiL+C323BQchJsczU6HvzhyIAK+709W2+9lzd nOVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YQiIl8HC; 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 s18si8641808otr.172.2020.01.14.02.06.01; Tue, 14 Jan 2020 02:06:12 -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=YQiIl8HC; 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 S1729928AbgANKEo (ORCPT + 99 others); Tue, 14 Jan 2020 05:04:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:60300 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729464AbgANKEf (ORCPT ); Tue, 14 Jan 2020 05:04:35 -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 865852465B; Tue, 14 Jan 2020 10:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578996275; bh=6j/tsqTPkVZZNOwROE5egcMMWa4qmVzGas67jGUa4LA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YQiIl8HCBeDlz8HyB23XtZRn2WS/5NTddGadpxeFLJ+z2nmRDUdxqCLt7hSfGnlo4 qtAYGdzPzNcJc3kxXwx9Zbup3bFfacEGCwTj2WHUbVjJEgJIyyVgDWKgaFPm1zQpHV 1ER1f5p7hWh4QSZ7ttZxn25/B17Qtj+1phsGU/CM= 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 5.4 20/78] HID: hid-input: clear unmapped usages Date: Tue, 14 Jan 2020 11:00:54 +0100 Message-Id: <20200114094356.444210459@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114094352.428808181@linuxfoundation.org> References: <20200114094352.428808181@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 @@ -1132,9 +1132,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); @@ -1215,9 +1221,11 @@ mapped: set_bit(MSC_SCAN, input->mscbit); } -ignore: return; +ignore: + usage->type = 0; + usage->code = 0; } static void hidinput_handle_scroll(struct hid_usage *usage,