提交 6ba18636 编写于 作者: J Jean Delvare 提交者: Greg Kroah-Hartman

PCI: Require vendor and device for new_id

Currently, there is no minimum number of fields required when adding
a new device ID to a PCI driver through the new_id sysfs file. It is
possible to add a new ID with only the vendor ID set, causing the
driver to attempt to attach to all PCI devices from that vendor. This
has been reported to happen accidentally:
  http://lists.lm-sensors.org/pipermail/lm-sensors/2007-March/019366.html
It is even possible to not even set the vendor ID field, causing the
driver to attempt to attach to _all_ the PCI devices.

This sounds dangerous and I fail to see any valid use of this
"feature". Thus I suggest that we now require at least the first two
fields (vendor ID and device ID) to be set. For what it's worth, this
is what the USB subsystem does.
Signed-off-by: NJean Delvare <khali@linux-fr.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 40ee9e9f
...@@ -163,9 +163,9 @@ echo "vendor device subvendor subdevice class class_mask driver_data" > \ ...@@ -163,9 +163,9 @@ echo "vendor device subvendor subdevice class class_mask driver_data" > \
/sys/bus/pci/drivers/{driver}/new_id /sys/bus/pci/drivers/{driver}/new_id
All fields are passed in as hexadecimal values (no leading 0x). All fields are passed in as hexadecimal values (no leading 0x).
Users need pass only as many fields as necessary: The vendor and device fields are mandatory, the others are optional. Users
o vendor, device, subvendor, and subdevice fields default need pass only as many optional fields as necessary:
to PCI_ANY_ID (FFFFFFFF), o subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF)
o class and classmask fields default to 0 o class and classmask fields default to 0
o driver_data defaults to 0UL. o driver_data defaults to 0UL.
......
...@@ -52,7 +52,7 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count) ...@@ -52,7 +52,7 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
{ {
struct pci_dynid *dynid; struct pci_dynid *dynid;
struct pci_driver *pdrv = to_pci_driver(driver); struct pci_driver *pdrv = to_pci_driver(driver);
__u32 vendor=PCI_ANY_ID, device=PCI_ANY_ID, subvendor=PCI_ANY_ID, __u32 vendor, device, subvendor=PCI_ANY_ID,
subdevice=PCI_ANY_ID, class=0, class_mask=0; subdevice=PCI_ANY_ID, class=0, class_mask=0;
unsigned long driver_data=0; unsigned long driver_data=0;
int fields=0; int fields=0;
...@@ -61,7 +61,7 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count) ...@@ -61,7 +61,7 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
fields = sscanf(buf, "%x %x %x %x %x %x %lux", fields = sscanf(buf, "%x %x %x %x %x %x %lux",
&vendor, &device, &subvendor, &subdevice, &vendor, &device, &subvendor, &subdevice,
&class, &class_mask, &driver_data); &class, &class_mask, &driver_data);
if (fields < 0) if (fields < 2)
return -EINVAL; return -EINVAL;
dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册