Received: by 10.223.185.116 with SMTP id b49csp509774wrg; Fri, 23 Feb 2018 02:18:04 -0800 (PST) X-Google-Smtp-Source: AH8x227iSuwxAVts5FKHUrsddlqlxIXkOO2Dv6BUfIZJEtH4Chy6jZirWVk7u0DzN1yYsYx4Leor X-Received: by 10.99.181.28 with SMTP id y28mr1088075pge.222.1519381083997; Fri, 23 Feb 2018 02:18:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519381083; cv=none; d=google.com; s=arc-20160816; b=mDcyHGot5BmBzGYyw2iM/wFzAhoTQCCciNPj7qR+rruS1f5dyrHeAd+vb4dY4RoFBi Pl8x8bIKNX1pO3IClns8svKCuL/BJnkcYSLsdFqqGT3fibCAyx49H+v6zDatTzz8EZ1z c8iJnNbYxvPhdo6ttgXUedW2H1ccnsAHxs3Q6+dXapI38n180d3vMG7aMlykOTohH/r8 thxHElHFei8lcSz3RPb+l8cpihcyyX0NWD8BR5FQ8xcy1Af+XesXNLyTlnSq2Kl8YuTY tekWkhi4JE1MP/LWKZ2dMBJfEUWZsDRbddAE+FbRc26SHD94GNW5W1IWlXOiFuFqoUhU ydbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=E8912SBG6XsZQpSKEiXaak7O1BKvvLVklKmTpPpQdws=; b=ptcHVpYCQ1HC3QhCFU9R5E7Hm4Q646hJGE93ekwmgnqc6l5exSdAJ5gS9G8IatacSp vlteowtLmfTyUTSPgXuZ1TmJw50kQYoAYgUUgykHhbiez/x5zjFf9tPg2PuIXm3qIgWq LeBaS0hPnIls4gi/D7NRYG6LL1xO9XgVrNkMJxP/SshOTgKR/VkpwZGM7n5HnsZByajL auzOHL/Q3Ihe4ssOJZxKJFCv2oh6TwaBpnVKB+bcvdjx9GFgJMJoFgovt6LCuJ1dw9ky N0m5NcOcPc1FTtAKdSWdKp4BsTZMtz4oI4tqA4u/B49y5Qva3hzG8HduAIY+4MlT2n3B EPRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZIQxCk+A; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o127si1332039pga.599.2018.02.23.02.17.49; Fri, 23 Feb 2018 02:18:03 -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=@gmail.com header.s=20161025 header.b=ZIQxCk+A; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751456AbeBWKP3 (ORCPT + 99 others); Fri, 23 Feb 2018 05:15:29 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:43863 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750910AbeBWKP1 (ORCPT ); Fri, 23 Feb 2018 05:15:27 -0500 Received: by mail-pf0-f196.google.com with SMTP id z14so3330448pfe.10; Fri, 23 Feb 2018 02:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=E8912SBG6XsZQpSKEiXaak7O1BKvvLVklKmTpPpQdws=; b=ZIQxCk+AllC4zYch4puULXvYfMVVnI9hQ/mlaBaOS5/TTM/QYnGIEaD0v+Tk0h6lCM HZqlh5PeklDNwI+XPEDNHICbVUHVxSxjFEpRthXZaUdF6/zWv1kjGw9FEY22u+plznn0 JNAr/FkqEucLRZjEJ9zUo1xQVXGeyJzM/pBCsARz2x30SXgcUn8LIC7qx7z1xh1NwKX2 5zDGUcBHg/X90yes/N9GfgtF6gk5hO5Ldx4LORv+f3pTh3QGa8CpQ/iQbcXJ5iqo/THf jPkDDLz2hgkDvnLfd1C98D3+N+kGHLuhGPGzRwEXAWkHHm9UyrKRdQBkLRNOcPn+wqX1 YdUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=E8912SBG6XsZQpSKEiXaak7O1BKvvLVklKmTpPpQdws=; b=JHVO+STyhjKlpV+PjVotkx3Xdg+8tEphFiXhzrDuqvGg+YH23tDgm984MHQN+hEp8N rmEDIF0QZW1nRKTPQy8dbQvd4U5cH50GWmWhBabDp8HZq6NUkMhkCSM20CcsJe1pXtRZ 9+ze+gBEj53cQaro+ijglY5gQLmxIwfanoO0D+XL1wFqVRVEa/sEkXLp+j0xTz02/QDs 0WyRJMPbEe4TDCIsOukkKqEdJd9s02DzMi0T5oAtXBHaNTUrCf+B0DHjUnlfyy0Wa3jI P/1xOTeXjDA5BmEnyPD7eoANHEBNrNsf+TnI48zEBn+pvIvJHbygvqX00Sh4jQlmwtLX vhog== X-Gm-Message-State: APf1xPBactrd5B89Gc8DEMBlWgWgshR2eDePuRw02zMpnsrp1eOcBObT AlSzK4rZdQqMRfXiUjhBRpA= X-Received: by 10.99.96.137 with SMTP id u131mr1059235pgb.103.1519380926353; Fri, 23 Feb 2018 02:15:26 -0800 (PST) Received: from localhost.localdomain ([175.203.71.146]) by smtp.gmail.com with ESMTPSA id m3sm3852574pgd.3.2018.02.23.02.15.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 02:15:25 -0800 (PST) From: Seunghun Han To: Tony Luck , Borislav Petkov Cc: linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Seunghun Han Subject: [PATCH] x86: mce: fix kernel panic when check_interval is changed Date: Fri, 23 Feb 2018 19:13:50 +0900 Message-Id: <20180223101350.8344-1-kkamagui@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I am Seunghun Han and a senior security researcher at National Security Research Institute of South Korea. I found a critical security issue which can make kernel panic in userspace. After analyzing the issue carefully, I found that MCE driver in the kernel has a problem which can be occurred in SMP environment. The check_interval file in /sys/devices/system/machinecheck/machinecheck directory is a global timer value for MCE polling. If it is changed by one CPU, MCE driver in kernel calls mce_restart() function and broadcasts the event to other CPUs to delete and restart MCE polling timer. The __mcheck_cpu_init_timer() function which is called by mce_restart() function initializes the mce_timer variable, and the "lock" in mce_timer is also reinitialized. If more than one CPU write a specific value to check_interval file concurrently, one can initialize the "lock" in mce_timer while the others are handling "lock" in mce_timer. This problem causes some synchronization errors such as kernel panic and kernel hang. It is a critical security problem because the attacker can make kernel panic by writing a value to the check_interval file in userspace, and it can be used for Denial-of-Service (DoS) attack. To fix this problem, I changed the __mcheck_cpu_init_timer() function to reuse mce_timer instead of initializing it. The purpose of the function is to restart the timer and it can be archived by calling Signed-off-by: Seunghun Han --- arch/x86/kernel/cpu/mcheck/mce.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c index 3d8c573a9a27..d72f2f74f4d7 100644 --- a/arch/x86/kernel/cpu/mcheck/mce.c +++ b/arch/x86/kernel/cpu/mcheck/mce.c @@ -1771,7 +1771,6 @@ static void __mcheck_cpu_init_timer(void) { struct timer_list *t = this_cpu_ptr(&mce_timer); - timer_setup(t, mce_timer_fn, TIMER_PINNED); mce_start_timer(t); } @@ -2029,8 +2028,10 @@ static void mce_enable_ce(void *all) return; cmci_reenable(); cmci_recheck(); - if (all) + if (all) { + del_timer_sync(this_cpu_ptr(&mce_timer)); __mcheck_cpu_init_timer(); + } } static struct bus_type mce_subsys = { -- 2.11.0