Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1705544ybi; Wed, 17 Jul 2019 20:28:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzT9KZ8p8/FoIjpghR8n/a47a72EQD5mp5a4EtTKrU6c8f9Y7m+OBD8ns1BnagfSmWJ6Gtw X-Received: by 2002:a17:90a:1785:: with SMTP id q5mr48043890pja.106.1563420491582; Wed, 17 Jul 2019 20:28:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563420491; cv=none; d=google.com; s=arc-20160816; b=KCjRa+CD7NO2ebRUBZKU7xgshe+xuQzcn7jXDv1up5H1qgyAZ84JnYZO+RIsIgxZWx sNuW5ZNk/eX3eZoLE/dvOrZ6g0/TmY5Lh/AgHQwSGR2PAQ3xUlaC0y8iajieZ+MRcqMk SPHQIxowZmj7m4eQpFFOPI9u+4woitl/bcirLC78GlUg8HnAAXj1JwZGtqQqvTzM/uP4 M6ae789Dv4SuhhDoTzUwGMq4gsX2HysEwsXBezaEQ2JMtGDY0Fggz4WW0BoRgspv1H4v oDnO99i+LoGLTfCSDdch8Ch8IIWlVWpPxciM53vt/TyXKZD0kylWrYPVhMA5a577B+7G GZwQ== 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=LRWAbWeg+x/zuEjkCvJArEy+0TSkzc0H+x375d6pU/A=; b=WIRB4akTqtyvXWdxGGTkLkkYUuMTe9plQHb//mIEtyqAIoRU3PoqG5IKVgtT98w5FW AS5ro5FilDPrxhfiPAE0GMBZuOIBVuHBUNLpLK/t+ycBtbf48yCZ0mdxSfDLpJFYD11a FlwaiuIn7C8AFfsNJdke9foM2NXroZzatM9N2B5/NF++3cshsDEJGwfa4TPeAfKmQF4T oU3OYpkDwa0XXSlmlUYhDhcBKpRmo6D+9359Ag9fNoVpC/lPTR3Rs0wI4p+LMV+12bAh XtjzRY0dOSgiCrJgj4hI9utOm1Sg8i4n9M56Q4CzeKxeCSm1WQlzxwBaIbCeBypJBU5m LPBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KQAxbbL9; 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 i8si26209147pfk.189.2019.07.17.20.27.55; Wed, 17 Jul 2019 20:28:11 -0700 (PDT) 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=KQAxbbL9; 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 S2389936AbfGRDFX (ORCPT + 99 others); Wed, 17 Jul 2019 23:05:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:36394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389899AbfGRDFT (ORCPT ); Wed, 17 Jul 2019 23:05:19 -0400 Received: from localhost (115.42.148.210.bf.2iij.net [210.148.42.115]) (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 812C021848; Thu, 18 Jul 2019 03:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419118; bh=Cw8nZhSNTC1JErlNBl+stX66sOGdrKeE3CNCJw9MiTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KQAxbbL9LLEQOhg77C8Im7f+Iomg7AQ3o0eoZu4BjiFE/7Ny5LKAKjaAOLl63jz9s Vh485AaehisXaxquO78dDrMsjRXZPYJk4N4rWm28+LsgJa/d4QmIySLpGC4KukGFel EbKtGXUqIpQeVWm2erfgr0EtKN/X9Y+3zV3NAblY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eiichi Tsukata , Thomas Gleixner , peterz@infradead.org, Sasha Levin Subject: [PATCH 5.1 36/54] cpu/hotplug: Fix out-of-bounds read when setting fail state Date: Thu, 18 Jul 2019 12:01:31 +0900 Message-Id: <20190718030056.073634451@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718030053.287374640@linuxfoundation.org> References: <20190718030053.287374640@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 [ Upstream commit 33d4a5a7a5b4d02915d765064b2319e90a11cbde ] Setting invalid value to /sys/devices/system/cpu/cpuX/hotplug/fail can control `struct cpuhp_step *sp` address, results in the following global-out-of-bounds read. Reproducer: # echo -2 > /sys/devices/system/cpu/cpu0/hotplug/fail KASAN report: BUG: KASAN: global-out-of-bounds in write_cpuhp_fail+0x2cd/0x2e0 Read of size 8 at addr ffffffff89734438 by task bash/1941 CPU: 0 PID: 1941 Comm: bash Not tainted 5.2.0-rc6+ #31 Call Trace: write_cpuhp_fail+0x2cd/0x2e0 dev_attr_store+0x58/0x80 sysfs_kf_write+0x13d/0x1a0 kernfs_fop_write+0x2bc/0x460 vfs_write+0x1e1/0x560 ksys_write+0x126/0x250 do_syscall_64+0xc1/0x390 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x7f05e4f4c970 The buggy address belongs to the variable: cpu_hotplug_lock+0x98/0xa0 Memory state around the buggy address: ffffffff89734300: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00 ffffffff89734380: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00 >ffffffff89734400: 00 00 00 00 fa fa fa fa 00 00 00 00 fa fa fa fa ^ ffffffff89734480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffffffff89734500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Add a sanity check for the value written from user space. Fixes: 1db49484f21ed ("smp/hotplug: Hotplug state fail injection") Signed-off-by: Eiichi Tsukata Signed-off-by: Thomas Gleixner Cc: peterz@infradead.org Link: https://lkml.kernel.org/r/20190627024732.31672-1-devel@etsukata.com Signed-off-by: Sasha Levin --- kernel/cpu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/cpu.c b/kernel/cpu.c index 6170034f4118..e97e7224ab47 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1954,6 +1954,9 @@ static ssize_t write_cpuhp_fail(struct device *dev, if (ret) return ret; + if (fail < CPUHP_OFFLINE || fail > CPUHP_ONLINE) + return -EINVAL; + /* * Cannot fail STARTING/DYING callbacks. */ -- 2.20.1