Skip to content

Commit ef75e14

Browse files
Dan Carpentergregkh
authored andcommitted
staging: comedi: verify array index is correct before using it
This code reads from the array before verifying that "trig" is a valid index. If the index is wildly out of bounds then reading from an invalid address could lead to an Oops. Fixes: a8c66b6 ("staging: comedi: addi_apci_1500: rewrite the subdevice support functions") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Ian Abbott <[email protected]> Link: https://lore.kernel.org/r/20200709102936.GA20875@mwanda Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 617894c commit ef75e14

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/staging/comedi/drivers/addi_apci_1500.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ static int apci1500_di_cfg_trig(struct comedi_device *dev,
456456
unsigned int lo_mask = data[5] << shift;
457457
unsigned int chan_mask = hi_mask | lo_mask;
458458
unsigned int old_mask = (1 << shift) - 1;
459-
unsigned int pm = devpriv->pm[trig] & old_mask;
460-
unsigned int pt = devpriv->pt[trig] & old_mask;
461-
unsigned int pp = devpriv->pp[trig] & old_mask;
459+
unsigned int pm;
460+
unsigned int pt;
461+
unsigned int pp;
462462

463463
if (trig > 1) {
464464
dev_dbg(dev->class_dev,
@@ -471,6 +471,10 @@ static int apci1500_di_cfg_trig(struct comedi_device *dev,
471471
return -EINVAL;
472472
}
473473

474+
pm = devpriv->pm[trig] & old_mask;
475+
pt = devpriv->pt[trig] & old_mask;
476+
pp = devpriv->pp[trig] & old_mask;
477+
474478
switch (data[2]) {
475479
case COMEDI_DIGITAL_TRIG_DISABLE:
476480
/* clear trigger configuration */

0 commit comments

Comments
 (0)