| .. | .. |
|---|
| 13 | 13 | #include <linux/seq_file.h> |
|---|
| 14 | 14 | #include <linux/capability.h> |
|---|
| 15 | 15 | #include <linux/uaccess.h> |
|---|
| 16 | +#include <linux/security.h> |
|---|
| 16 | 17 | #include <asm/byteorder.h> |
|---|
| 17 | 18 | #include "pci.h" |
|---|
| 18 | 19 | |
|---|
| .. | .. |
|---|
| 52 | 53 | nbytes = size - pos; |
|---|
| 53 | 54 | cnt = nbytes; |
|---|
| 54 | 55 | |
|---|
| 55 | | - if (!access_ok(VERIFY_WRITE, buf, cnt)) |
|---|
| 56 | + if (!access_ok(buf, cnt)) |
|---|
| 56 | 57 | return -EINVAL; |
|---|
| 57 | 58 | |
|---|
| 58 | 59 | pci_config_pm_runtime_get(dev); |
|---|
| .. | .. |
|---|
| 115 | 116 | struct pci_dev *dev = PDE_DATA(ino); |
|---|
| 116 | 117 | int pos = *ppos; |
|---|
| 117 | 118 | int size = dev->cfg_size; |
|---|
| 118 | | - int cnt; |
|---|
| 119 | + int cnt, ret; |
|---|
| 120 | + |
|---|
| 121 | + ret = security_locked_down(LOCKDOWN_PCI_ACCESS); |
|---|
| 122 | + if (ret) |
|---|
| 123 | + return ret; |
|---|
| 119 | 124 | |
|---|
| 120 | 125 | if (pos >= size) |
|---|
| 121 | 126 | return 0; |
|---|
| .. | .. |
|---|
| 125 | 130 | nbytes = size - pos; |
|---|
| 126 | 131 | cnt = nbytes; |
|---|
| 127 | 132 | |
|---|
| 128 | | - if (!access_ok(VERIFY_READ, buf, cnt)) |
|---|
| 133 | + if (!access_ok(buf, cnt)) |
|---|
| 129 | 134 | return -EINVAL; |
|---|
| 130 | 135 | |
|---|
| 131 | 136 | pci_config_pm_runtime_get(dev); |
|---|
| .. | .. |
|---|
| 196 | 201 | #endif /* HAVE_PCI_MMAP */ |
|---|
| 197 | 202 | int ret = 0; |
|---|
| 198 | 203 | |
|---|
| 204 | + ret = security_locked_down(LOCKDOWN_PCI_ACCESS); |
|---|
| 205 | + if (ret) |
|---|
| 206 | + return ret; |
|---|
| 207 | + |
|---|
| 199 | 208 | switch (cmd) { |
|---|
| 200 | 209 | case PCIIOC_CONTROLLER: |
|---|
| 201 | 210 | ret = pci_domain_nr(dev->bus); |
|---|
| .. | .. |
|---|
| 222 | 231 | } |
|---|
| 223 | 232 | /* If arch decided it can't, fall through... */ |
|---|
| 224 | 233 | #endif /* HAVE_PCI_MMAP */ |
|---|
| 234 | + fallthrough; |
|---|
| 225 | 235 | default: |
|---|
| 226 | 236 | ret = -EINVAL; |
|---|
| 227 | 237 | break; |
|---|
| .. | .. |
|---|
| 237 | 247 | struct pci_filp_private *fpriv = file->private_data; |
|---|
| 238 | 248 | int i, ret, write_combine = 0, res_bit = IORESOURCE_MEM; |
|---|
| 239 | 249 | |
|---|
| 240 | | - if (!capable(CAP_SYS_RAWIO)) |
|---|
| 250 | + if (!capable(CAP_SYS_RAWIO) || |
|---|
| 251 | + security_locked_down(LOCKDOWN_PCI_ACCESS)) |
|---|
| 241 | 252 | return -EPERM; |
|---|
| 242 | 253 | |
|---|
| 243 | 254 | if (fpriv->mmap_state == pci_mmap_io) { |
|---|
| .. | .. |
|---|
| 247 | 258 | } |
|---|
| 248 | 259 | |
|---|
| 249 | 260 | /* Make sure the caller is mapping a real resource for this device */ |
|---|
| 250 | | - for (i = 0; i < PCI_ROM_RESOURCE; i++) { |
|---|
| 261 | + for (i = 0; i < PCI_STD_NUM_BARS; i++) { |
|---|
| 251 | 262 | if (dev->resource[i].flags & res_bit && |
|---|
| 252 | 263 | pci_mmap_fits(dev, i, vma, PCI_MMAP_PROCFS)) |
|---|
| 253 | 264 | break; |
|---|
| 254 | 265 | } |
|---|
| 255 | 266 | |
|---|
| 256 | | - if (i >= PCI_ROM_RESOURCE) |
|---|
| 267 | + if (i >= PCI_STD_NUM_BARS) |
|---|
| 257 | 268 | return -ENODEV; |
|---|
| 258 | 269 | |
|---|
| 259 | 270 | if (fpriv->mmap_state == pci_mmap_mem && |
|---|
| .. | .. |
|---|
| 295 | 306 | } |
|---|
| 296 | 307 | #endif /* HAVE_PCI_MMAP */ |
|---|
| 297 | 308 | |
|---|
| 298 | | -static const struct file_operations proc_bus_pci_operations = { |
|---|
| 299 | | - .owner = THIS_MODULE, |
|---|
| 300 | | - .llseek = proc_bus_pci_lseek, |
|---|
| 301 | | - .read = proc_bus_pci_read, |
|---|
| 302 | | - .write = proc_bus_pci_write, |
|---|
| 303 | | - .unlocked_ioctl = proc_bus_pci_ioctl, |
|---|
| 304 | | - .compat_ioctl = proc_bus_pci_ioctl, |
|---|
| 309 | +static const struct proc_ops proc_bus_pci_ops = { |
|---|
| 310 | + .proc_lseek = proc_bus_pci_lseek, |
|---|
| 311 | + .proc_read = proc_bus_pci_read, |
|---|
| 312 | + .proc_write = proc_bus_pci_write, |
|---|
| 313 | + .proc_ioctl = proc_bus_pci_ioctl, |
|---|
| 314 | +#ifdef CONFIG_COMPAT |
|---|
| 315 | + .proc_compat_ioctl = proc_bus_pci_ioctl, |
|---|
| 316 | +#endif |
|---|
| 305 | 317 | #ifdef HAVE_PCI_MMAP |
|---|
| 306 | | - .open = proc_bus_pci_open, |
|---|
| 307 | | - .release = proc_bus_pci_release, |
|---|
| 308 | | - .mmap = proc_bus_pci_mmap, |
|---|
| 318 | + .proc_open = proc_bus_pci_open, |
|---|
| 319 | + .proc_release = proc_bus_pci_release, |
|---|
| 320 | + .proc_mmap = proc_bus_pci_mmap, |
|---|
| 309 | 321 | #ifdef HAVE_ARCH_PCI_GET_UNMAPPED_AREA |
|---|
| 310 | | - .get_unmapped_area = get_pci_unmapped_area, |
|---|
| 322 | + .proc_get_unmapped_area = get_pci_unmapped_area, |
|---|
| 311 | 323 | #endif /* HAVE_ARCH_PCI_GET_UNMAPPED_AREA */ |
|---|
| 312 | 324 | #endif /* HAVE_PCI_MMAP */ |
|---|
| 313 | 325 | }; |
|---|
| .. | .. |
|---|
| 376 | 388 | } |
|---|
| 377 | 389 | seq_putc(m, '\t'); |
|---|
| 378 | 390 | if (drv) |
|---|
| 379 | | - seq_printf(m, "%s", drv->name); |
|---|
| 391 | + seq_puts(m, drv->name); |
|---|
| 380 | 392 | seq_putc(m, '\n'); |
|---|
| 381 | 393 | return 0; |
|---|
| 382 | 394 | } |
|---|
| .. | .. |
|---|
| 413 | 425 | |
|---|
| 414 | 426 | sprintf(name, "%02x.%x", PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); |
|---|
| 415 | 427 | e = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR, bus->procdir, |
|---|
| 416 | | - &proc_bus_pci_operations, dev); |
|---|
| 428 | + &proc_bus_pci_ops, dev); |
|---|
| 417 | 429 | if (!e) |
|---|
| 418 | 430 | return -ENOMEM; |
|---|
| 419 | 431 | proc_set_size(e, dev->cfg_size); |
|---|