mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maoyi Xie <maoyixie.tju@gmail.com>
To: Stefan Richter <stefanr@s5r6.in-berlin.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org,
	linux1394-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: [PATCH] media: firedtv: bound the CA reply length in avc_ca_app_info
Date: Wed,  1 Jul 2026 16:28:02 +0800	[thread overview]
Message-ID: <20260701082802.1589509-1-maoyixie.tju@gmail.com> (raw)

avc_ca_app_info() copies a device length from the CI-CAM response with no
bound check:

	memcpy(&app_info[5], &r->operand[pos], 5 + r->operand[pos + 4]);

r->operand[pos + 4] is a byte the CAM controls, up to 255. app_info is the
256 byte msg[] of struct ca_msg, reached from userspace through the
CA_GET_MSG ioctl. The copy starts at offset 5 and runs 5 + that byte, so a
value above 246 overruns the buffer. A byte of 0xff writes about 9 bytes
past it.

The same idiom in avc_ca_pmt() was bounded for CVE-2021-42739 in
commit 35d2969ea3c7 ("media: firewire: firedtv-avc: fix a buffer overflow
in avc_ca_pmt()"). This reply path was left unbounded. It now returns
-EINVAL when the reported length would run past the 256 byte reply.

Fixes: 154907957f939 ("firedtv: massive refactoring")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
 drivers/media/firewire/firedtv-avc.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/media/firewire/firedtv-avc.c b/drivers/media/firewire/firedtv-avc.c
index a36c284121702..d77b9b802eddb 100644
--- a/drivers/media/firewire/firedtv-avc.c
+++ b/drivers/media/firewire/firedtv-avc.c
@@ -971,7 +971,7 @@ int avc_ca_app_info(struct firedtv *fdtv, unsigned char *app_info,
 {
 	struct avc_command_frame *c = (void *)fdtv->avc_data;
 	struct avc_response_frame *r = (void *)fdtv->avc_data;
-	int pos, ret;
+	int pos, length, ret;
 
 	mutex_lock(&fdtv->avc_mutex);
 
@@ -995,12 +995,18 @@ int avc_ca_app_info(struct firedtv *fdtv, unsigned char *app_info,
 	/* FIXME: check response code and validate response data */
 
 	pos = get_ca_object_pos(r);
+	length = r->operand[pos + 4];
+	/* 5 header bytes then 5 + length bytes are written to app_info */
+	if (5 + 5 + length > 256) {
+		ret = -EINVAL;
+		goto out;
+	}
 	app_info[0] = (EN50221_TAG_APP_INFO >> 16) & 0xff;
 	app_info[1] = (EN50221_TAG_APP_INFO >>  8) & 0xff;
 	app_info[2] = (EN50221_TAG_APP_INFO >>  0) & 0xff;
-	app_info[3] = 6 + r->operand[pos + 4];
+	app_info[3] = 6 + length;
 	app_info[4] = 0x01;
-	memcpy(&app_info[5], &r->operand[pos], 5 + r->operand[pos + 4]);
+	memcpy(&app_info[5], &r->operand[pos], 5 + length);
 	*len = app_info[3] + 4;
 out:
 	mutex_unlock(&fdtv->avc_mutex);
-- 
2.34.1


                 reply	other threads:[~2026-07-01  8:28 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=20260701082802.1589509-1-maoyixie.tju@gmail.com \
    --to=maoyixie.tju@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=mchehab@kernel.org \
    --cc=stefanr@s5r6.in-berlin.de \
    /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

Powered by JetHome