From: sashiko-bot@kernel.org
To: "Dibin Moolakadan Subrahmanian"
<dibin.moolakadan.subrahmanian@intel.com>
Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v2 1/2] drm/i915/dmc: Add sanity check for DMC load address
Date: Mon, 07 Sep 2026 10:51:53 +0000 [thread overview]
Message-ID: <20260907105153.75DED1F00ADE@smtp.kernel.org> (raw)
In-Reply-To: <20260907103731.1379922-5-dibin.moolakadan.subrahmanian@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] NULL pointer dereference in dmc_load_program() when firmware payload allocation fails for secondary pipes.
- [High] Firmware with fw_size == 0 bypasses sanity checks and causes a ZERO_SIZE_PTR dereference in assert_dmc_loaded().
--
commit f7a48dbeca10ad9c2178ea5ef93894eef607fc54
Author: Dibin Moolakadan Subrahmanian <dibin.moolakadan.subrahmanian@intel.com>
drm/i915/dmc: Add sanity check for DMC load address
For DMC firmware header version 3, the firmware load address is stored
in dmc_info->start_mmioaddr and later used by dmc_load_program().
Unlike the MMIO address table, the firmware load address is not
validated. Add a sanity check to ensure it is within the valid range.
> diff --git a/drivers/gpu/drm/i915/display/intel_dmc.c b/drivers/gpu/drm/i915/display/intel_dmc.c
> index a191eee240d9f..051b721a08959 100644
> --- a/drivers/gpu/drm/i915/display/intel_dmc.c
> +++ b/drivers/gpu/drm/i915/display/intel_dmc.c
> @@ -1023,6 +1023,56 @@ static void dmc_set_fw_offset(struct intel_dmc *dmc,
> }
> }
>
> +/*
> + * Check if the load address is within the valid range for the given DMC ID.
> + */
> +static bool dmc_load_addr_sanity_check(struct intel_dmc *dmc,
> + u32 start_addr, u32 payload_size,
> + int header_ver, enum intel_dmc_id dmc_id)
> +{
> + struct intel_display *display = dmc->display;
> + u32 start_range, end_range, end_addr;
[ ... ]
> + if (payload_size == 0)
> + end_addr = start_addr;
[Severity: High]
This is a pre-existing issue, but this patch explicitly allows a 0-byte
payload to bypass the sanity check. If a firmware file has fw_size == 0,
kmalloc(0) will return ZERO_SIZE_PTR, which is not NULL.
Because payload is not NULL, has_dmc_id_fw() will return true, and
assert_dmc_loaded() will try to dereference it:
intel_dmc.c:assert_dmc_loaded() {
...
found = intel_de_read(display, DMC_PROGRAM(dmc->dmc_info[dmc_id].start_mmioaddr, 0));
expected = dmc->dmc_info[dmc_id].payload[0];
...
}
Could this cause a kernel panic due to a ZERO_SIZE_PTR dereference?
Should the sanity check instead reject firmware with a 0-byte payload?
> + else if (check_add_overflow(start_addr, payload_size - 1, &end_addr))
> + return false;
> +
> + if (start_addr < start_range || end_addr > end_range)
> + return false;
> +
> + return true;
> +}
[ ... ]
> @@ -1169,17 +1237,6 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc,
> dmc_info->mmio_count = mmio_count;
> dmc_info->start_mmioaddr = start_mmioaddr;
>
> - rem_size -= header_len_bytes;
> -
> - /* fw_size is in dwords, so multiplied by 4 to convert into bytes. */
> - payload_size = dmc_header->fw_size * 4;
> - if (rem_size < payload_size)
> - goto error_truncated;
> -
> - if (payload_size > dmc->max_fw_size) {
> - drm_err(display->drm, "DMC FW too big (%u bytes)\n", payload_size);
> - return 0;
> - }
> dmc_info->dmc_fw_size = dmc_header->fw_size;
>
> dmc_info->payload = kmalloc(payload_size, GFP_KERNEL);
[Severity: High]
This isn't a bug introduced by this patch, but if kmalloc() fails here
for a secondary pipe (like DMC_FW_PIPEA), does this leave the struct in
an inconsistent state?
If kmalloc() fails, the function returns 0, but dmc_info->dmc_fw_size is
already updated. Since parse_dmc_fw() ignores the return value for
secondary pipes, could this cause a NULL pointer dereference later in
dmc_load_program()?
intel_dmc_load_program() will call dmc_load_program() which iterates
based on dmc_fw_size:
intel_dmc.c:dmc_load_program() {
for (i = 0; i < dmc->dmc_info[dmc_id].dmc_fw_size; i++) {
intel_de_write_fw(display,
DMC_PROGRAM(dmc->dmc_info[dmc_id].start_mmioaddr, i),
dmc->dmc_info[dmc_id].payload[i]);
}
}
Would it be safer to only update dmc_fw_size after payload allocation
succeeds?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260907103731.1379922-4-dibin.moolakadan.subrahmanian@intel.com?part=1
next prev parent reply other threads:[~2026-09-07 10:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 10:37 [PATCH v2 0/2] Add validation for DMC firmware header parsing Dibin Moolakadan Subrahmanian
2026-09-07 10:37 ` [PATCH v2 1/2] drm/i915/dmc: Add sanity check for DMC load address Dibin Moolakadan Subrahmanian
2026-09-07 10:51 ` sashiko-bot [this message]
2026-09-07 10:37 ` [PATCH v2 2/2] drm/i915/dmc: Prevent fw_size multiplication overflow Dibin Moolakadan Subrahmanian
2026-09-07 10:45 ` sashiko-bot
2026-09-07 11:37 ` ✗ CI.checkpatch: warning for Add validation for DMC firmware header parsing (rev2) Patchwork
2026-09-07 11:39 ` ✓ CI.KUnit: success " Patchwork
2026-09-07 12:27 ` ✓ Xe.CI.BAT: " Patchwork
2026-09-07 12:47 ` ✓ i915.CI.BAT: success for Add validation for DMC firmware header parsing (rev3) Patchwork
2026-09-07 14:35 ` ✗ Xe.CI.FULL: failure for Add validation for DMC firmware header parsing (rev2) Patchwork
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=20260907105153.75DED1F00ADE@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dibin.moolakadan.subrahmanian@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.