History

PCI/switchtec: Add Gen4 MRPC GAS access permission check

Gen4 hardware provides new MRPC commands to read and write directly from any address in the PCI BAR (which Microsemi refers to as GAS). Since accessing BARs can be dangerous and break the driver, we don't want unprivileged users to have this ability. Therefore, require CAP_SYS_ADMIN for the local and remote GAS access MRPC commands. Privileged processes will already have access to the BAR through the sysfs resource file so this doesn't give userspace any capabilities it didn't already have. [logang@deltatee.com: rework commit message] Link: https://lore.kernel.org/r/20200106190337.2428-11-logang@deltatee.com Signed-off-by: Kelvin Cao <kelvin.cao@microchip.com> Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

Kelvin Cao committed 6 years ago

Commit ce7c8861 parent 4efa1d22 files · +11 −0Browse files

Unified · Split

2 files
  1. drivers/pci/switch/switchtec.c +6 −0
  2. include/linux/switchtec.h +5 −0
drivers/pci/switch/switchtec.c+6−0
@@ -479,6 +479,12 @@ static ssize_t switchtec_dev_write(struct file *filp, const char __user *data, · 478 unmodified lines
479 rc = -EFAULT;479 rc = -EFAULT;
480 goto out;480 goto out;
481 }481 }
482 if (((MRPC_CMD_ID(stuser->cmd) == MRPC_GAS_WRITE) ||
483 (MRPC_CMD_ID(stuser->cmd) == MRPC_GAS_READ)) &&
484 !capable(CAP_SYS_ADMIN)) {
485 rc = -EPERM;
486 goto out;
487 }
482 488
483 data += sizeof(stuser->cmd);489 data += sizeof(stuser->cmd);
484 rc = copy_from_user(&stuser->data, data, size - sizeof(stuser->cmd));490 rc = copy_from_user(&stuser->data, data, size - sizeof(stuser->cmd));
include/linux/switchtec.h+5−0
@@ -21,6 +21,11 @@ · 20 unmodified lines
21#define SWITCHTEC_EVENT_FATAL BIT(4)21#define SWITCHTEC_EVENT_FATAL BIT(4)
22 22
23#define SWITCHTEC_DMA_MRPC_EN BIT(0)23#define SWITCHTEC_DMA_MRPC_EN BIT(0)
24
25#define MRPC_GAS_READ 0x29
26#define MRPC_GAS_WRITE 0x87
27#define MRPC_CMD_ID(x) ((x) & 0xffff)
28
24enum {29enum {
25 SWITCHTEC_GAS_MRPC_OFFSET = 0x0000,30 SWITCHTEC_GAS_MRPC_OFFSET = 0x0000,
26 SWITCHTEC_GAS_TOP_CFG_OFFSET = 0x1000,31 SWITCHTEC_GAS_TOP_CFG_OFFSET = 0x1000,