Add toggle for disabling newly added USB devices
authorDaniel Micay <danielmicay@gmail.com>
Tue, 16 May 2017 21:51:48 +0000 (17:51 -0400)
committerNolen Johnson <johnsonnolen@gmail.com>
Wed, 22 Dec 2021 02:21:18 +0000 (21:21 -0500)
Based on the public grsecurity patches.

Change-Id: I2cbea91b351cda7d098f4e1aa73dff1acbd23cce
Signed-off-by: Daniel Micay <danielmicay@gmail.com>
drivers/usb/core/hub.c
kernel/sysctl.c

index 9c22d453787b2228d172bd79776808c8ee57b1a5..1d12e9dff88f68402536fa114fa440c39f7767f0 100644 (file)
@@ -40,6 +40,8 @@ static char *device_enum_fail[2]    = {
 "USB_DEVICE_STATE=Device no response", NULL };
 #endif
 
+extern int deny_new_usb;
+
 /* Protect struct usb_device->state and ->children members
  * Note: Both are also protected by ->dev.sem, except that ->state can
  * change to USB_STATE_NOTATTACHED even when the semaphore isn't held. */
@@ -4854,6 +4856,12 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
                        goto done;
                return;
        }
+
+       if (deny_new_usb) {
+               dev_err(&port_dev->dev, "denied insert of USB device on port %d\n", port1);
+               goto done;
+       }
+
        if (hub_is_superspeed(hub->hdev))
                unit_load = 150;
        else
index 2855b4f0fc1c0def38e9c226385edfa2c851d813..66c8e88db531686b69608083e53d5d47f226645f 100644 (file)
 #if defined(CONFIG_SYSCTL)
 
 /* External variables not in a header file. */
+#ifdef CONFIG_USB
+int deny_new_usb __read_mostly = 0;
+EXPORT_SYMBOL(deny_new_usb);
+#endif
 extern int suid_dumpable;
 #ifdef CONFIG_COREDUMP
 extern int core_uses_pid;
@@ -901,6 +905,17 @@ static struct ctl_table kern_table[] = {
                .extra1         = &zero,
                .extra2         = &two,
        },
+#endif
+#ifdef CONFIG_USB
+       {
+               .procname       = "deny_new_usb",
+               .data           = &deny_new_usb,
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = proc_dointvec_minmax_sysadmin,
+               .extra1         = &zero,
+               .extra2         = &one,
+       },
 #endif
        {
                .procname       = "ngroups_max",