Skip to content

Commit 06ad8d3

Browse files
committed
drm/gma500: Fix out-of-bounds access to struct drm_device.vblank[]
The gma500 driver expects 3 pipelines in several it's IRQ functions. Accessing struct drm_device.vblank[], this fails with devices that only have 2 pipelines. An example KASAN report is shown below. [ 62.267688] ================================================================== [ 62.268856] BUG: KASAN: slab-out-of-bounds in psb_irq_postinstall+0x250/0x3c0 [gma500_gfx] [ 62.269450] Read of size 1 at addr ffff8880012bc6d0 by task systemd-udevd/285 [ 62.269949] [ 62.270192] CPU: 0 PID: 285 Comm: systemd-udevd Tainted: G E 5.10.0-rc1-1-default+ #572 [ 62.270807] Hardware name: /DN2800MT, BIOS MTCDT10N.86A.0164.2012.1213.1024 12/13/2012 [ 62.271366] Call Trace: [ 62.271705] dump_stack+0xae/0xe5 [ 62.272180] print_address_description.constprop.0+0x17/0xf0 [ 62.272987] ? psb_irq_postinstall+0x250/0x3c0 [gma500_gfx] [ 62.273474] __kasan_report.cold+0x20/0x38 [ 62.273989] ? psb_irq_postinstall+0x250/0x3c0 [gma500_gfx] [ 62.274460] kasan_report+0x3a/0x50 [ 62.274891] psb_irq_postinstall+0x250/0x3c0 [gma500_gfx] [ 62.275380] drm_irq_install+0x131/0x1f0 <...> [ 62.300751] Allocated by task 285: [ 62.301223] kasan_save_stack+0x1b/0x40 [ 62.301731] __kasan_kmalloc.constprop.0+0xbf/0xd0 [ 62.302293] drmm_kmalloc+0x55/0x100 [ 62.302773] drm_vblank_init+0x77/0x210 Resolve the issue by only handling vblank entries up to the number of CRTCs. I'm adding a Fixes tag for reference, although the bug has been present since the driver's initial commit. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Fixes: 5c49fd3 ("gma500: Add the core DRM files and headers") Cc: Alan Cox <alan@linux.intel.com> Cc: Dave Airlie <airlied@redhat.com> Cc: Patrik Jakobsson <patrik.r.jakobsson@gmail.com> Cc: dri-devel@lists.freedesktop.org Cc: stable@vger.kernel.org#v3.3+ Link: https://patchwork.freedesktop.org/patch/msgid/20201105190256.3893-1-tzimmermann@suse.de
1 parent 34a2808 commit 06ad8d3

1 file changed

Lines changed: 12 additions & 22 deletions

File tree

drivers/gpu/drm/gma500/psb_irq.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ int psb_irq_postinstall(struct drm_device *dev)
347347
{
348348
struct drm_psb_private *dev_priv = dev->dev_private;
349349
unsigned long irqflags;
350+
unsigned int i;
350351

351352
spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
352353

@@ -359,20 +360,12 @@ int psb_irq_postinstall(struct drm_device *dev)
359360
PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
360361
PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
361362

362-
if (dev->vblank[0].enabled)
363-
psb_enable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
364-
else
365-
psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
366-
367-
if (dev->vblank[1].enabled)
368-
psb_enable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
369-
else
370-
psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
371-
372-
if (dev->vblank[2].enabled)
373-
psb_enable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
374-
else
375-
psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
363+
for (i = 0; i < dev->num_crtcs; ++i) {
364+
if (dev->vblank[i].enabled)
365+
psb_enable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE);
366+
else
367+
psb_disable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE);
368+
}
376369

377370
if (dev_priv->ops->hotplug_enable)
378371
dev_priv->ops->hotplug_enable(dev, true);
@@ -385,6 +378,7 @@ void psb_irq_uninstall(struct drm_device *dev)
385378
{
386379
struct drm_psb_private *dev_priv = dev->dev_private;
387380
unsigned long irqflags;
381+
unsigned int i;
388382

389383
spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
390384

@@ -393,14 +387,10 @@ void psb_irq_uninstall(struct drm_device *dev)
393387

394388
PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
395389

396-
if (dev->vblank[0].enabled)
397-
psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
398-
399-
if (dev->vblank[1].enabled)
400-
psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
401-
402-
if (dev->vblank[2].enabled)
403-
psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
390+
for (i = 0; i < dev->num_crtcs; ++i) {
391+
if (dev->vblank[i].enabled)
392+
psb_disable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE);
393+
}
404394

405395
dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG |
406396
_PSB_IRQ_MSVDX_FLAG |

0 commit comments

Comments
 (0)