Received: by 10.223.185.116 with SMTP id b49csp6622798wrg; Wed, 28 Feb 2018 12:32:41 -0800 (PST) X-Google-Smtp-Source: AH8x225uyOSpAuHiQpbLAJ/I5iKB9hhNcZDptZoJ69NN4MLZrKJPVNHc6BS6dd30D2zbV5YvQ6Av X-Received: by 10.98.229.21 with SMTP id n21mr18763110pff.158.1519849961100; Wed, 28 Feb 2018 12:32:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519849961; cv=none; d=google.com; s=arc-20160816; b=CD4nnelcykw2zDN2M+mJ9q7ujK4a0ZFKZ9Cmgr9DWTFINuTf1037oZENLK2Km3WaBA Ce2TD7wxx1JFvcdqWpkb3DvMtCg7SVEK0aF55FyDSdoSOI4Y03iqt/z9kYqLqGr51bEK JE1oD8CPLOZJA3vuUvmVlADAuRn3Q4ZKNpeVpHGX0H9efzlWUbPcWEUvv37JZaEqOQtz B8jvWB8A8TkCFanslucTeRXRN3ExHWrw1oyMGq0u+LJ99ZpQSvaAbR2xnQCk1CvSQMNv Z0D1CnWIrWSiDW4f5J/KYfZe0MPMH4l/G7cQbBEvpHV/k2Upn4SffOAwuQvS5EW5UW2k wA9g== 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=hf2Z5V6JSGyVPbid2pfabIGyulMtCJAalxlrd4giEx8=; b=mTwGIT3s/dROPu02Q/dbRKI4DTdoA9ZRN5IXUfqVlTPY53pA0njeowMSchTjat4U2d u3QZwSHgLnJo1ig+t4H2iztUYTtx2aTG9nsbsjvaSqidmFZZcuB8apmz/ea1uF/q7ykm kidEyrCFc2eDFgphtwnUJR6yHGwOD0PolCESn6bENsbpDxZv0YjDG1GCwmaPjhf/Be19 wlqAu0H+r7rPR/ZnTjkEbzKZ6fT1oKfpPjTF+vHemA6UmhwpY8o8yBIHXIMguCgMV9EH XO65OYTOngB7DysbjCp7XiJOj0XWYLE4GEzAyW9hLVoryedOguVFr7k71Jxwzhd23yxW 64nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f7Bo4NR3; 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 j4si1435520pgf.265.2018.02.28.12.32.25; Wed, 28 Feb 2018 12:32:41 -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=f7Bo4NR3; 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 S934651AbeB1Ubp (ORCPT + 99 others); Wed, 28 Feb 2018 15:31:45 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36258 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934609AbeB1Ubn (ORCPT ); Wed, 28 Feb 2018 15:31:43 -0500 Received: by mail-pg0-f67.google.com with SMTP id i14so1395234pgv.3; Wed, 28 Feb 2018 12:31:43 -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=hf2Z5V6JSGyVPbid2pfabIGyulMtCJAalxlrd4giEx8=; b=f7Bo4NR3FoK6V4gNznP4seV02wyIKwunEf4jE8kHsqNBNw+ySgdtb1Hv87JiB0Sgjr IUmh3ln720IP752Kvbl51Cfmq1nvkFiTCnbZyczuGrjkKC1+bYdFCinV9/ElaLTCaNAI lj7s1JWq8G7q8Or8va3RC9tv6OrwPYe56mDwvkKD13KFv+HMOV//dWjk6gHkVkNt4k2f k+8wlEwfdRatAbIUbJEc5X9I6N07HX9UNQuo2WxXrDtgkvVLBqsTW9VC8J667k+X9A3Q IDRkX2lnjz94ZLrN/90CBI1gSeyUdwU8GZH+VD2F3hJj34clryrVE2K5TcOHr6SqUU5O QggA== 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=hf2Z5V6JSGyVPbid2pfabIGyulMtCJAalxlrd4giEx8=; b=WP37eB833V4E15IARzLZewy4+uaIe/BgMvCsJuRkXU0FccmCChj4Cj/1vhlDlrZad5 Fqd5p0dk00u//9+NEyAVBQnaah8/E8sER6HfDgttAosnNYr5OK+H3lYpXHrtlegjAZVY UJZaBltGV3xKqw+Edb5W5CvZfU31KnGGXv14vldhoVsR71+3KKEPkirS+hmyEQ7sUdum Mp0SEwK30jUgvJffnnhVML3upwa+zTUDFm7iOUnz599cJi2TG86GuCYmgY+8ewmnn/4Z XE0hGDdSsQPQwAAy/SA5wmlnV+g0R5HNsEqWfhhPEzyvRjNG3GrIe1uKvyWkhS+2MdYc oavA== X-Gm-Message-State: APf1xPC7SjMqplyVN2kQ+Ikk82zthuxlzk9GTceLWwf0aFNrqzQCrJkh hJgdIMIZ6UHJdH007VI54Kc= X-Received: by 10.99.137.195 with SMTP id v186mr15112032pgd.90.1519849902976; Wed, 28 Feb 2018 12:31:42 -0800 (PST) Received: from localhost.localdomain ([121.152.105.114]) by smtp.gmail.com with ESMTPSA id 64sm4104414pgj.39.2018.02.28.12.31.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 12:31:41 -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 V2] x86: mce: fix kernel panic when check_interval is changed Date: Thu, 1 Mar 2018 05:31:31 +0900 Message-Id: <20180228203131.3176-1-kkamagui@gmail.com> X-Mailer: git-send-email 2.16.2 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 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 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 added a mce_sysfs_mutex to serialize requests. Signed-off-by: Seunghun Han --- Changes since v1: add mce_sysfs_mutex according to review result. arch/x86/kernel/cpu/mcheck/mce.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c index 706584681a4c..bee0795a3b8c 100644 --- a/arch/x86/kernel/cpu/mcheck/mce.c +++ b/arch/x86/kernel/cpu/mcheck/mce.c @@ -55,6 +55,7 @@ #include "mce-internal.h" static DEFINE_MUTEX(mce_log_mutex); +static DEFINE_MUTEX(mce_sysfs_mutex); #define CREATE_TRACE_POINTS #include @@ -2045,8 +2046,11 @@ static void mce_enable_ce(void *all) return; cmci_reenable(); cmci_recheck(); - if (all) + if (all) { + mutex_lock(&mce_sysfs_mutex); __mcheck_cpu_init_timer(); + mutex_unlock(&mce_sysfs_mutex); + } } static struct bus_type mce_subsys = { @@ -2132,8 +2136,14 @@ static ssize_t store_int_with_restart(struct device *s, struct device_attribute *attr, const char *buf, size_t size) { + unsigned long old_check_interval = check_interval; ssize_t ret = device_store_int(s, attr, buf, size); + + if (check_interval == old_check_interval) + return ret; + mutex_lock(&mce_sysfs_mutex); mce_restart(); + mutex_unlock(&mce_sysfs_mutex); return ret; } -- 2.16.2