Skip to contentSkip to conversation

comedi: adv_pci1710: prevent NULL deref in command test

PATCH New Ian Abbott 1 participant 1 message Nov 25

Subsystems (2)
lore
Share & tools
lore

Ian Abbott

author maintainer
#0 lore raw

PATCH 1/1 comedi: adv_pci1710: prevent NULL deref in command test

From: Jeehoon Kim <[email protected]>

The COMEDI_CMDTEST ioctl permits a NULL channel list: do_cmdtest_ioctl() only loads and validates the channel list when the user-supplied pointer is non-NULL, otherwise it calls the subdevice's ->do_cmdtest() handler with cmd->chanlist == NULL (and cmd->chanlist_len still bounded only by len_chanlist).

pci1710_ai_cmdtest() calls pci1710_ai_check_chanlist() unconditionally in step 5, and that helper dereferences cmd->chanlist[0] on its first lines (CR_CHAN()/CR_AREF()). A user issuing COMEDI_CMDTEST with a NULL chanlist pointer therefore triggers a NULL pointer dereference.

Every other comedi driver guards the step 5 check with
"if (cmd->chanlist && cmd->chanlist_len > 0)"; adv_pci1710 was missed. Add the same guard.

Fixes 56556577d9c4 ("staging: comedi: adv_pci1710: don't check the chanlist twice")
---
 drivers/comedi/drivers/adv_pci1710.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/comedi/drivers/adv_pci1710.c +3 -3
index fc749241da416..aa0e56df4d368 100644
@@ -621,9 +621,9 @@ static int pci1710_ai_cmdtest(struct comedi_device *dev,
 	if (err)
 		return 4;
 
-	/* Step 5: check channel list */
-
-	err |= pci1710_ai_check_chanlist(dev, s, cmd);
+	/* Step 5: check channel list if it exists */
+	if (cmd->chanlist && cmd->chanlist_len > 0)
+		err |= pci1710_ai_check_chanlist(dev, s, cmd);
 
 	if (err)
 		return 5;
Signature · 1 line
2.53.0