All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Slawomir Stepien" <sst@poczta.fm>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/cirrus-qemu: Validate BAR0 size during probe
Date: Tue, 25 Aug 2026 12:18:07 +0000	[thread overview]
Message-ID: <20260825121807.A90931F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825120729.493611-1-sst@poczta.fm>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The driver maps PCI BAR1 (MMIO) without verifying that its length is sufficient to cover the register offsets accessed by the driver (up to 0x15 for CRT_DATA). If a malicious or malformed PCI device provides a very small BAR1 (e.g., 16 bytes), accesses to higher offsets could cross page boundaries into unmapped memory, potentially causing a kernel panic.
--

--- Patch [1]: [PATCH v2] drm/cirrus-qemu: Validate BAR0 size during probe ---
commit b04af41f1fca891d59ccb1049a9b053cf626fb58
Author: Slawomir Stepien <sst@poczta.fm>
drm/cirrus-qemu: Validate BAR0 size during probe

This commit adds a check during probe to validate that the PCI BAR0 size is at
least CIRRUS_VRAM_SIZE. This prevents out-of-bounds memory accesses when
drm_fb_memcpy() copies framebuffers to VRAM mapped from a smaller BAR0.

Link: https://syzkaller.appspot.com/bug?extid=2442951a6abb004df963
Link: https://syzkaller.appspot.com/ai_job?id=ba262a3a-bccf-4ad8-a1b0-583c55d34fd6

> diff --git a/drivers/gpu/drm/tiny/cirrus-qemu.c b/drivers/gpu/drm/tiny/cirrus-qemu.c
> index 075221b431d37..3bf23fcf65749 100644
> --- a/drivers/gpu/drm/tiny/cirrus-qemu.c
> +++ b/drivers/gpu/drm/tiny/cirrus-qemu.c
> @@ -582,6 +582,9 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
>  	struct cirrus_device *cirrus;
>  	int ret;
>  
> +	if (pci_resource_len(pdev, 0) < CIRRUS_VRAM_SIZE)
> +		return -ENODEV;
> +

[Severity: High]
This is a pre-existing issue, but since we are validating the length of BAR0
(VRAM) here to prevent out-of-bounds accesses, should we also validate the
length of BAR1 (MMIO)?

Later in cirrus_pci_probe(), BAR1 is mapped using its raw length:

    cirrus->mmio = devm_ioremap(&pdev->dev, pci_resource_start(pdev, 1),
                                pci_resource_len(pdev, 1));

The driver subsequently accesses MMIO offsets up to 0x15:

drivers/gpu/drm/tiny/cirrus-qemu.c:wreg_crt() {
    ...
    iowrite8(reg, cirrus->mmio + CRT_INDEX);
    iowrite8(val, cirrus->mmio + CRT_DATA);
}

If a malformed PCI device presents a very small BAR1 (e.g., 16 bytes) and is
allocated such that its physical address is near the end of a page (e.g.,
ending at 0xFFF), devm_ioremap() will map only that single page.

Could accessing offset 0x15 cross the page boundary into unmapped virtual
memory and trigger a supervisor page fault?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260825120729.493611-1-sst@poczta.fm?part=1

  parent reply	other threads:[~2026-08-25 12:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 12:07 [PATCH v2] drm/cirrus-qemu: Validate BAR0 size during probe Slawomir Stepien
2026-08-25 12:15 ` Thomas Zimmermann
2026-08-25 12:18 ` sashiko-bot [this message]
2026-08-25 16:00 ` [syzbot ci] " syzbot ci
2026-08-26  6:57 ` [PATCH v2] " Thomas Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260825121807.A90931F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sst@poczta.fm \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.