dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Levin" <sashal@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH AUTOSEL 6.18] drm/amdgpu: validate RAS EEPROM tbl_size before record count
Date: Mon, 31 Aug 2026 14:20:25 +0000	[thread overview]
Message-ID: <20260831142026.29CF31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831133314.4125787-69-sashal@kernel.org>

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

Pre-existing issues:
- [Critical] Unvalidated `first_rec_offset` from EEPROM leads to an unsigned underflow in `RAS_OFFSET_TO_INDEX`, causing a massive heap buffer overflow during `amdgpu_ras_eeprom_read`.
--

commit 887663ae59b09548ad94227f6b760b666b20f6c3
Author: Candice Li <candice.li@amd.com>

drm/amdgpu: validate RAS EEPROM tbl_size before record count

Corrupt EEPROM data can set tbl_size below the table header size.
Guard the RAS_NUM_RECS macros against undersized tbl_size and reset
the table during init when tbl_size is below the minimum for the table
version instead of trusting the header.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c
> index 3eb3fb55ccb05..ef4389deb24ce 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c

[ ... ]

> @@ -1415,11 +1418,24 @@ int amdgpu_ras_eeprom_init(struct amdgpu_ras_eeprom_control *control)
>  	switch (hdr->version) {
>  	case RAS_TABLE_VER_V2_1:
>  	case RAS_TABLE_VER_V3:
> +		if (hdr->tbl_size < RAS_TABLE_HEADER_SIZE + RAS_TABLE_V2_1_INFO_SIZE) {
> +			dev_err(adev->dev,
> +				"RAS header invalid, tbl_size %u smaller than minimum %u, resetting table\n",
> +				hdr->tbl_size,
> +				RAS_TABLE_HEADER_SIZE + RAS_TABLE_V2_1_INFO_SIZE);
> +			return amdgpu_ras_eeprom_reset_table(control);
> +		}
>  		control->ras_num_recs = RAS_NUM_RECS_V2_1(hdr);
>  		control->ras_record_offset = RAS_RECORD_START_V2_1;
>  		control->ras_max_record_count = RAS_MAX_RECORD_COUNT_V2_1;
>  		break;
>  	case RAS_TABLE_VER_V1:
> +		if (hdr->tbl_size < RAS_TABLE_HEADER_SIZE) {
> +			dev_err(adev->dev,
> +				"RAS header invalid, tbl_size %u smaller than minimum %u, resetting table\n",
> +				hdr->tbl_size, RAS_TABLE_HEADER_SIZE);
> +			return amdgpu_ras_eeprom_reset_table(control);
> +		}
>  		control->ras_num_recs = RAS_NUM_RECS(hdr);
>  		control->ras_record_offset = RAS_RECORD_START;
>  		control->ras_max_record_count = RAS_MAX_RECORD_COUNT;

[Severity: Critical]
This is a pre-existing issue, but since this patch handles validation of
corrupt EEPROM data, I wanted to point out another potential issue in this
function.

A bit further down in amdgpu_ras_eeprom_init(), first_rec_offset is used
without bounds validation:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c:amdgpu_ras_eeprom_init() {
    ...
	control->ras_fri = RAS_OFFSET_TO_INDEX(control, hdr->first_rec_offset);
    ...
}

If a corrupted or maliciously programmed EEPROM provides a first_rec_offset
that is smaller than control->ras_record_offset (e.g., 0), the unsigned
subtraction inside the RAS_OFFSET_TO_INDEX macro could underflow, assigning
a massive value to control->ras_fri.

Later, when amdgpu_ras_eeprom_read() attempts to read the records, this
underflow could propagate and cause a large heap buffer overflow:

drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c:amdgpu_ras_eeprom_read() {
	...
	} else {
		g0 = control->ras_max_record_count - control->ras_fri;
		g1 += 1;
	}
	...
	res = __amdgpu_ras_eeprom_read(control, buf, control->ras_fri, g0);
	...
}

The variable g0 would again underflow to a massive value, which is then
passed as the num parameter to __amdgpu_ras_eeprom_read():

drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c:__amdgpu_ras_eeprom_read() {
	...
	buf_size = num * RAS_TABLE_RECORD_SIZE;
	res = amdgpu_eeprom_read(adev->pm.ras_eeprom_i2c_bus,
				 control->i2c_address +
				 RAS_INDEX_TO_OFFSET(control, fri),
				 buf, buf_size);
	...
}

The massive calculated buf_size is passed to amdgpu_eeprom_read(), which
could continuously read from the I2C bus directly into the small,
correctly-sized heap buffer, leading to memory corruption.

