From patchwork Tue Sep 26 10:19:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 13399040 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E901E7D277 for ; Tue, 26 Sep 2023 10:20:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=EnP4IX+GlMx/u/RKBHzP3uRREH6Wn8x+Zdb3rMtLzrc=; b=jaqCtR2st+Abmr lyL8yOb9MExzkzLwwLEFFT4ZVc9jbMSumfpB5D5gxKeLWfCYjGiB1oBfBvD1ni1iAFy4ZnGdEVZ5j 77uP0zKx8+yPoSsyKO6UOx27nPji15suOJGfHa9qjGZKcqKmAmw/gkDekAQGkNjMxIHnvmIkZaSFO 8gboog9jTSXw3LpZDztzZ40mO9XWSLnm2lkFl7WFsKhxQ0BJP4GjDi+6gQbh02xVRhZFD1FCgkiGm pcO0KfdGAkKGYxjF+16Ac9o/lOIjp/w9aY5eXPDTuVsgS5cO/AkMSZLobgwJ8LjyRw8ha4LTVR+O1 3V4Exzkhnk3On3SAlAmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ql5A9-00G2NW-1C; Tue, 26 Sep 2023 10:19:29 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ql5A6-00G2Mt-1r; Tue, 26 Sep 2023 10:19:27 +0000 X-UUID: 24c4deb85c5611ee9b7791016c24628a-20230926 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=9pAB4vHxgXuOrF3cQ2v7MgCCwLtC7aUzC54ZVS4HYqQ=; b=K8bbdp7gq1NlWfol4J5gyjwhwQRd431TAgeFUo+8LQzkjfnkyJwQV7udbjxAInoKdjl/BfdY78D5v5YRqFl0/4hNuLUsjEVhISr/Hr1Rl8Dx3s3oUjl7HXimQ+gO4lmw+sd1oYscZVbI1eiUEntCaXBM9jWYR3cQIWf1Eg5JLaY=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:b5730924-3bff-40d3-9b90-b43ec521d7b8,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:5f78ec9,CLOUDID:2c067bc3-1e57-4345-9d31-31ad9818b39f,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR: NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: 24c4deb85c5611ee9b7791016c24628a-20230926 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 707863151; Tue, 26 Sep 2023 03:19:14 -0700 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 26 Sep 2023 18:19:11 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 26 Sep 2023 18:19:10 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Matthias Brugger , , , Yunfei Dong , Irui Wang CC: , , , , , , Maoguang Meng Subject: [PATCH 1/2] media: mediatek: vcodec: Fix encoder access NULL pointer Date: Tue, 26 Sep 2023 18:19:08 +0800 Message-ID: <20230926101909.15030-1-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--5.105600-8.000000 X-TMASE-MatchedRID: GEfnc4mEQr+uhCBFl/b63nQIOMndeKgE5Y0kb0hqatxnerzbhugqspVD ZsT0rYWCzpwM53iUVtXbCHv011Gy9dS7ezKc1AokngIgpj8eDcAZ1CdBJOsoY8RB0bsfrpPIx1F PlNAAmcDr4JEOMLTOvRaDB3e61dbj0hR2WQtXdazG0iw/N0V7hZ6oP1a0mRIj X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--5.105600-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: F52746FEAA883B08C25F18637D5B84EC5699F7FD68D85E3D7C3A99FE851EC73F2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_031926_625593_B6157163 X-CRM114-Status: UNSURE ( 9.73 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Need to set the private data with encoder device, or will access NULL pointer in encoder handler. Fixes: 1972e32431ed ("media: mediatek: vcodec: Fix possible invalid memory access for encoder") Signed-off-by: Irui Wang Reviewed-by: AngeloGioacchino Del Regno --- drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c index d299cc2962a5..ae6290d28f8e 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c @@ -138,7 +138,8 @@ int vpu_enc_init(struct venc_vpu_inst *vpu) vpu->ctx->vpu_inst = vpu; status = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler, vpu->id, - vpu_enc_ipi_handler, "venc", NULL); + vpu_enc_ipi_handler, "venc", + vpu->ctx->dev); if (status) { mtk_venc_err(vpu->ctx, "vpu_ipi_register fail %d", status); From patchwork Tue Sep 26 10:19:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 13399041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ADBF4E7D277 for ; Tue, 26 Sep 2023 10:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=na1P5Z8j6oQ8LvuhvR5gnCyUioutCthA/8L1mu0tEoc=; b=eqg/qKDZo0vSZs 1pcwYNEwuZyuMIWl0Vk9euZDf3eNhcuviGBWJwlY8atfIbGpDmxwfeiE1HSz80Mu5gPqkJV9yYxg/ BqJ411Sy+gVo5sPLMELToJbcJyrpF7BiipAEpbTYwsWrfq+oHULFh4xV74Um1O0bpyGOzyn42UFdU EwrdauI+Q98vEuuB6uNTC3YxR9FSxljE05U4EjkTPd+yM7NruUXQdmazTlGNmxsbYOvQJytm2gO06 yLNnBjh9l4uqGm47PIn/sA5OrJ5znc85k7P8fgrh5ldNWbkGw3QM1v20KZwD+cqfwSaKCXbTe4K2j evEfz7qR71aD7Q4cxyWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ql5Aa-00G2Su-37; Tue, 26 Sep 2023 10:19:56 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ql5AX-00G2S9-1w; Tue, 26 Sep 2023 10:19:54 +0000 X-UUID: 3916a5f45c5611ee9b7791016c24628a-20230926 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=40Z60dywDiXam7OraAE9s6YIBV6xPjNlnKiDsQUuJu8=; b=ZJYpMlQezmvm/RmzGzn6vV5ZFBg1gKBchkKwIG6vxZTAA0mrYk7dUZgCaENnaOsqD7L2ODhzHn8WC2URQcL8D25I7nO4Hc7TCArzm/pNVPlGALw6DVmpy+FP/xoqa7yl0W9Ui56Tui6wKaE8zxUybJETEl7mqkHs9SDuVbfWGD0=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:2791c5b3-ee81-46d3-b54d-234f1807bd9d,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:5f78ec9,CLOUDID:22596414-4929-4845-9571-38c601e9c3c9,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR: NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: 3916a5f45c5611ee9b7791016c24628a-20230926 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 340538886; Tue, 26 Sep 2023 03:19:48 -0700 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 26 Sep 2023 18:19:14 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 26 Sep 2023 18:19:13 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Matthias Brugger , , , Yunfei Dong , Irui Wang CC: , , , , , , Maoguang Meng Subject: [PATCH 2/2] media: mediatek: vcodec: Handle encoder vsi NULL pointer case Date: Tue, 26 Sep 2023 18:19:09 +0800 Message-ID: <20230926101909.15030-2-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230926101909.15030-1-irui.wang@mediatek.com> References: <20230926101909.15030-1-irui.wang@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--7.091600-8.000000 X-TMASE-MatchedRID: cp51Uxq7L6sEshQLfIZrysnlbo5l7mGFJwFLIHVZ6fvfc2Xd6VJ+yrx1 VMA+w2QulTJXKqh1ne29cOdjc/43lZH0YXYnbGozFEUknJ/kEl4YSQiB0ZTudfoLR4+zsDTtIFg EzOKKV2ZWlXDJGO9dw1RaeKIGTQfJwTnaD7mFxuQCohBZVD+eQlZca9RSYo/b X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--7.091600-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 5C163453A2C201611508BB54AA4306416D94492B541BA8C6922B690B29CF1F5F2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_031953_640877_2663E138 X-CRM114-Status: GOOD ( 10.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There will be a kernel null pointer exception if 'vsi' is NULL, check 'vsi' is not NULL before assign it to encoder instance. Signed-off-by: Irui Wang Reviewed-by: AngeloGioacchino Del Regno --- .../platform/mediatek/vcodec/encoder/venc/venc_h264_if.c | 5 +++++ .../platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c index a68dac72c4e4..385bcc0d14f3 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c @@ -597,6 +597,11 @@ static int h264_enc_init(struct mtk_vcodec_enc_ctx *ctx) inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx->dev->reg_base, VENC_SYS); ret = vpu_enc_init(&inst->vpu_inst); + if (!inst->vpu_inst.vsi) { + mtk_venc_err(ctx, "share buffer is NULL"); + kfree(inst); + return -EFAULT; + } if (MTK_ENC_IOVA_IS_34BIT(ctx)) inst->vsi_34 = (struct venc_h264_vsi_34 *)inst->vpu_inst.vsi; diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c index 05abca91e742..23ca0d93324f 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c @@ -326,6 +326,11 @@ static int vp8_enc_init(struct mtk_vcodec_enc_ctx *ctx) inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx->dev->reg_base, VENC_LT_SYS); ret = vpu_enc_init(&inst->vpu_inst); + if (!inst->vpu_inst.vsi) { + mtk_venc_err(ctx, "share buffer is NULL"); + kfree(inst); + return -EFAULT; + } inst->vsi = (struct venc_vp8_vsi *)inst->vpu_inst.vsi;