lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1581062166-27284-1-git-send-email-shenkai8@huawei.com>
Date:   Fri, 7 Feb 2020 07:56:06 +0000
From:   Shen Kai <shenkai8@...wei.com>
To:     <gregkh@...uxfoundation.org>, <jslaby@...e.com>
CC:     <linux-kernel@...r.kernel.org>, <hushiyuan@...wei.com>,
        <linfeilong@...wei.com>
Subject: [PATCH] add lock proctect to __handle_sysrq in write_sysrq_trigger

From: Feilong Lin <linfeilong@...wei.com>

Add lock protect to __handle_sysrq to avoid race condition.
__handle_sysrq will change console_loglevel without lock protect
which can lead to console_loglevel to be set as an unexpected value.

Problem may occur when "echo t > /proc/sysrq-trigger" is called on 
multiple cpus concurrently.

In this case in __handle_sysrq, console_loglevel is set to 7 to print
some head info to the console then restore it. But without lock protect
in parallel execution situation, restoring may go wrong. The new 
loglevel may be taken as the previous loglevel incorrectly.
Console_loglevel can be 7 at last, which causes the terminal to output
info in most log levels.

This bug was found on linux 4.19

Signed-off-by: Feilong Lin <linfeilong@...wei.com>
Reported-by: Kai Shen <shenkai8@...wei.com>
---
 drivers/tty/sysrq.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index f724962..cbb48a9 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -1087,6 +1087,8 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
  */
+static DEFINE_MUTEX(sysrq_mutex);
+
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
@@ -1095,7 +1097,9 @@ static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 
 		if (get_user(c, buf))
 			return -EFAULT;
+		mutex_lock(&sysrq_mutex);
 		__handle_sysrq(c, false);
+		mutex_unlock(&sysrq_mutex);
 	}
 
 	return count;
-- 
2.6.4.windows.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