Skip to content

Commit

Permalink
iio: cf_axi_adc: Prevent out-of-bounds debug register access
Browse files Browse the repository at this point in the history
Make sure that when using the debug register access that registers outside
of the mapped memory region are not accessed. Otherwise undefined behavior
can occur.

Signed-off-by: Lars-Peter Clausen <[email protected]>
  • Loading branch information
larsclausen authored and commodo committed Apr 30, 2018
1 parent 9b924ae commit a1dba55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/iio/adc/cf_axi_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ struct axiadc_state {
struct device *dev_spi;
struct iio_info iio_info;
struct clk *clk;
size_t regs_size;
void __iomem *regs;
void __iomem *slave_regs;
unsigned max_usr_channel;
Expand Down
6 changes: 6 additions & 0 deletions drivers/iio/adc/cf_axi_adc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ static int axiadc_reg_access(struct iio_dev *indio_dev,
struct axiadc_state *st = iio_priv(indio_dev);
int ret;

/* Check that the register is in range and aligned */
if ((reg & DEBUGFS_DRA_PCORE_REG_MAGIC) &&
((reg & 0xffff) >= st->regs_size || (reg & 0x3)))
return -EINVAL;

mutex_lock(&indio_dev->mlock);

if (!(reg & DEBUGFS_DRA_PCORE_REG_MAGIC)) {
Expand Down Expand Up @@ -772,6 +777,7 @@ static int axiadc_probe(struct platform_device *pdev)
st = iio_priv(indio_dev);

mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
st->regs_size = resource_size(mem);
st->regs = devm_ioremap_resource(&pdev->dev, mem);
if (IS_ERR(st->regs))
return PTR_ERR(st->regs);
Expand Down

0 comments on commit a1dba55

Please sign in to comment.