Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795051146; b=BsGTH5rqtAXPqrz62HX19btxucSdWww80GcQFjdviVU/kqEn+C9ikeumTSNgG+Va5fgm EoHwG43pSctoFyw4k2yXVWIXIKtuIPrG5HVUae5aBzy1uxWhwpB+HYSSUTbiPh0h1ZZQ7 bs/QVamumj8QJ4aOrWShooerTAcFfwC6nmoPKy0R6/SNlO905eXB/mLTSU1c9cpjMz9bJ DxhHJtWaTUUQVhJJu0U032Dd2w2dAqabJCbHZ200RzK3VSGqUJWcFagBKhxbxYqkUoWdR mxQe5IuFE9Je/2zsPDqz8YahQSAxgTT1NimHrtRO6iCnKMPqpSsavEWU80lTtv+RXJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795051146; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=WSTWh6hd2Po9y42YuJg0mt1XK0iC6TpYzUisSa234/U=; b=LFExKZyxWkGzGkL8S8+3lhc+kwD1xz7x6Kbp6AZ129jVeBTmMLux1diKJXovDGNLleom 2ndfTqwWkXwTLIuOfksfdg3WsXa65uL0qqyPdRV/QbRAh/yqhfThoa+R94T0Vtp7VMeI+ wUj4thNf4pErBH1WVKGzGxKvs5jeIKaGITRZ18IA7jhVnQf6mNX63BNSMmrU2N60U0drR z53ZAgK8+IV7/gtaLcWGVisrQM/+mIoR+z+oViCmkhBqlvOtFc3dwXYB6i/reNZojJ7OL pHVQeGPU4loQb3wVzN1deiAqX6uyVMdFm5MxuODkW8b72vMCSV+8HF2NCeLfajBLjNA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="N7qUrqN/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A6E6606A32A; Thu, 19 Nov 2026 01:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=N7qUrqN/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id E57531F000C4; Thu, 19 Nov 2026 01:19:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795051146; bh=WSTWh6hd2Po9y42YuJg0mt1XK0iC6TpYzUisSa234/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=N7qUrqN/iZSerHludxt0OzYVjFOXBY3gIh1pwDET5p+hSyvZVitngJlwgP+Ysjmnl SOb84ydWTPrh03uK0NQgfIJ4FuS81LgD8kkGK8jjbFePZHmJJrTaAS0pGqkLlRcXuq 0mk/SieABI0eGuE52P5miVI369rUAs5rnEt+/ErU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yousef Alhouseen , Sasha Levin Subject: [PATCH 5.15 0105/2214] misc: bcm-vk: validate write size before allocation Date: Wed, 18 Nov 2026 15:29:41 +0100 Message-ID: <20261118150014.118627403@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150009.797899913@linuxfoundation.org> References: <20261118150009.797899913@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yousef Alhouseen [ Upstream commit f66c40cd90954f52809b3eabd386137f56bb6215 ] bcm_vk_write() uses the user-supplied write count to size a flexible-array work entry and then copies count bytes into that array. The allocation expression is evaluated before any overflow check, so a very large count can wrap the allocation smaller than the subsequent copy. Reject empty writes, check the allocation arithmetic before kzalloc(), and initialize the __counted_by field before copying into to_v_msg[]. Signed-off-by: Yousef Alhouseen Link: https://patch.msgid.link/20260629160605.29412-1-alhouseenyousef@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/bcm-vk/bcm_vk_msg.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/misc/bcm-vk/bcm_vk_msg.c b/drivers/misc/bcm-vk/bcm_vk_msg.c index fa14fd9ad1bf4..9176dcee77fba 100644 --- a/drivers/misc/bcm-vk/bcm_vk_msg.c +++ b/drivers/misc/bcm-vk/bcm_vk_msg.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1089,6 +1090,7 @@ ssize_t bcm_vk_write(struct file *p_file, u32 q_num; u32 msg_size; u32 msgq_size; + size_t entry_size; if (!bcm_vk_drv_access_ok(vk)) return -EPERM; @@ -1096,20 +1098,26 @@ ssize_t bcm_vk_write(struct file *p_file, dev_dbg(dev, "Msg count %zu\n", count); /* first, do sanity check where count should be multiple of basic blk */ - if (count & (VK_MSGQ_BLK_SIZE - 1)) { - dev_err(dev, "Failure with size %zu not multiple of %zu\n", + if (!count || count & (VK_MSGQ_BLK_SIZE - 1)) { + dev_err(dev, "Failure with size %zu not a positive multiple of %zu\n", count, VK_MSGQ_BLK_SIZE); rc = -EINVAL; goto write_err; } + if (check_add_overflow(sizeof(*entry), count, &entry_size) || + check_add_overflow(entry_size, vk->ib_sgl_size, &entry_size)) { + rc = -EOVERFLOW; + goto write_err; + } + /* allocate the work entry + buffer for size count and inband sgl */ - entry = kzalloc(sizeof(*entry) + count + vk->ib_sgl_size, - GFP_KERNEL); + entry = kzalloc(entry_size, GFP_KERNEL); if (!entry) { rc = -ENOMEM; goto write_err; } + entry->to_v_blks = count >> VK_MSGQ_BLK_SZ_SHIFT; /* now copy msg from user space, and then formulate the work entry */ if (copy_from_user(&entry->to_v_msg[0], buf, count)) { @@ -1117,7 +1125,6 @@ ssize_t bcm_vk_write(struct file *p_file, goto write_free_ent; } - entry->to_v_blks = count >> VK_MSGQ_BLK_SZ_SHIFT; entry->ctx = ctx; /* do a check on the blk size which could not exceed queue space */ @@ -1354,4 +1361,3 @@ void bcm_vk_msg_remove(struct bcm_vk *vk) bcm_vk_drain_all_pend(&vk->pdev->dev, &vk->to_v_msg_chan, NULL); bcm_vk_drain_all_pend(&vk->pdev->dev, &vk->to_h_msg_chan, NULL); } - -- 2.53.0