]> xenbits.xensource.com Git - people/julieng/linux-arm.git/commitdiff
Add sysrq option to disable secure boot mode
authorKyle McMartin <kyle@redhat.com>
Fri, 30 Aug 2013 13:28:51 +0000 (09:28 -0400)
committerJulien Grall <julien.grall@citrix.com>
Fri, 18 Sep 2015 15:29:30 +0000 (16:29 +0100)
Bugzilla: N/A
Upstream-status: Fedora mustard

arch/x86/kernel/setup.c
drivers/input/misc/uinput.c
drivers/tty/sysrq.c
include/linux/input.h
include/linux/sysrq.h
kernel/debug/kdb/kdb_main.c
kernel/module.c

index 5def6b4143fa33b636b0eceeed9fd591f71e8155..1eac9d22cb0b8251d18c1b1a9d1f4d10d70ebef2 100644 (file)
 #include <linux/tboot.h>
 #include <linux/jiffies.h>
 
+#include <linux/fips.h>
+#include <linux/cred.h>
+#include <linux/sysrq.h>
+#include <linux/init_task.h>
+
 #include <video/edid.h>
 
 #include <asm/mtrr.h>
@@ -1286,6 +1291,37 @@ void __init i386_reserve_resources(void)
 
 #endif /* CONFIG_X86_32 */
 
+#ifdef CONFIG_MAGIC_SYSRQ
+#ifdef CONFIG_MODULE_SIG
+extern bool sig_enforce;
+#endif
+
+static void sysrq_handle_secure_boot(int key)
+{
+       if (!efi_enabled(EFI_SECURE_BOOT))
+               return;
+
+       pr_info("Secure boot disabled\n");
+#ifdef CONFIG_MODULE_SIG
+       sig_enforce = fips_enabled;
+#endif
+}
+static struct sysrq_key_op secure_boot_sysrq_op = {
+       .handler        =       sysrq_handle_secure_boot,
+       .help_msg       =       "unSB(x)",
+       .action_msg     =       "Disabling Secure Boot restrictions",
+       .enable_mask    =       SYSRQ_DISABLE_USERSPACE,
+};
+static int __init secure_boot_sysrq(void)
+{
+       if (efi_enabled(EFI_SECURE_BOOT))
+               register_sysrq_key('x', &secure_boot_sysrq_op);
+       return 0;
+}
+late_initcall(secure_boot_sysrq);
+#endif /*CONFIG_MAGIC_SYSRQ*/
+
+
 static struct notifier_block kernel_offset_notifier = {
        .notifier_call = dump_kernel_offset
 };
index 421e29e4cd81130a197d934399bbe69210afa1b4..61c1eb97806c341dd660ee57b4db449a76b3d535 100644 (file)
@@ -366,6 +366,7 @@ static int uinput_allocate_device(struct uinput_device *udev)
        if (!udev->dev)
                return -ENOMEM;
 
+       udev->dev->flags |= INPUTDEV_FLAGS_SYNTHETIC;
        udev->dev->event = uinput_dev_event;
        input_set_drvdata(udev->dev, udev);
 
index b5b427888b2453d88e59f7d002ab8d4e512d23e6..289c7898a3b0d0d7fa14f2d60f65d884ff7f83df 100644 (file)
@@ -465,6 +465,7 @@ static struct sysrq_key_op *sysrq_key_table[36] = {
        /* x: May be registered on mips for TLB dump */
        /* x: May be registered on ppc/powerpc for xmon */
        /* x: May be registered on sparc64 for global PMU dump */
+       /* x: May be registered on x86_64 for disabling secure boot */
        NULL,                           /* x */
        /* y: May be registered on sparc64 for global register dump */
        NULL,                           /* y */
@@ -508,7 +509,7 @@ static void __sysrq_put_key_op(int key, struct sysrq_key_op *op_p)
                 sysrq_key_table[i] = op_p;
 }
 
