staging: comedi: verify array index is correct before using it
Subsystems (2)
PATCH 1/1 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 a8c66b684efa ("staging: comedi: addi_apci_1500: rewrite the subdevice support functions")
Signed-off-by Dan Carpenter <[email protected]>
--- drivers/staging/comedi/drivers/addi_apci_1500.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/staging/comedi/drivers/addi_apci_1500.c +7 -3
@@ -456,9 +456,9 @@ static int apci1500_di_cfg_trig(struct comedi_device *dev,unsigned int lo_mask = data[5 ] << shift;unsigned int chan_mask = hi_mask | lo_mask;unsigned int old_mask = (1 << shift) -1 ; -unsigned int pm = devpriv->pm[trig] & old_mask; -unsigned int pt = devpriv->pt[trig] & old_mask; -unsigned int pp = devpriv->pp[trig] & old_mask; +unsigned int pm; +unsigned int pt; +unsigned int pp;if (trig >1 ) { dev_dbg(dev->class_dev,
@@ -471,6 +471,10 @@ static int apci1500_di_cfg_trig(struct comedi_device *dev,return -EINVAL ; } + pm = devpriv->pm[trig] & old_mask; + pt = devpriv->pt[trig] & old_mask; + pp = devpriv->pp[trig] & old_mask; +switch (data[2 ]) {case COMEDI_DIGITAL_TRIG_DISABLE :/* clear trigger configuration */
Signature · 1 line
2.27.0
Quoted 29 lines · Dan Carpenter
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 a8c66b684efa ("staging: comedi: addi_apci_1500: rewrite the subdevice support functions")Signed-off-by Dan Carpenter <[email protected]>--- drivers/staging/comedi/drivers/addi_apci_1500.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/staging/comedi/drivers/addi_apci_1500.c +3
-3@@ -456,9 +456,9 @@ static int apci1500_di_cfg_trig(struct comedi_device *dev,unsigned int lo_mask = data[5 ] << shift;unsigned int chan_mask = hi_mask | lo_mask;unsigned int old_mask = (1 << shift) -1 ; -unsigned int pm = devpriv->pm[trig] & old_mask; -unsigned int pt = devpriv->pt[trig] & old_mask; -unsigned int pp = devpriv->pp[trig] & old_mask; +unsigned int pm; +unsigned int pt; +unsigned int pp;if (trig >1 ) { dev_dbg(dev->class_dev,
drivers/staging/comedi/drivers/addi_apci_1500.c static int apci1500_di_cfg_trig(struct comedi_device *dev, · line 480
Quoted 10 lines
drivers/staging/comedi/drivers/addi_apci_1500.c +4
-0@@ -471,6 +471,10 @@ static int apci1500_di_cfg_trig(struct comedi_device *dev,return -EINVAL ; } + pm = devpriv->pm[trig] & old_mask; + pt = devpriv->pt[trig] & old_mask; + pp = devpriv->pp[trig] & old_mask; +switch (data[2 ]) {case COMEDI_DIGITAL_TRIG_DISABLE :/* clear trigger configuration */
Nice catch!
Reviewed-by Ian Abbott <[email protected]>
Signature · 4 lines
-=( Ian Abbott <[email protected]> || Web: www.mev.co.uk )=- -=( MEV Ltd. is a company registered in England & Wales. )=- -=( Registered number: 02862268. Registered address: )=- -=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-