Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp817278ybl; Wed, 11 Dec 2019 07:59:03 -0800 (PST) X-Google-Smtp-Source: APXvYqziXnuHgrvumgKURxVyOZ33SDxaGueE8nDC4IvCeBO7a5eKzNcrWOmBExeOfFlDg6qu8vD8 X-Received: by 2002:aca:a902:: with SMTP id s2mr3454368oie.5.1576079943070; Wed, 11 Dec 2019 07:59:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576079943; cv=none; d=google.com; s=arc-20160816; b=Ow2nK6VnMXiMa7wfCSMO8dbFlmqFfowCnrx8CjX2nwJ500mV5t+l6OJldhz2u+2NBm gW/FvDQAA/MWWnxuORvNVl8EZzJHOoq05cuBbgJQngdP5u9EUUN37R7IF5rzvdOl2ZUX g5QdzfjPke2eFLYc/7kLsthK7f0MCoVtDwO6oo/N6upGxUzxnxEvH+MfsYJSea2cbOtH GhftJvXgA//GpdSofvE6qV6m/9+Szp4rinqld9Hjft3itJHkMM2YPuVRgFXxcrBr5Lp5 wCCLV8cLYcsyuOcEG3WtqQxAmSJPAIrhzmmLrDokFAcjo/ASgY6+utp5mViJLceRvye/ Re4A== 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=/HneSaAaZcqDDOAwokslA7B3bmhHfgZMsvQYue0o/nk=; b=Zm8HHlHfLWM7UieoUdKGQmkjPnpbvUF9nsR73H/+cxwk40S7ROYlsUNgRiC+E8u6ze mTfIqXHrt9oJRn8CjF+FHrpA2DMI3M9Jaz6yAiGnChMnrCIHF0xu1E5MyAjLl/31Gdan WS4LvF4nehUqHfneuVWtFaa45OPfLxaAPFXV4a/74KJC6D9LJ9mkm3xivmm0N2Ui3UAJ Ps5jgw4Rss43CTgShqDeLLXEY2UDB3pzXibsr8q0FFyIBiFy36GWa2yPckEo5FhI4sXx p+yj/+D3eskM560xIzWk6V9a8NIn01KrZXU07BQOWGNbbccgSjBW64q8pLr++XKcjcvH LzMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P85hZyky; 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 t18si1386681oij.133.2019.12.11.07.58.50; Wed, 11 Dec 2019 07:59:03 -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=P85hZyky; 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 S1730430AbfLKPOw (ORCPT + 99 others); Wed, 11 Dec 2019 10:14:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:38030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730846AbfLKPNw (ORCPT ); Wed, 11 Dec 2019 10:13:52 -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 1CC012465C; Wed, 11 Dec 2019 15:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077231; bh=B3UhKAqWVlq8iHx8Xvx/hiWVPkC7YtwfvTyR+6T9d2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P85hZykymzssl2QlXHYKxB1aC0s/E/DPxHKFmahCNuB/uPsKWlEMBDe3HBAg9CArV qCY7YMJm9KniX8+uShXa6JV0y/OsIr2EP+4KBrJ2tFrk29xSAyoELmBvPH3ts0VDGo xVJJ3bEFltz/dtVKLRnUmLjI5+nYElh9ycl/fITI= 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 Subject: [PATCH 5.3 066/105] tty: vt: keyboard: reject invalid keycodes Date: Wed, 11 Dec 2019 16:05:55 +0100 Message-Id: <20191211150247.684002354@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@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 b2b2dd71e0859436d4e05b2f61f86140250ed3f8 upstream. Do not try to handle keycodes that are too big, otherwise we risk doing out-of-bounds writes: 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] In this case we were dealing with a fuzzed HID device that declared over 12K buttons, and while HID layer should not be reporting to us such big keycodes, we should also be defensive and reject invalid data ourselves as well. Reported-by: syzbot+19340dff067c2d3835c0@syzkaller.appspotmail.com Signed-off-by: Dmitry Torokhov Cc: stable Link: https://lore.kernel.org/r/20191122204220.GA129459@dtor-ws Signed-off-by: Greg Kroah-Hartman --- drivers/tty/vt/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -1491,7 +1491,7 @@ static void kbd_event(struct input_handl if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev)) kbd_rawcode(value); - if (event_type == EV_KEY) + if (event_type == EV_KEY && event_code <= KEY_MAX) kbd_keycode(event_code, value, HW_RAW(handle->dev)); spin_unlock(&kbd_event_lock);