From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D90725335A; Thu, 17 Apr 2025 18:07:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744913222; cv=none; b=B1L12xdwc+CUTyJ8nGysiHGSMVlSzeHYpiA8RBcPyNZjJ4Of1Z4ZyHOp2r2h3oIaJRX4dFqg2ha52PUqmW6DabAcVj/ynfxMvSomgPj8+NAxUjNjfUG42wQAvfc4GmYvC9LmoUEiR1t4htBKS0w8QaErex9fHD5k64+4fh1alQk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744913222; c=relaxed/simple; bh=8/jd1y8JhiXhh5c5yx10s4CMpOG1tv6R60J08maU4DY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dRLIV2T/wHMO6N0XjQrMGcZkAeX7L65rKpqE4X/LOcln61uJdRfziUY8AoeAR3DmU0isQZT+poS9+oyzct28rsGV+TwL/pNJsuh2Q3Jqnld6KPgkWEs5kQ5F/3lLBoC/ECkFTIljIh4iDs3aG7mVocYZiUQ2CRX2NPW6x3vKmE0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DNeV2I+r; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="DNeV2I+r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7347C4CEE4; Thu, 17 Apr 2025 18:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744913222; bh=8/jd1y8JhiXhh5c5yx10s4CMpOG1tv6R60J08maU4DY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DNeV2I+r50DwTJZxXKv3iTHLIhSgQ+U0d4/7mGgVKLI1HzKzEfxEhizfYpOjfwrLr 4Zibu5hpMdiSh67EEBct1nyO1E+BA/VP7Fr6hH4VK2hW2lKth0D8rI0Z3m3OeKUOEC 8P0I16N/U3h9ateVUZSJOkRF/dL4w/Le4q/WhvXM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bryan ODonoghue , Vikash Garodia , Hans Verkuil Subject: [PATCH 6.14 227/449] media: venus: hfi: add check to handle incorrect queue size Date: Thu, 17 Apr 2025 19:48:35 +0200 Message-ID: <20250417175127.131535264@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250417175117.964400335@linuxfoundation.org> References: <20250417175117.964400335@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vikash Garodia commit 69baf245b23e20efda0079238b27fc63ecf13de1 upstream. qsize represents size of shared queued between driver and video firmware. Firmware can modify this value to an invalid large value. In such situation, empty_space will be bigger than the space actually available. Since new_wr_idx is not checked, so the following code will result in an OOB write. ... qsize = qhdr->q_size if (wr_idx >= rd_idx) empty_space = qsize - (wr_idx - rd_idx) .... if (new_wr_idx < qsize) { memcpy(wr_ptr, packet, dwords << 2) --> OOB write Add check to ensure qsize is within the allocated size while reading and writing packets into the queue. Cc: stable@vger.kernel.org Fixes: d96d3f30c0f2 ("[media] media: venus: hfi: add Venus HFI files") Reviewed-by: Bryan O'Donoghue Signed-off-by: Vikash Garodia Signed-off-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/media/platform/qcom/venus/hfi_venus.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/media/platform/qcom/venus/hfi_venus.c +++ b/drivers/media/platform/qcom/venus/hfi_venus.c @@ -187,6 +187,9 @@ static int venus_write_queue(struct venu /* ensure rd/wr indices's are read from memory */ rmb(); + if (qsize > IFACEQ_QUEUE_SIZE / 4) + return -EINVAL; + if (wr_idx >= rd_idx) empty_space = qsize - (wr_idx - rd_idx); else @@ -255,6 +258,9 @@ static int venus_read_queue(struct venus wr_idx = qhdr->write_idx; qsize = qhdr->q_size; + if (qsize > IFACEQ_QUEUE_SIZE / 4) + return -EINVAL; + /* make sure data is valid before using it */ rmb();