Skip to contentSkip to conversation

comedi: dt2815: add hardware detection to prevent crash

PATCH In review Deepanshu Kartikey 1 participant 3 messages Mar 9 – Mar 31 Comedi drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 comedi: dt2815: add hardware detection to prevent crash

The dt2815 driver crashes when attached to I/O ports without actual hardware present. This occurs because syzkaller or users can attach the driver to arbitrary I/O addresses via COMEDI_DEVCONFIG ioctl.

When no hardware exists at the specified port, inb() operations return 0xff (floating bus), but outb() operations can trigger page faults due to undefined behavior, especially under race conditions:

  BUG: unable to handle page fault for address: 000000007fffff90
  #PF: supervisor write access in kernel mode
  #PF: error_code(0x0002) - not-present page
  RIP: 0010:dt2815_attach+0x6e0/0x1110

Add hardware detection by reading the status register before attempting any write operations. If the read returns 0xff, assume no hardware is present and fail the attach with -ENODEV. This prevents crashes from outb() operations on non-existent hardware.

---
 drivers/comedi/drivers/dt2815.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/comedi/drivers/dt2815.c +12 -0
index 03ba2fd18a21..7c642860f127 100644
@@ -175,6 +175,18 @@ static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 		    ? current_range_type : voltage_range_type;
 	}
 
+	/*
+	 * Check if hardware is present before attempting any I/O operations.
+	 * Reading 0xff from status register typically indicates no hardware
+	 * on the bus (floating bus reads as all 1s).
+	 */
+	if (inb(dev->iobase + DT2815_STATUS) == 0xff) {
+		dev_err(dev->class_dev,
+			"No hardware detected at I/O base 0x%lx\n",
+			dev->iobase);
+		return -ENODEV;
+	}
+
 	/* Init the 2815 */
 	outb(0x00, dev->iobase + DT2815_STATUS);
 	for (i = 0; i < 100; i++) {
Signature · 1 line
2.43.0
#1 lore raw
Quoted 52 lines · Deepanshu Kartikey

The dt2815 driver crashes when attached to I/O ports without actual hardware present. This occurs because syzkaller or users can attach the driver to arbitrary I/O addresses via COMEDI_DEVCONFIG ioctl.

When no hardware exists at the specified port, inb() operations return 0xff (floating bus), but outb() operations can trigger page faults due to undefined behavior, especially under race conditions:

  BUG: unable to handle page fault for address: 000000007fffff90
  #PF: supervisor write access in kernel mode
  #PF: error_code(0x0002) - not-present page
  RIP: 0010:dt2815_attach+0x6e0/0x1110

Add hardware detection by reading the status register before attempting any write operations. If the read returns 0xff, assume no hardware is present and fail the attach with -ENODEV. This prevents crashes from outb() operations on non-existent hardware.

---
 drivers/comedi/drivers/dt2815.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/comedi/drivers/dt2815.c +12 -1
index 03ba2fd18a21..7c642860f127 100644
@@ -175,6 +175,18 @@ static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                    ? current_range_type : voltage_range_type;
        }
 
+       /*
+        * Check if hardware is present before attempting any I/O operations.
+        * Reading 0xff from status register typically indicates no hardware
+        * on the bus (floating bus reads as all 1s).
+        */
+       if (inb(dev->iobase + DT2815_STATUS) == 0xff) {
+               dev_err(dev->class_dev,
+                       "No hardware detected at I/O base 0x%lx\n",
+                       dev->iobase);
+               return -ENODEV;
+       }
+
        /* Init the 2815 */
        outb(0x00, dev->iobase + DT2815_STATUS);
        for (i = 0; i < 100; i++) {
--
Quoted 2 lines

2.43.0

Hi Greg,

Gentle ping on this patch. This patch was submitted on 26th jan 2026. It. It is Reviewed-by: Ian Abbott <[email protected]>

Subject: [PATCH] comedi: dt2815: add hardware
detection to prevent crash

Let me know if any changes required.

Thanks

#2 lore raw
Quoted 48 lines · Deepanshu Kartikey
Quoted 46 lines · Deepanshu Kartikey

The dt2815 driver crashes when attached to I/O ports without actual hardware present. This occurs because syzkaller or users can attach the driver to arbitrary I/O addresses via COMEDI_DEVCONFIG ioctl.

When no hardware exists at the specified port, inb() operations return 0xff (floating bus), but outb() operations can trigger page faults due to undefined behavior, especially under race conditions:

  BUG: unable to handle page fault for address: 000000007fffff90
  #PF: supervisor write access in kernel mode
  #PF: error_code(0x0002) - not-present page
  RIP: 0010:dt2815_attach+0x6e0/0x1110

Add hardware detection by reading the status register before attempting any write operations. If the read returns 0xff, assume no hardware is present and fail the attach with -ENODEV. This prevents crashes from outb() operations on non-existent hardware.

---
 drivers/comedi/drivers/dt2815.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/comedi/drivers/dt2815.c +10 -0
index 03ba2fd18a21..7c642860f127 100644
@@ -175,6 +175,18 @@ static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                    ? current_range_type : voltage_range_type;
        }
 
+       /*
+        * Check if hardware is present before attempting any I/O operations.
+        * Reading 0xff from status register typically indicates no hardware
+        * on the bus (floating bus reads as all 1s).
+        */
+       if (inb(dev->iobase + DT2815_STATUS) == 0xff) {
+               dev_err(dev->class_dev,
+                       "No hardware detected at I/O base 0x%lx\n",
+                       dev->iobase);
+               return -ENODEV;
Quoted 10 lines
Quoted 8 lines
drivers/comedi/drivers/dt2815.c +2 -1
+       }
+
        /* Init the 2815 */
        outb(0x00, dev->iobase + DT2815_STATUS);
        for (i = 0; i < 100; i++) {
--

2.43.0

Hi Greg,
Gentle ping on this patch . I submitted this patch on 26th jan 2026. It is reviewed by : Reviewed-by: Ian Abbott <[email protected]>

Please let me know if anything else required to get it merged

Thanks

Deepanshu