media: dm1105: Limit number of cards to avoid buffer over read
authorAnton Vasilyev <vasilyev@ispras.ru>
Wed, 18 Jul 2018 14:13:56 +0000 (10:13 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Thu, 2 Aug 2018 22:53:42 +0000 (18:53 -0400)
dm1105_probe() counts number of cards at dm1105_devcount,
but missed bounds check before dereference a card array.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/pci/dm1105/dm1105.c

index c9db108..1ddb057 100644 (file)
@@ -986,6 +986,9 @@ static int dm1105_probe(struct pci_dev *pdev,
        int ret = -ENOMEM;
        int i;
 
+       if (dm1105_devcount >= ARRAY_SIZE(card))
+               return -ENODEV;
+
        dev = kzalloc(sizeof(struct dm1105_dev), GFP_KERNEL);
        if (!dev)
                return -ENOMEM;