Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1689603ybi; Wed, 17 Jul 2019 20:10:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyU7qFfS6rWXbhKDWR37a8ArXnw91kYLrjJIHGothUIPfoeJ92/GTPsyO5wdVVhZgRqoZdl X-Received: by 2002:a63:8c0e:: with SMTP id m14mr29031511pgd.219.1563419445481; Wed, 17 Jul 2019 20:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563419445; cv=none; d=google.com; s=arc-20160816; b=ROFIWEuI+DSWvZLsRz3cXrVK1tnAQS4k5uhaYZ4SADYNcO0hQrV+Opxo8nM6ZR74VP qQRUwNj6g9zJQOz4KfendCD7wiQYeB99pk7AX+LzG5xokRTbRTttzsC3662+mZUSeXEZ ddEpEOFTvcLbn4qP5AqcU0VhZuIqI+EnjFwUZLJV+cAcWRoMAkxp4YfEMm/iRiQPZOAN A4olNgbIF2tMc/LAP0S8nrQStYvY5NRzMa3AUJEwCmp3J66x7alYVFXXGksoUnWLvBYS vWmjPttmAPDBHBLn4CwtFRXNs8zGeHnBHGNzGUUOHadrkwvjC5pw/q87LCx0h05kod1d +P3Q== 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=rwyDTMbQTKsGMU0/Y6P/JXy+bB/5MMxpXHZ6W0N8sDc=; b=ZiOpTsYEM8uQtGxLXIv0pRXjj42PypC6Th+LFEleIz+AKx3exP+XCapmcM5uxRiIwq 8YQqXQ4ecJQgvrlYXfDQ7vDP0KjWwt3cU5yizsw93LZWlMudzSFhVilLI00IkWz52AJv wq3FldtiQKnODDJIF6ggB8Fasl2VvSu7wULxhaSxiWC8POqLvX4cL5PTHd7iQm3550FB +ePCCevxBLpI4qJ+A4S2FZa8/Aydy7plS4ZEUcADM5a2Mars/zhL6h7OPjECxo6fv14T VlzPM0iHQVnbyqqaO/WyJGMN61U+PDvxy8tOkk/2ZZb5Pf2opgbuYClp/r0bxUJiJSvB iI9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JYSLQh5m; 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 l63si25274265pge.264.2019.07.17.20.10.29; Wed, 17 Jul 2019 20:10:45 -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=JYSLQh5m; 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 S2390114AbfGRDIH (ORCPT + 99 others); Wed, 17 Jul 2019 23:08:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:39942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390623AbfGRDIF (ORCPT ); Wed, 17 Jul 2019 23:08:05 -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 0727E2053B; Thu, 18 Jul 2019 03:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419285; bh=/NMn9Q8TUVA7ZHtuJSKbz8Iduk5jCcm0N1Py8ubBZhE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JYSLQh5mTzmv7/Qf92OHGubu4PmaEx81dSkcbTMYf+CdEdsBhM31uLX4NRsdUOcEA +r8SfKlixqS+G5k8LZUdgd/dPGiCg/vRPosfb9iyNvtFxpw2qtrapTwBNsUqS1elsl L59sVwh8tGIv8QTj2kN+BavvQAym3O6UXsPb6dVk= 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 4.19 27/47] cpu/hotplug: Fix out-of-bounds read when setting fail state Date: Thu, 18 Jul 2019 12:01:41 +0900 Message-Id: <20190718030051.034480603@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718030045.780672747@linuxfoundation.org> References: <20190718030045.780672747@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 46aefe5c0e35..d9f855cb9f6f 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1925,6 +1925,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