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 45F1C24113C; Tue, 29 Apr 2025 16:47:18 +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=1745945240; cv=none; b=CNcflAg9OmO+5NqbjbIdJcFKe0V1rRF/8S/l9SndOl9V/SFAEHOJM9iHU6PQs9+k6DzO0C5OhDYVhz6EE41yiJzTr/N1razlSTxIlbuFOridVwnSUQnpWiov3RcXOO5EjMPzzPZ5s/Jl36L8zdTarwGQnr8h5k4K09Dk1VW3Bhg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745945240; c=relaxed/simple; bh=zLfGoZx6FkrqkgS4QTtknsHsxtElA3BNhoAONQkzKTE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jJWeJO1Nl+5zfQtqB7VIDFcEMgpg+IJUyDqbkxbiQNToJoruW7YlPklMnlrgkQ87reK5Xf90bYt4UejGj0fsQzBpjowpG4vAnVVOoNB5uC8NXA2bi+TdqVzswD8fU5kqgABMzvUDVs+Htm12oBLdSOlSyq533LEuhMdQ1rzr554= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=czGS/sSl; 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="czGS/sSl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DE36C4CEE3; Tue, 29 Apr 2025 16:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745945238; bh=zLfGoZx6FkrqkgS4QTtknsHsxtElA3BNhoAONQkzKTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=czGS/sSl2TTz76o0dmNiKsHt16gw/4UpdWVhSZPc6UmZBo/br6EYyC0EmHafdGUvF OWraRi41EY06aZMUDpJOMmImUnWPqEhoYPgAruWDjN3TR2p1NA+AV/zf97DNJUEWDF UcS+Vt/dRJDNVw19yQKtVxUclqCoxoBhjfTZ5BDI= 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 5.4 046/179] media: venus: hfi: add check to handle incorrect queue size Date: Tue, 29 Apr 2025 18:39:47 +0200 Message-ID: <20250429161051.267464157@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161049.383278312@linuxfoundation.org> References: <20250429161049.383278312@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-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 @@ -188,6 +188,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 @@ -256,6 +259,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();