Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp800257imu; Tue, 11 Dec 2018 07:47:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/XxcO3b4QLXy69TF7bbgH/ttx75qWr/Aaqz6bZK68QN8Y2uS0AiMNK64PRolGWAeWeg4usK X-Received: by 2002:a63:a51b:: with SMTP id n27mr15327799pgf.17.1544543264541; Tue, 11 Dec 2018 07:47:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544543264; cv=none; d=google.com; s=arc-20160816; b=hfaHettp38QhpDmiYf21n/ROArRzmdMN7UsrekiPgfp4o6WWeGIN400ExmNFo89PLr TXJE9DjxTmgb14sp5Byi5Gp/GaVuu87MOMpkAeJ3q5h/r2JvMRLbWNH3ctEfqxY/r6+w Anznl1Z8U3TXmU+x/dqRaNYXcblIRIh9H12BILRSHNAtvdw+2LHhQ1tWFgW+OggljZ3R KryS1FhuvzRjCtYFxY4s7r3AI7YWE0elT2XquJY4rWrgb2mqN5RTZ7Of7gQZl1bSDBZN Dij38g7cNoxHNrUwrvfledPoZ/GyyR5mB6B4sQxR50KVnBpJYRULpwXS4j5Qlm3UkCMb x2Cg== 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=orP3uOFwIsNEvrQZmMUUfZJvEYyHnGiZk6qj3VMy1G0=; b=U8rTtPguYLHd8rsmj0HqqLjxz3fz2SuVIIuzeKShZeoSG8vhsEu7mFUbAgrnXoAzqm mHd70D08jZTLg2fuCfJlwjeAiMJ1kU4IQ55Pt7PpHsJrNSct4+TWhMYDjdQCRzu3qMOm iQJ+W5LNDDeF+vdBaHs0OIXJDSq78DnX3gzmf+Vyz3uBFeZY2KqpAiHpkGIQ9lQUr/fS +l4iUkRFmUUiM3U5Ozq5FoVhD37sLNOgfPwZCuUHbDfLihw9e3tZFn/NP59WcIKYM+Rl ThOOIBcmH+CX43Hz9wknhuW80KGGRjDLFg9rjGlSFQkG2ymdfTOi3+LicW0b0mGoMtu6 UWSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LADm3bVx; 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 l66si13541124pfi.5.2018.12.11.07.47.29; Tue, 11 Dec 2018 07:47:44 -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=LADm3bVx; 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 S1727913AbeLKPoo (ORCPT + 99 others); Tue, 11 Dec 2018 10:44:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:33044 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727897AbeLKPok (ORCPT ); Tue, 11 Dec 2018 10:44:40 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 1265C20855; Tue, 11 Dec 2018 15:44:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543079; bh=6Zx2hjK8jucerjTjeOsCYKXBznSN0JHyB9vQ8CAv7Sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LADm3bVxPifAsBuu+D4PdlKWfIsYAUeeE28VK58J82j3etovGw/m//ykgXZvbwBkY 6Gh0jbiqdee5XwoP88VSPYIHhYflYQicddTIKKnoeHiTsel2J43v6bczAKmAO7KKOm EUAFfgTVmnNybpRwnXwsL6rDvwEDiyCY1p0QeHq0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Macpaul Lin , Daniel Thompson Subject: [PATCH 3.18 52/54] kgdboc: fix KASAN global-out-of-bounds bug in param_set_kgdboc_var() Date: Tue, 11 Dec 2018 16:41:40 +0100 Message-Id: <20181211151548.979018838@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151546.010073210@linuxfoundation.org> References: <20181211151546.010073210@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Macpaul Lin commit dada6a43b0402eba438a17ac86fdc64ac56a4607 upstream. This patch is trying to fix KE issue due to "BUG: KASAN: global-out-of-bounds in param_set_kgdboc_var+0x194/0x198" reported by Syzkaller scan." [26364:syz-executor0][name:report8t]BUG: KASAN: global-out-of-bounds in param_set_kgdboc_var+0x194/0x198 [26364:syz-executor0][name:report&]Read of size 1 at addr ffffff900e44f95f by task syz-executor0/26364 [26364:syz-executor0][name:report&] [26364:syz-executor0]CPU: 7 PID: 26364 Comm: syz-executor0 Tainted: G W 0 [26364:syz-executor0]Call trace: [26364:syz-executor0][] dump_bacIctrace+Ox0/0x470 [26364:syz-executor0][] show_stack+0x20/0x30 [26364:syz-executor0][] dump_stack+Oxd8/0x128 [26364:syz-executor0][] print_address_description +0x80/0x4a8 [26364:syz-executor0][] kasan_report+Ox178/0x390 [26364:syz-executor0][] _asan_report_loadi_noabort+Ox18/0x20 [26364:syz-executor0][] param_set_kgdboc_var+Ox194/0x198 [26364:syz-executor0][] param_attr_store+Ox14c/0x270 [26364:syz-executor0][] module_attr_store+0x60/0x90 [26364:syz-executor0][] sysfs_kl_write+Ox100/0x158 [26364:syz-executor0][] kernfs_fop_write+0x27c/0x3a8 [26364:syz-executor0][] do_loop_readv_writev+0x114/0x1b0 [26364:syz-executor0][] do_readv_writev+0x4f8/0x5e0 [26364:syz-executor0][] vfs_writev+0x7c/Oxb8 [26364:syz-executor0][] SyS_writev+Oxcc/0x208 [26364:syz-executor0][] elO_svc_naked +0x24/0x28 [26364:syz-executor0][name:report&] [26364:syz-executor0][name:report&]The buggy address belongs to the variable: [26364:syz-executor0][name:report&] kgdb_tty_line+Ox3f/0x40 [26364:syz-executor0][name:report&] [26364:syz-executor0][name:report&]Memory state around the buggy address: [26364:syz-executor0] ffffff900e44f800: 00 00 00 00 00 04 fa fa fa fa fa fa 00 fa fa fa [26364:syz-executor0] ffffff900e44f880: fa fa fa fa 00 fa fa fa fa fa fa fa 00 fa fa fa [26364:syz-executor0]> ffffff900e44f900: fa fa fa fa 04 fa fa fa fa fa fa fa 00 00 00 00 [26364:syz-executor0][name:report&] ^ [26364:syz-executor0] ffffff900e44f980: 00 fa fa fa fa fa fa fa 04 fa fa fa fa fa fa fa [26364:syz-executor0] ffffff900e44fa00: 04 fa fa fa fa fa fa fa 00 fa fa fa fa fa fa fa [26364:syz-executor0][name:report&] [26364:syz-executor0][name:panic&]Disabling lock debugging due to kernel taint [26364:syz-executor0]------------[cut here]------------ After checking the source code, we've found there might be an out-of-bounds access to "config[len - 1]" array when the variable "len" is zero. Signed-off-by: Macpaul Lin Acked-by: Daniel Thompson Cc: stable Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/kgdboc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -232,7 +232,7 @@ static void kgdboc_put_char(u8 chr) static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp) { - int len = strlen(kmessage); + size_t len = strlen(kmessage); if (len >= MAX_CONFIG_LEN) { printk(KERN_ERR "kgdboc: config string too long\n"); @@ -254,7 +254,7 @@ static int param_set_kgdboc_var(const ch strcpy(config, kmessage); /* Chop out \n char as a result of echo */ - if (config[len - 1] == '\n') + if (len && config[len - 1] == '\n') config[len - 1] = '\0'; if (configured == 1)