Skip to content

Commit

Permalink
add toggle for disabling newly added USB devices
Browse files Browse the repository at this point in the history
Based on the public grsecurity patches.

Note: not for submission upstream and may be removed once CopperheadOS
is migrated to another mechanism for this.
  • Loading branch information
thestinger committed Jan 28, 2018
1 parent ebfb467 commit 9310bdb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/usb/core/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#define USB_VENDOR_GENESYS_LOGIC 0x05e3
#define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01

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. */
Expand Down Expand Up @@ -4811,6 +4813,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
Expand Down
15 changes: 15 additions & 0 deletions kernel/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
#if defined(CONFIG_SYSCTL)

/* External variables not in a header file. */
#if IS_ENABLED(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;
Expand Down Expand Up @@ -891,6 +895,17 @@ static struct ctl_table kern_table[] = {
.extra1 = &zero,
.extra2 = &one,
},
#if IS_ENABLED(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",
.data = &ngroups_max,
Expand Down

0 comments on commit 9310bdb

Please sign in to comment.