From patchwork Thu Jul 27 04:34:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikash Garodia X-Patchwork-Id: 126629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp851020vqo; Wed, 26 Jul 2023 22:00:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlH97J9v5EjEAlQ3LB8Q8pEaDCscy40ML62lqcIAtIVVAb4TwwvjmidqovXMfg6XBF1UoX9l X-Received: by 2002:a17:906:cc4f:b0:99b:4210:cc75 with SMTP id mm15-20020a170906cc4f00b0099b4210cc75mr914446ejb.40.1690434053844; Wed, 26 Jul 2023 22:00:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690434053; cv=none; d=google.com; s=arc-20160816; b=mBcWqPOY46BFExJx2WUgrlMvP+JjDMDVU5E0NqWeFnzcPFJPnT73EkL8US52yqGcNg m6enGCc68mIEjG5ke/KrA8eOZblKpUcJvFOmid16D6FCQx2MFzgGvkD4QjiSZAVi7mM6 rga5KQFXdZ1pX+x0MkP4IiKYYFY5HNOit6617UD64bl0k/OMw2D+1rzb7Bd9Fm7hB6yU tOsaJB7bUXmJu2RJZhEfmLiKdmGA3mwNJaKR15l0zcxM2XbAu8MXteU87w4y5Kz3ljTv 4r4XRcfzHznHKd5qjylQtUsp4T09N/jmsfC1YVm6uWJgfiwFSKAwvRkIR3Xs+LjEWr+x 7XHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=b9JkBU4ajOHvGCySu6FDWdEm1FvpwdBuAZcDijsmdWU=; fh=GcndwOMBf1bnpW+bW+jgpNWzVvxAZNEz+Wt3jUkG7qY=; b=ZelmuIC4xW1u3IFeLIsv19qNw3BSIyRbcE4R6wJXH/VvPox3zVRtqeZTLHK8FwwJmg tCfDHTx0HoseNt+tEQzZxg05yN4AfM0cAl2UR41rKbLonVeHL3B2rt7IjoWW9GNyuIFt zRk5CahdDJu9TTEdAHBmqq4ZGSKAM0M3F/DIa6CihdAkh3n1u+eY5nwAfRFZOehv++Cp R7avUA7f/hor3pKglhvERLTCMmXpA0GQLBL4BCNVnNcoCBWdZB2cG3epn+F+8jLfZLtX Eu4n6vxl2Cz4A8PDStM+z/h7Fx8UR7CrhkAyvgN+kpxDDEH11M6Wo85ofVzgUVruQE4f hWUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="hp8/gnGc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id uz16-20020a170907119000b00992de9a0240si405602ejb.220.2023.07.26.22.00.27; Wed, 26 Jul 2023 22:00:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="hp8/gnGc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231395AbjG0EfR (ORCPT + 99 others); Thu, 27 Jul 2023 00:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231361AbjG0EfP (ORCPT ); Thu, 27 Jul 2023 00:35:15 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D99BE271C; Wed, 26 Jul 2023 21:35:13 -0700 (PDT) Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36R2Uk7N015046; Thu, 27 Jul 2023 04:35:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=b9JkBU4ajOHvGCySu6FDWdEm1FvpwdBuAZcDijsmdWU=; b=hp8/gnGctnBJCaUzagUp2MwlSIz+T5VTdvtqcjBGyIfexxU3jzmOpJxPWQZkVsVZt+Vj lX7C6/x+512EB1C8lVrCgiaxf/Lvns9NHMV6a9kvL5Ok9jhW9EJe7U6E0WYAz7hkGxXY 9XSMMYnAFnMigGRPH8osL5EyveKSEOw6orOUo2yGetN4U53pN3J6DhBMpvZVccZy0uZN dam3EhcNYq9BMXtXowmzGCmaDjS1Lzz/ehE7R09vCW/K9oUx8EfLlmt7QzgFwyU0mt2p aj6I3X5n+DJa9mvlCtyY/nPv+ko+jTtDX3YpRKcJ59bXojapQ9eJiF79YGxC5VUgJmZL 1Q== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3s37g0h17b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 04:35:09 +0000 Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36R4Z8Ap024865 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 04:35:08 GMT Received: from hu-vgarodia-hyd.qualcomm.com (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 26 Jul 2023 21:35:04 -0700 From: Vikash Garodia To: , , , , , , , CC: , , , , Vikash Garodia Subject: [PATCH 1/4] venus: hfi: add checks to perform sanity on queue pointers Date: Thu, 27 Jul 2023 10:04:26 +0530 Message-ID: <1690432469-14803-2-git-send-email-quic_vgarodia@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1690432469-14803-1-git-send-email-quic_vgarodia@quicinc.com> References: <1690432469-14803-1-git-send-email-quic_vgarodia@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01a.na.qualcomm.com (10.52.223.231) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: OjS1bhixCOrlUzg_0rosxVGwVdyXt7ZG X-Proofpoint-ORIG-GUID: OjS1bhixCOrlUzg_0rosxVGwVdyXt7ZG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-26_08,2023-07-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=688 phishscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307270040 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772548578710434875 X-GMAIL-MSGID: 1772548578710434875 Read and write pointers are used to track the packet index in the memory shared between video driver and firmware. There is a possibility of OOB access if the read or write pointer goes beyond the queue memory size. Add checks for the read and write pointer to avoid OOB access. Cc: stable@vger.kernel.org Fixes: d96d3f30c0f2 ("[media] media: venus: hfi: add Venus HFI files") Signed-off-by: Vikash Garodia --- drivers/media/platform/qcom/venus/hfi_venus.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/platform/qcom/venus/hfi_venus.c b/drivers/media/platform/qcom/venus/hfi_venus.c index f0b4638..dc228c4 100644 --- a/drivers/media/platform/qcom/venus/hfi_venus.c +++ b/drivers/media/platform/qcom/venus/hfi_venus.c @@ -206,6 +206,10 @@ static int venus_write_queue(struct venus_hfi_device *hdev, new_wr_idx = wr_idx + dwords; wr_ptr = (u32 *)(queue->qmem.kva + (wr_idx << 2)); + + if (wr_ptr < (u32 *)queue->qmem.kva || wr_ptr > (u32 *)(queue->qmem.kva + queue->qmem.size)) + return -EINVAL; + if (new_wr_idx < qsize) { memcpy(wr_ptr, packet, dwords << 2); } else { @@ -273,6 +277,10 @@ static int venus_read_queue(struct venus_hfi_device *hdev, } rd_ptr = (u32 *)(queue->qmem.kva + (rd_idx << 2)); + + if (rd_ptr < (u32 *)queue->qmem.kva || rd_ptr > (u32 *)(queue->qmem.kva + queue->qmem.size)) + return -EINVAL; + dwords = *rd_ptr >> 2; if (!dwords) return -EINVAL;