Could hdr->first_rec_offset be validated against control->ras_record_offset
during amdgpu_ras_eeprom_init() to prevent this?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260831133314.4125787-69-sashal@kernel.org?part=1

  reply	other threads:[~2026-08-31 14:20 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260831133314.4125787-1-sashal@kernel.org>
2026-08-31 13:20 ` [PATCH AUTOSEL 6.18] drm/panel/tdo-tl070wsh30: Use refcounted allocation in place of devm_kzalloc() Sasha Levin
2026-08-31 13:42   ` sashiko-bot
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18-5.10] drm/arm/komeda: fix error handling for clk_prepare_enable() and callers Sasha Levin
2026-08-31 13:59   ` sashiko-bot
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18-6.12] drm/amdgpu: validate and share PSP fw_pri_buf copies via psp_copy_fw Sasha Levin
2026-08-31 14:00   ` sashiko-bot
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18-6.12] drm: rz-du: Ensure correct suspend/resume ordering with VSP Sasha Levin
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18-6.12] drm/amd/display: Check for sharpening case when calculating max vtaps for scaler Sasha Levin
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18] drm/amdgpu: validate RAS EEPROM tbl_size before record count Sasha Levin
2026-08-31 14:20   ` sashiko-bot [this message]
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18] drm/amd/ras: Fix CPER ring debugfs read overflow Sasha Levin
2026-08-31 14:24   ` sashiko-bot
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18-5.10] drm/arm/malidp: use clk_bulk API in runtime PM resume and suspend Sasha Levin
2026-08-31 14:33   ` sashiko-bot
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18] drm/panel-edp: Add AUO B133HAN06.6 and BOE NV133FHM-N4F V8.0 Sasha Levin
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18] drm/amd/display: Avoid DPMS-on for phantom stream Sasha Levin
2026-08-31 14:35   ` sashiko-bot
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18-5.10] drm/panel: simple: Add AM-1280800W8TZQW-T00H Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.12] drm/panel: Enable GPIOLIB for panels which uses functions from it Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.6] drm/amdkfd: Let driver decide buffer size at AMDKFD_IOC_GET_DMABUF_INFO ioctl Sasha Levin
2026-08-31 14:44   ` sashiko-bot
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.12] drm/amd/display: Initialize dsc_caps to 0 Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.1] drm/bridge: tc358768: Set pre_enable_prev_first for reverse order Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18] drm/xe: Fix null pointer dereference in devcoredump cleanup Sasha Levin
2026-08-31 14:54   ` sashiko-bot
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.12] drm/imagination: Populate FW common context ID before passing to the FW Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18] drm: renesas: rzg2l_mipi_dsi: Fix deassert/assert of CMN_RSTB signal Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.12] drm/amdkfd: Properly acquire queue buffers in CRIU restore Sasha Levin
2026-08-31 14:56   ` sashiko-bot
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.6] drm/amdgpu: flush pending RCU callbacks on module unload Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18] drm/panel-edp: Add CSW PNB601LS1-2 and LGD LP116WHA-SPB1 Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-5.10] drm/amd/pm/si: Fix updating clock limits from power states Sasha Levin
2026-08-31 14:58   ` sashiko-bot
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.10] drm/gma500: return errors from Oaktrail HDMI I2C reads Sasha Levin
2026-08-31 15:04   ` sashiko-bot
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18] drm/imagination: Don't timeout job if its fence has been signaled Sasha Levin
2026-08-31 15:13   ` sashiko-bot
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.15] host1x: bus: Fix missing ops null check in error teardown Sasha Levin
2026-08-31 15:13   ` sashiko-bot
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.10] drm/amd/pm/si: Don't schedule thermal work when queue isn't initialized Sasha Levin
2026-08-31 15:16   ` sashiko-bot
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-6.12] fbcon: don't suspend/resume when vc is graphics mode Sasha Levin
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-6.12] drm/mediatek: dsi: Add compatible for mt8167-dsi Sasha Levin
2026-08-31 15:22   ` sashiko-bot
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18] drm/amd/display: Fix 8K Mode Not Parsed by EDID Sasha Levin
2026-08-31 15:25   ` sashiko-bot
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.10] drm/amd/display: Fix CRC open failure during active rendering Sasha Levin
2026-08-31 15:24   ` sashiko-bot
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.15] drm/gud: Add RCade Display Adapter VID/PID pair Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18] drm/amdgpu: cap ATOM command table nesting depth Sasha Levin
2026-08-31 15:24   ` sashiko-bot
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18-6.6] drm/nouveau/gsp: add SEC2 to GA100 chip table Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18] drm/amd/ras: reset CPER ring on corrupt entry size Sasha Levin
2026-08-31 15:40   ` sashiko-bot
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18-5.10] fbdev: pm2fb: unwind WC setup on probe failure Sasha Levin
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18-6.6] drm/amdgpu: Use system unbound workqueue for soft IH ring Sasha Levin
2026-08-31 15:53   ` sashiko-bot
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18] drm/amdgpu/userq: pin mqd and fw object bo to avoid eviction Sasha Levin
2026-08-31 15:50   ` sashiko-bot
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18] fbdev: Wrap user-invoked calls to fb_set_var() in helper Sasha Levin
2026-08-31 15:54   ` sashiko-bot
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18-6.1] drm/gem: Consider GEM object reclaimable if shrinking fails Sasha Levin
2026-08-31 15:59   ` sashiko-bot
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18] drm/amdgpu: check and drop invalid bad page records Sasha Levin
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18] drm/panel-edp: Add BOE NT140WHM-N4T, BOE NT140WHM-T05, BOE NV140FHM-N40 Sasha Levin
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-6.6] drm/amdkfd: Fix OOB memory exposure in get_wave_state() Sasha Levin
2026-08-31 16:12   ` sashiko-bot
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-6.6] drm/amdgpu: fix buffer overflow during vBIOS update Sasha Levin
2026-08-31 16:16   ` sashiko-bot
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-6.12] drm/amdgpu: harden FRU PIA parsing with bounded helpers Sasha Levin
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-6.6] drm/amdkfd: Unwind debug trap enable on copy_to_user failure Sasha Levin
2026-08-31 16:30   ` sashiko-bot
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-6.6] drm/amdkfd: fix UAF race in destroy_queue_cpsch Sasha Levin
2026-08-31 16:36   ` sashiko-bot
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-6.12] drm/amdgpu: Prefer ROM BAR for default VGA device Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18] drm/panel-edp: Add AUO B140XTN07.5, AUO B140HAK03.5, AUO B116XTN02.3, AUO B140XTK02.4, AUO B140HAN07.7 Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-6.1] drm/amdkfd: Check bounds for allocate_sdma_queue restore_sdma_id Sasha Levin
2026-08-31 16:43   ` sashiko-bot
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-6.12] drm/nouveau/bios: skip the IFR header if present Sasha Levin
2026-08-31 16:44   ` sashiko-bot
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-6.6] drm/amd/pm: Check SMUv13.0.6/12 metrics integrity Sasha Levin
2026-08-31 16:51   ` sashiko-bot
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18] drm/amdgpu: avoid integer overflow in VA range check Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-6.1] drm/amd/pm: bound pp_dpm_set_pp_table() memcpy Sasha Levin
2026-08-31 16:46   ` sashiko-bot
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-6.6] drm/amdkfd: check find_first_zero_bit before __set_bit on kfd->doorbell_bitmap Sasha Levin
2026-08-31 16:48   ` sashiko-bot
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18] drm/amdgpu/ras: add ras_suspend callback and use it for cp_ecc_error_irq Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18] drm/amdkfd: fix SMI event cross-process information leak Sasha Levin
2026-08-31 16:54   ` sashiko-bot
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18] drm/amdgpu: add first record offset check Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18-6.6] drm/amd/display: Fix DPMS using partially updated pipe context Sasha Levin
2026-08-31 17:15   ` sashiko-bot
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18-6.12] drm/amd/display: Find link encoder for flexible DIG mapping cases Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18] drm/amdgpu/pm: fix SmartShift bias sysfs store PM refcount on parse error Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18] drm/panel-edp: Add LG LP129WT232166 panel Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18] drm/amdgpu: Bound GPIO I2C table entry count from VBIOS Sasha Levin
2026-08-31 17:14   ` sashiko-bot
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18-6.6] drm/panel: jadard-jd9365da-h3: set prepare_prev_first Sasha Levin
2026-08-31 17:11   ` sashiko-bot
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18] drm/amdgpu: use atomic operation to achieve lockless serialization Sasha Levin
2026-08-31 17:20   ` sashiko-bot
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18-6.12] drm/dp: Add DSC virtual DPCD quirk for Realtek MST branch device Sasha Levin
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18] drm/xe/guc: Add support for NO_RESPONSE_BUSY in CTB Sasha Levin
2026-08-31 13:31 ` [PATCH AUTOSEL 6.18-6.1] drm/amdkfd: Check bounds on allocate_doorbell Sasha Levin
2026-08-31 17:38   ` sashiko-bot

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=20260831142026.29CF31F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashal@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox