Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp803488imu; Tue, 11 Dec 2018 07:50:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/UE13xGoNGDshp0jkWKiLTrAtEGwfJAEtZoizN9U8+EEm+VkS80OYeRVssToT5Hj/LbGn38 X-Received: by 2002:a17:902:48:: with SMTP id 66mr16061031pla.68.1544543440261; Tue, 11 Dec 2018 07:50:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544543440; cv=none; d=google.com; s=arc-20160816; b=BLXr9QkdxdqAoVaQ96KDZ2eOLv9fQA1vMsDEzfg1fMWIx7GwRqpJfPvjcHO668QZuS 3QQS9ICJuMiAO0gh4ycmNVqjYenX21o814RagNXsv9x8ZF3qvl6unoAg2J9bTgIFnDb7 YsujmQ9ZWR/gBIWBbytaMqTtRwIKxilUFjjcQB8eEmNVs5dp3+HNceHlgecb/LFaBnsV n8vIBdRKGhdC1kgy5o0XTBgf/tvIwu7QK714DBH4DF3dvBKY1LPMst28/nPMmza852f3 MHdM0FJyqN2BrfY1UY+HJD0102N4Kul2nwFnhHmIioDZzE7w37oxt8Tih+lSGIpNv6K2 PNdA== 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=vTsXy4IgyHRfYTVFdRNq49WGDcODebs1dSqKTCfpH2k=; b=P3i1WBg2X7jBuKFDdOT/gRvJD8svBgNrJfvf2yudfqVJTX6dKLymzenkS/+AM1B9KH a4GMGzcZmqiSCsKvgLC8ihucE1yUVXWzdwBQw3KvoVdOAtowPxl83+3qZ0N7LqHauxzK q0lhOBHr+bjUbmnzVD9bFHeY35QofwjE24S/wtfLce9mvu7GPnbFv8Dgn6co+L002Vrz jld7w0P5hIbTphF5b7ZVgZL787ofZIXPf+2z0R4se+JfWxKcUlhDc33oazwo2h+0NsOt pki4meWy6y41l/2nq0ZpeBirRAxSFC7al6UXwhh1GhufmQnuPyXs9hBMd3zR+0lvJxnl WAIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tqih7l91; 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 p66si13279534pfp.144.2018.12.11.07.50.24; Tue, 11 Dec 2018 07:50:40 -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=tqih7l91; 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 S1728890AbeLKPsu (ORCPT + 99 others); Tue, 11 Dec 2018 10:48:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:37102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728864AbeLKPsr (ORCPT ); Tue, 11 Dec 2018 10:48:47 -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 1E9CA20870; Tue, 11 Dec 2018 15:48:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543326; bh=I56TJmKCf9pokNmWAK6G8URE7cBHXgRUy+OCcuREvLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tqih7l913ytniwgUsCIocv+GZO7y13lCnHXNSPdqgrW04Wrp1c5laRVQIypKGCg8r 18SuWxA3taMsjka5DRMeOF/kWQq+c8lyzRS7xFc3OEtcKapIFq4CheYMd6FMJ5XC2S N1l8RYmQJzrtpVgRrIsAvB7xfqUI6BmT4nA9wzCU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Macpaul Lin , Daniel Thompson Subject: [PATCH 4.4 86/91] kgdboc: fix KASAN global-out-of-bounds bug in param_set_kgdboc_var() Date: Tue, 11 Dec 2018 16:41:45 +0100 Message-Id: <20181211151613.844598759@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151606.026852373@linuxfoundation.org> References: <20181211151606.026852373@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 4.4-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)