From patchwork Mon Apr 1 10:24:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 10879625 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C036613B5 for ; Mon, 1 Apr 2019 10:26:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A90D028889 for ; Mon, 1 Apr 2019 10:26:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D9AF28849; Mon, 1 Apr 2019 10:26:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DD622888D for ; Mon, 1 Apr 2019 10:26:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726502AbfDAK0B (ORCPT ); Mon, 1 Apr 2019 06:26:01 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37526 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726542AbfDAKZ5 (ORCPT ); Mon, 1 Apr 2019 06:25:57 -0400 Received: by mail-wr1-f68.google.com with SMTP id w10so11265793wrm.4 for ; Mon, 01 Apr 2019 03:25:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2PZs3tnG+oChvFnAzez0PCW1+F33VtcOpKbbfmVAZG8=; b=E4AOuhmKiJOo1SZicy8tpW/3IzL+t9EuzwpCHQbC2zUw0uGMJsDxx1NKlcaIG0Musd 6NmAld2szDeb+yYltO8425FZrUqMBEOZXmHrebSYaOquHUjKEUYewQh6HRt6L8J5Gers LK1z0nzlEO9lZwkqHZPhn+WydMORSdMenfeyCy133Z7ZGIey3QO7Lcy9aJeiUGJ+PxK5 yl8kDnB65J7ph/XhpInGy2jlv8GZ78WE56cGSJOwKxVzeMennMHviROQJVKb+JdOwT/B 9RR32yl+WVwHO7c2SnFEIP/V63OlwmBePBxmUvsk+Y+qWNy0yxoC4ViWAgJ4gBIL96mj isCg== X-Gm-Message-State: APjAAAWYOIIFy4oSXVUuqFN3h8PMFUziFnKQvKsv1/DVzhNdTy2QzssV JiLYS+LAVYFJU/J0rUcMMGGWpA== X-Google-Smtp-Source: APXvYqzq/2GLBNkP55y+Mu/c3hkX+oePOZjy+FkwnJD9W4lHZoCpALJstxLzox2tyuGLChxJdRuGRQ== X-Received: by 2002:a5d:6987:: with SMTP id g7mr28452777wru.299.1554114355255; Mon, 01 Apr 2019 03:25:55 -0700 (PDT) Received: from raver.teknoraver.net (net-93-70-69-135.cust.vodafonedsl.it. [93.70.69.135]) by smtp.gmail.com with ESMTPSA id r9sm8947247wmh.38.2019.04.01.03.25.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Apr 2019 03:25:54 -0700 (PDT) From: Matteo Croce To: x86@kernel.org, LKML , 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 Message-Id: <20190401102456.11162-6-mcroce@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190401102456.11162-1-mcroce@redhat.com> References: <20190401102456.11162-1-mcroce@redhat.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 +#include +#include +#include + +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);