mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guo Zihao <guozh23@xiaopeng.com>
To: hverkuil@kernel.org
Cc: mchehab@kernel.org, niklas.soderlund+renesas@ragnatech.se,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH] media: i2c: adv7604: fix out-of-bounds access with a one-block EDID
Date: Thu, 29 Oct 2026 16:30:59 +0800	[thread overview]
Message-ID: <20261029083059.546070-1-guozh23@xiaopeng.com> (raw)

When VIDIOC_S_EDID is called with a one-block EDID (no CTA extension
block, hence no Source Physical Address), v4l2_get_edid_phys_addr()
leaves spa_loc at 0. The fallback path then sets spa_loc to 128 and
reads edid->edid[128] and edid->edid[129], 2 bytes past the end of
the 128-byte kernel buffer that check_array_args() allocated for the
EDID data. The physical address is subsequently written back at the
same out-of-bounds location, so this is both a 2-byte out-of-bounds
read and write of kernel heap memory.

This regressed when support for EDIDs up to 4 blocks was added:
commit 54b74981c86c ("media: adv7604: writing a one-block EDID
failed") carefully handled the one-block case, but the fallback that
was added six days later undid that protection again.

Only take the spa_loc = 128 fallback if a second block exists, and
only write the physical address back into the EDID if a SPA location
was found. This restores the one-block behavior of 54b74981c86c.

Fixes: c730ff32b917 ("media: adv7604: support EDIDs up to 4 blocks")
Cc: stable@vger.kernel.org
Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
---

Triggering this requires nothing more than a VIDIOC_S_EDID call with a
single-block EDID on a subdev node, i.e. the most basic EDID a
userspace application can pass.

Verified by an ASAN-based userspace reproduction of the
check_array_args()/adv76xx_set_edid() path (kmalloc(128) buffer,
blocks=1, no SPA):

    ERROR: AddressSanitizer: heap-buffer-overflow
    READ of size 1 ... 0 bytes to the right of 128-byte region

With this fix applied the reproduction is clean. No regressions for
multi-block EDIDs containing a SPA: the spa_loc != 0 paths are
unchanged.

 drivers/media/i2c/adv7604.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index ac9c69ce438f..c007ac0bd8e5 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -2358,7 +2358,7 @@ static int adv76xx_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
 	if (err)
 		return err;
 
-	if (!spa_loc) {
+	if (!spa_loc && edid->blocks > 1) {
 		/*
 		 * There is no SPA, so just set spa_loc to 128 and pa to whatever
 		 * data is there.
@@ -2404,8 +2404,10 @@ static int adv76xx_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
 				  mask, (spa_loc & 0x100) ? mask : 0);
 	}
 
-	edid->edid[spa_loc] = state->spa_port_a[0];
-	edid->edid[spa_loc + 1] = state->spa_port_a[1];
+	if (spa_loc) {
+		edid->edid[spa_loc] = state->spa_port_a[0];
+		edid->edid[spa_loc + 1] = state->spa_port_a[1];
+	}
 
 	memcpy(state->edid.edid, edid->edid, 128 * edid->blocks);
 	state->edid.blocks = edid->blocks;
-- 
2.50.1


                 reply	other threads:[~2026-10-29  8:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261029083059.546070-1-guozh23@xiaopeng.com \
    --to=guozh23@xiaopeng.com \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®