Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3687913ybv; Mon, 10 Feb 2020 04:43:50 -0800 (PST) X-Google-Smtp-Source: APXvYqylIXzGUD1zwzavKYmQpr2t12m555IFYc8vz364pe2j7drRxXKQt8tgYtV6rZj7x4bjl18N X-Received: by 2002:a9d:3e43:: with SMTP id h3mr875196otg.84.1581338630546; Mon, 10 Feb 2020 04:43:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581338630; cv=none; d=google.com; s=arc-20160816; b=q4xnURTBDpEb0ZW4A1Ah8OtJprm2UN5o6TQwCUm3eOZzgCrdQNPEbrcsgZ5bSLUgKx 1AKgYF6WBQI9ub56NlH62IjGJwDpvGhxDdex7Xtk8ukG8jQ4ZFOfTEDiUxzIzjbrBHCd bAq9h/jLKqAfPJaPJ9V25q9+FFz//CGzK64t3LeOPat/ZXPCoyp+8Ie1Oc+SS3fBs09H 76YmG4kL40zr6F+lQrec8jks4dI5O+KK1pASH6uRORZobNnuCeCZFYdjoh/8SX2w2AyP roBaGCl2belBMNeCT12YqTCWuTlbSm2D+cXH1G3EN5FWu0wnMiKjDfO9K2W4S/TKtiPA obrQ== 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=/Mwju3et27e+QuKwN81JtWBTGKwJloZkwxbYyOoN6yA=; b=zC2GcxjOeYpd2FBOuN8iAOtnT+TLDjOczf34NBktRcFYSD7G8ZlcM1EDUQRJ/kngoS /XXte4SmDkl0eqyjF/J0fdmMjYszcAbrFNr+WGcT1BY3x760Y+7xTZgSW7uEaBVJ48kg MlGC5evJMUi6UlBZEfvIlCS8pCOVpWBb6Dik/0OqQXV4QrgAX0N/UlkvPPoTzW9tHLiF 208v25aH0cll9AqEdC+CU/xW/kTefc05mowe5lK5bC2FBTe4qoX4IN4Jat3cDJk3B37u DhUl4E83PuY6pmz4h6QZzcVybf1Q2wM22j921QJ/BhkGzFB0y/1nbRGGK5xe2wOhQntX nCZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xIGXde+u; 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 s17si125884otr.320.2020.02.10.04.43.39; Mon, 10 Feb 2020 04:43:50 -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=xIGXde+u; 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 S1730280AbgBJMmh (ORCPT + 99 others); Mon, 10 Feb 2020 07:42:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:37124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728130AbgBJMj1 (ORCPT ); Mon, 10 Feb 2020 07:39:27 -0500 Received: from localhost (unknown [209.37.97.194]) (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 87C1821739; Mon, 10 Feb 2020 12:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338366; bh=t+7mj2y7Pg3yWFabejvmCnP1OD8PLDuyovdxaA+8P1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xIGXde+u519NtW9POFP9LciPNfcxDYXY0Nr4G49U5tkVQ6Aabd4VKia40Ik6wSofJ b/coXnHLPdTah8npshJ/SxPfotoFMivJKaVyNxAxYQNF0mxjqBH/J4L84pPHnnGfyU POzQeIfNz7eHqhnzoLGgMWFBtMVHrnxTEEXxUbaw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Kicinski , Taehee Yoo Subject: [PATCH 5.5 025/367] netdevsim: fix stack-out-of-bounds in nsim_dev_debugfs_init() Date: Mon, 10 Feb 2020 04:28:58 -0800 Message-Id: <20200210122426.200878011@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@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: Taehee Yoo [ Upstream commit 6fb8852b1298200da39bd85788bc5755d1d56f32 ] When netdevsim dev is being created, a debugfs directory is created. The variable "dev_ddir_name" is 16bytes device name pointer and device name is "netdevsim". The maximum dev id length is 10. So, 16bytes for device name isn't enough. Test commands: modprobe netdevsim echo "1000000000 0" > /sys/bus/netdevsim/new_device Splat looks like: [ 249.622710][ T900] BUG: KASAN: stack-out-of-bounds in number+0x824/0x880 [ 249.623658][ T900] Write of size 1 at addr ffff88804c527988 by task bash/900 [ 249.624521][ T900] [ 249.624830][ T900] CPU: 1 PID: 900 Comm: bash Not tainted 5.5.0+ #322 [ 249.625691][ T900] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 249.626712][ T900] Call Trace: [ 249.627103][ T900] dump_stack+0x96/0xdb [ 249.627639][ T900] ? number+0x824/0x880 [ 249.628173][ T900] print_address_description.constprop.5+0x1be/0x360 [ 249.629022][ T900] ? number+0x824/0x880 [ 249.629569][ T900] ? number+0x824/0x880 [ 249.630105][ T900] __kasan_report+0x12a/0x170 [ 249.630717][ T900] ? number+0x824/0x880 [ 249.631201][ T900] kasan_report+0xe/0x20 [ 249.631723][ T900] number+0x824/0x880 [ 249.632235][ T900] ? put_dec+0xa0/0xa0 [ 249.632716][ T900] ? rcu_read_lock_sched_held+0x90/0xc0 [ 249.633392][ T900] vsnprintf+0x63c/0x10b0 [ 249.633983][ T900] ? pointer+0x5b0/0x5b0 [ 249.634543][ T900] ? mark_lock+0x11d/0xc40 [ 249.635200][ T900] sprintf+0x9b/0xd0 [ 249.635750][ T900] ? scnprintf+0xe0/0xe0 [ 249.636370][ T900] nsim_dev_probe+0x63c/0xbf0 [netdevsim] [ ... ] Reviewed-by: Jakub Kicinski Fixes: ab1d0cc004d7 ("netdevsim: change debugfs tree topology") Signed-off-by: Taehee Yoo Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/netdevsim/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -73,7 +73,7 @@ static const struct file_operations nsim static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) { - char dev_ddir_name[16]; + char dev_ddir_name[sizeof(DRV_NAME) + 10]; sprintf(dev_ddir_name, DRV_NAME "%u", nsim_dev->nsim_bus_dev->dev.id); nsim_dev->ddir = debugfs_create_dir(dev_ddir_name, nsim_dev_ddir);