mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hyunjung Ko <hj351016@gmail.com>
To: Scott Branden <scott.branden@broadcom.com>
Cc: bcm-kernel-feedback-list@broadcom.com,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Hyunjung Ko <hj351016@gmail.com>
Subject: [PATCH] misc: bcm-vk: bound plane descriptors against the message buffer
Date: Tue, 17 Nov 2026 18:37:12 +0900	[thread overview]
Message-ID: <20261117093712.185359-1-hj351016@gmail.com> (raw)

In bcm_vk_write(), a VK_FID_TRANS_BUF message embeds an array of
num_planes struct _vk_data descriptors at the end of the message.  Their
start is computed as:

	data = (struct _vk_data *)&entry->to_v_msg[msg_size + 1];
	data -= num_planes;

num_planes (0..15) comes from the message cmd field and msg_size (a u8)
from the size field; both are fully controlled by user space and are only
checked with 'msg_size > to_v_blks'.  Nothing verifies that the plane
count is consistent with the message size, so a crafted message (for
example size 0 with a non-zero plane count) makes 'data' underflow below
the copied buffer.  bcm_vk_sg_alloc() then reads num_planes descriptors
from out-of-bounds memory and interprets them as DMA addresses/sizes.

Reject any message whose descriptor range does not fall entirely within
the buffer copied from user space.

Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
 drivers/misc/bcm-vk/bcm_vk_msg.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/misc/bcm-vk/bcm_vk_msg.c b/drivers/misc/bcm-vk/bcm_vk_msg.c
index 17114092a284..e0d57f99a569 100644
--- a/drivers/misc/bcm-vk/bcm_vk_msg.c
+++ b/drivers/misc/bcm-vk/bcm_vk_msg.c
@@ -1192,6 +1192,21 @@ ssize_t bcm_vk_write(struct file *p_file,
 		/* Now back up to the start of the pointers */
 		data -= num_planes;
 
+		/*
+		 * 'data' and the num_planes descriptors that follow must lie
+		 * within the message buffer copied from user space.  A crafted
+		 * message with a plane count inconsistent with its size (e.g.
+		 * size 0 with a non-zero plane count) makes 'data' underflow
+		 * below the buffer (or run past its end), leading to an
+		 * out-of-bounds read in bcm_vk_sg_alloc().
+		 */
+		if ((void *)data < (void *)&entry->to_v_msg[0] ||
+		    (void *)(data + num_planes) >
+		    (void *)&entry->to_v_msg[entry->to_v_blks]) {
+			rc = -EINVAL;
+			goto write_free_msgid;
+		}
+
 		/* Convert user addresses to DMA SG List */
 		rc = bcm_vk_sg_alloc(dev, entry->dma, dir, data, num_planes);
 		if (rc)
-- 
2.43.0


                 reply	other threads:[~2026-11-17  9:37 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=20261117093712.185359-1-hj351016@gmail.com \
    --to=hj351016@gmail.com \
    --cc=arnd@arndb.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=scott.branden@broadcom.com \
    --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®