public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matteo Croce <mcroce@redhat.com>
To: x86@kernel.org, LKML <linux-kernel@vger.kernel.org>,
	linux-sound@vger.kernel.org, platform-driver-x86@vger.kernel.org
Subject: [PATCH 5/4] procfs: utility handler to trigger different errors
Date: Mon,  1 Apr 2019 12:24:56 +0200	[thread overview]
Message-ID: <20190401102456.11162-6-mcroce@redhat.com> (raw)
In-Reply-To: <20190401102456.11162-1-mcroce@redhat.com>

Add a /proc/crashtest handler which triggers different kernel errors.
Just write a single character (if many are written, only the first one
is read), to trigger different errors:
- p: raise a kernel panic
- w: generate a warning
- o: raise an oops
The handler permissions are set to 0220 to avoid non root users to crash
the system.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
---
 fs/proc/Makefile    |  1 +
 fs/proc/crashtest.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 fs/proc/crashtest.c

diff --git a/fs/proc/Makefile b/fs/proc/Makefile
index ead487e80510..df99d3245ad9 100644
--- a/fs/proc/Makefile
+++ b/fs/proc/Makefile
@@ -15,6 +15,7 @@ proc-$(CONFIG_TTY)      += proc_tty.o
 proc-y	+= cmdline.o
 proc-y	+= consoles.o
 proc-y	+= cpuinfo.o
+proc-y	+= crashtest.o
 proc-y	+= devices.o
 proc-y	+= interrupts.o
 proc-y	+= loadavg.o
diff --git a/fs/proc/crashtest.c b/fs/proc/crashtest.c
new file mode 100644
index 000000000000..ad7d21cc9d98
--- /dev/null
+++ b/fs/proc/crashtest.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/fs.h>
+#include <linux/init.h>
+#include <linux/proc_fs.h>
+#include <linux/uaccess.h>
+
+static ssize_t crashtest_write(struct file *file, const char __user *buf,
+			       size_t count, loff_t *ppos)
+{
+	char cmd;
+
+	if (!count)
+		return 0;
+
+	if (get_user(cmd, buf))
+		return -EFAULT;
+
+	switch (cmd) {
+	case 'p':
+		panic("crashtest");
+		break;
+	case 'w':
+		WARN(1, "crashtest");
+		break;
+	case 'o':
+		*(int*)0 = 0;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return count;
+}
+
+static const struct file_operations proc_crashtest_ops = {
+	.write	= crashtest_write,
+};
+
+static int __init proc_crashtest_init(void)
+{
+	return !proc_create("crashtest", 0220, NULL, &proc_crashtest_ops);
+}
+fs_initcall(proc_crashtest_init);
-- 
2.20.1


  parent reply	other threads:[~2019-04-01 10:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01 10:24 [PATCH 0/4] Introduce the aural error reporting framework Matteo Croce
2019-04-01 10:24 ` [PATCH 1/4] " Matteo Croce
2019-04-01 10:24 ` [PATCH 2/4] panic: use the aural error reporting framework to report panics Matteo Croce
2019-04-01 10:24 ` [PATCH 3/4] bug: use the aural error reporting framework to report warnings Matteo Croce
2019-04-01 10:24 ` [PATCH 4/4] oops: use the aural error reporting framework to report oopses Matteo Croce
2019-04-01 10:24 ` Matteo Croce [this message]
2019-04-01 11:03 ` [PATCH 0/4] Introduce the aural error reporting framework Peter Zijlstra
2019-04-02  8:49   ` Thomas Gleixner
2019-04-02 11:50     ` Matteo Croce
2019-04-02 13:21       ` Thomas Gleixner
2019-04-01 13:45 ` Emiliano Russo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190401102456.11162-6-mcroce@redhat.com \
    --to=mcroce@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox