proc.c (0898782247ae533d1f4e47a06bc5d4870931b284) | proc.c (aefcf2f4b58155d27340ba5f9ddbe9513da8286d) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Procfs interface for the PCI bus 4 * 5 * Copyright (c) 1997--1999 Martin Mares <mj@ucw.cz> 6 */ 7 8#include <linux/init.h> 9#include <linux/pci.h> 10#include <linux/slab.h> 11#include <linux/module.h> 12#include <linux/proc_fs.h> 13#include <linux/seq_file.h> 14#include <linux/capability.h> 15#include <linux/uaccess.h> | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Procfs interface for the PCI bus 4 * 5 * Copyright (c) 1997--1999 Martin Mares <mj@ucw.cz> 6 */ 7 8#include <linux/init.h> 9#include <linux/pci.h> 10#include <linux/slab.h> 11#include <linux/module.h> 12#include <linux/proc_fs.h> 13#include <linux/seq_file.h> 14#include <linux/capability.h> 15#include <linux/uaccess.h> |
16#include <linux/security.h> |
|
16#include <asm/byteorder.h> 17#include "pci.h" 18 19static int proc_initialized; /* = 0 */ 20 21static loff_t proc_bus_pci_lseek(struct file *file, loff_t off, int whence) 22{ 23 struct pci_dev *dev = PDE_DATA(file_inode(file)); --- 86 unchanged lines hidden (view full) --- 110 111static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf, 112 size_t nbytes, loff_t *ppos) 113{ 114 struct inode *ino = file_inode(file); 115 struct pci_dev *dev = PDE_DATA(ino); 116 int pos = *ppos; 117 int size = dev->cfg_size; | 17#include <asm/byteorder.h> 18#include "pci.h" 19 20static int proc_initialized; /* = 0 */ 21 22static loff_t proc_bus_pci_lseek(struct file *file, loff_t off, int whence) 23{ 24 struct pci_dev *dev = PDE_DATA(file_inode(file)); --- 86 unchanged lines hidden (view full) --- 111 112static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf, 113 size_t nbytes, loff_t *ppos) 114{ 115 struct inode *ino = file_inode(file); 116 struct pci_dev *dev = PDE_DATA(ino); 117 int pos = *ppos; 118 int size = dev->cfg_size; |
118 int cnt; | 119 int cnt, ret; |
119 | 120 |
121 ret = security_locked_down(LOCKDOWN_PCI_ACCESS); 122 if (ret) 123 return ret; 124 |
|
120 if (pos >= size) 121 return 0; 122 if (nbytes >= size) 123 nbytes = size; 124 if (pos + nbytes > size) 125 nbytes = size - pos; 126 cnt = nbytes; 127 --- 63 unchanged lines hidden (view full) --- 191 unsigned long arg) 192{ 193 struct pci_dev *dev = PDE_DATA(file_inode(file)); 194#ifdef HAVE_PCI_MMAP 195 struct pci_filp_private *fpriv = file->private_data; 196#endif /* HAVE_PCI_MMAP */ 197 int ret = 0; 198 | 125 if (pos >= size) 126 return 0; 127 if (nbytes >= size) 128 nbytes = size; 129 if (pos + nbytes > size) 130 nbytes = size - pos; 131 cnt = nbytes; 132 --- 63 unchanged lines hidden (view full) --- 196 unsigned long arg) 197{ 198 struct pci_dev *dev = PDE_DATA(file_inode(file)); 199#ifdef HAVE_PCI_MMAP 200 struct pci_filp_private *fpriv = file->private_data; 201#endif /* HAVE_PCI_MMAP */ 202 int ret = 0; 203 |
204 ret = security_locked_down(LOCKDOWN_PCI_ACCESS); 205 if (ret) 206 return ret; 207 |
|
199 switch (cmd) { 200 case PCIIOC_CONTROLLER: 201 ret = pci_domain_nr(dev->bus); 202 break; 203 204#ifdef HAVE_PCI_MMAP 205 case PCIIOC_MMAP_IS_IO: 206 if (!arch_can_pci_mmap_io()) --- 26 unchanged lines hidden (view full) --- 233 234#ifdef HAVE_PCI_MMAP 235static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) 236{ 237 struct pci_dev *dev = PDE_DATA(file_inode(file)); 238 struct pci_filp_private *fpriv = file->private_data; 239 int i, ret, write_combine = 0, res_bit = IORESOURCE_MEM; 240 | 208 switch (cmd) { 209 case PCIIOC_CONTROLLER: 210 ret = pci_domain_nr(dev->bus); 211 break; 212 213#ifdef HAVE_PCI_MMAP 214 case PCIIOC_MMAP_IS_IO: 215 if (!arch_can_pci_mmap_io()) --- 26 unchanged lines hidden (view full) --- 242 243#ifdef HAVE_PCI_MMAP 244static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) 245{ 246 struct pci_dev *dev = PDE_DATA(file_inode(file)); 247 struct pci_filp_private *fpriv = file->private_data; 248 int i, ret, write_combine = 0, res_bit = IORESOURCE_MEM; 249 |
241 if (!capable(CAP_SYS_RAWIO)) | 250 if (!capable(CAP_SYS_RAWIO) || 251 security_locked_down(LOCKDOWN_PCI_ACCESS)) |
242 return -EPERM; 243 244 if (fpriv->mmap_state == pci_mmap_io) { 245 if (!arch_can_pci_mmap_io()) 246 return -EINVAL; 247 res_bit = IORESOURCE_IO; 248 } 249 --- 202 unchanged lines hidden --- | 252 return -EPERM; 253 254 if (fpriv->mmap_state == pci_mmap_io) { 255 if (!arch_can_pci_mmap_io()) 256 return -EINVAL; 257 res_bit = IORESOURCE_IO; 258 } 259 --- 202 unchanged lines hidden --- |