-void __handle_sysrq(int key, bool check_mask)
+void __handle_sysrq(int key, int from)
 {
        struct sysrq_key_op *op_p;
        int orig_log_level;
@@ -528,11 +529,15 @@ void __handle_sysrq(int key, bool check_mask)
 
         op_p = __sysrq_get_key_op(key);
         if (op_p) {
+               /* Ban synthetic events from some sysrq functionality */
+               if ((from == SYSRQ_FROM_PROC || from == SYSRQ_FROM_SYNTHETIC) &&
+                   op_p->enable_mask & SYSRQ_DISABLE_USERSPACE)
+                       printk("This sysrq operation is disabled from userspace.\n");
                /*
                 * Should we check for enabled operations (/proc/sysrq-trigger
                 * should not) and is the invoked operation enabled?
                 */
-               if (!check_mask || sysrq_on_mask(op_p->enable_mask)) {
+               if (from == SYSRQ_FROM_KERNEL || sysrq_on_mask(op_p->enable_mask)) {
                        pr_cont("%s\n", op_p->action_msg);
                        console_loglevel = orig_log_level;
                        op_p->handler(key);
@@ -564,7 +569,7 @@ void __handle_sysrq(int key, bool check_mask)
 void handle_sysrq(int key)
 {
        if (sysrq_on())
-               __handle_sysrq(key, true);
+               __handle_sysrq(key, SYSRQ_FROM_KERNEL);
 }
 EXPORT_SYMBOL(handle_sysrq);
 
@@ -645,7 +650,7 @@ static void sysrq_do_reset(unsigned long _state)
 static void sysrq_handle_reset_request(struct sysrq_state *state)
 {
        if (state->reset_requested)
-               __handle_sysrq(sysrq_xlate[KEY_B], false);
+               __handle_sysrq(sysrq_xlate[KEY_B], SYSRQ_FROM_KERNEL);
 
        if (sysrq_reset_downtime_ms)
                mod_timer(&state->keyreset_timer,
@@ -796,8 +801,10 @@ static bool sysrq_handle_keypress(struct sysrq_state *sysrq,
 
        default:
                if (sysrq->active && value && value != 2) {
+                       int from = sysrq->handle.dev->flags & INPUTDEV_FLAGS_SYNTHETIC ?
+                                       SYSRQ_FROM_SYNTHETIC : 0;
                        sysrq->need_reinject = false;
-                       __handle_sysrq(sysrq_xlate[code], true);
+                       __handle_sysrq(sysrq_xlate[code], from);
                }
                break;
        }
@@ -1077,7 +1084,7 @@ static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 
                if (get_user(c, buf))
                        return -EFAULT;
-               __handle_sysrq(c, false);
+               __handle_sysrq(c, SYSRQ_FROM_PROC);
        }
 
        return count;
index 82ce323b998692b9c3d0b95b762605e51147cafd..9e534f228945fb06a3e39d35838d1a165b0dce7b 100644 (file)
@@ -42,6 +42,7 @@ struct input_value {
  * @phys: physical path to the device in the system hierarchy
  * @uniq: unique identification code for the device (if device has it)
  * @id: id of the device (struct input_id)
+ * @flags: input device flags (SYNTHETIC, etc.)
  * @propbit: bitmap of device properties and quirks
  * @evbit: bitmap of types of events supported by the device (EV_KEY,
  *     EV_REL, etc.)
@@ -124,6 +125,8 @@ struct input_dev {
        const char *uniq;
        struct input_id id;
 
+       unsigned int flags;
+
        unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
 
        unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
@@ -190,6 +193,8 @@ struct input_dev {
 };
 #define to_input_dev(d) container_of(d, struct input_dev, dev)
 
+#define        INPUTDEV_FLAGS_SYNTHETIC        0x000000001
+
 /*
  * Verify that we are in sync with input_device_id mod_devicetable.h #defines
  */
index 387fa7d05c982b758942f83395e328949324fc1a..4b07e30b32793d1bb7b1b59a0f99b24feb055a89 100644 (file)
@@ -28,6 +28,8 @@
 #define SYSRQ_ENABLE_BOOT      0x0080
 #define SYSRQ_ENABLE_RTNICE    0x0100
 
+#define SYSRQ_DISABLE_USERSPACE        0x00010000
+
 struct sysrq_key_op {
        void (*handler)(int);
        char *help_msg;
@@ -42,8 +44,12 @@ struct sysrq_key_op {
  * are available -- else NULL's).
  */
 
+#define SYSRQ_FROM_KERNEL      0x0001
+#define SYSRQ_FROM_PROC                0x0002
+#define SYSRQ_FROM_SYNTHETIC   0x0004
+
 void handle_sysrq(int key);
-void __handle_sysrq(int key, bool check_mask);
+void __handle_sysrq(int key, int from);
 int register_sysrq_key(int key, struct sysrq_key_op *op);
 int unregister_sysrq_key(int key, struct sysrq_key_op *op);
 struct sysrq_key_op *__sysrq_get_key_op(int key);
index 4121345498e0e48f10b414a4b12e0b5f15daeabd..0ff3cef5df966bef0b5a379f29c1c799d88f6cbb 100644 (file)
@@ -1968,7 +1968,7 @@ static int kdb_sr(int argc, const char **argv)
                return KDB_ARGCOUNT;
 
        kdb_trap_printk++;
-       __handle_sysrq(*argv[1], check_mask);
+       __handle_sysrq(*argv[1], check_mask & SYSRQ_FROM_KERNEL);
        kdb_trap_printk--;
 
        return 0;
index 2b403ab0ef294a2b8a2586ae3ef7925c76d97539..7818c110e95ce347f7a76ad2314aab578124a3c6 100644 (file)
@@ -292,7 +292,7 @@ static void module_assert_mutex_or_preempt(void)
 #endif
 }
 
-static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
+bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
 #ifndef CONFIG_MODULE_SIG_FORCE
 module_param(sig_enforce, bool_enable_only, 0644);
 #endif /* !CONFIG_MODULE_SIG_FORCE */