[PATCH] comedi: adv_pci1710: prevent NULL deref in command test

From: Ian Abbott

Date: Wed Nov 25 2026 - 06:04:41 EST


From: Jeehoon Kim <Wlgns2756@xxxxxxxxx>

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.

Signed-off-by: Jeehoon Kim <Wlgns2756@xxxxxxxxx>
Reviewed-by: Ian Abbott <abbotti@xxxxxxxxx>
Fixes: 56556577d9c4 ("staging: comedi: adv_pci1710: don't check the chanlist twice")
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Ian Abbott <abbotti@xxxxxxxxx>
---
drivers/comedi/drivers/adv_pci1710.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/comedi/drivers/adv_pci1710.c b/drivers/comedi/drivers/adv_pci1710.c
index fc749241da416..aa0e56df4d368 100644
--- a/drivers/comedi/drivers/adv_pci1710.c
+++ b/drivers/comedi/drivers/adv_pci1710.c
@@ -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;
--
2.53.0