From nobody Wed Nov 25 17:19:49 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.142.180.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795218107; b=rlNtx4Kl3Xl5ypbzAw9lOw1X/L8xo0EyXrfSve8f8dolXqoV1xn5ExML7n7hT1STRvYI ZifUA3B7SLyxMZeq1FQQRCTrwxlNG2fNsk5KuhBsVlfZL1VPAcaRCLukKJj4JM91fomgV iXROLxrRrbTSKg8P8k3YqLWpe3BTSHyUbCwIgD73V3gBUO8hfIcky0rqRkx8I9D/EUe2C 0xFPlbJx9YZw7ubJQ+cNWEWMudfoKWwgWepBJPk4bjse2G9eApjSssK7hdyEk0M0ZhQUg GV5IaybePv8B/8tSVnmE4e+JHILUl7Bqp6hI3B4J1M85R/1jMC04nwY9b9ksQLWtNow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795218107; h=DMARC-Filter:Received:Date:From:To:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=v4jJEf6TgVkfG24sVas66atrbl+rzDNqobzHTACKDUU=; b=surufOklbL0vKCbK4WE4HeHZ+UIlzjPuwU7iYrGIbEORZFeE/Tsw+gIpuDa+lG0D99dO 3hfByE2mxsYZ460RiOa+QMtVI9kirC52mLx2II9tevsYInq5Oi7j+C0xIEAK+J+P6lbuK v9ItQhb65oVqbzWezHOSjxjYXNatOv9V+ft+eYpWMDqI+TVVrUXxI/FWZVxm7E0bW/R3p btOsCHwfQok/fUl32g1SnV6wGI6QEUrihUR7AHzStALX/D/vZiPfJA30LdwR7d0fxKpU1 UWLRPFVkRRR7P6G9PDmrb4/8BR4UhbGHW1O7Cw9nXtWrzbc/yFro9+4ZXOpq5kHoSLw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.remote-ip=185.142.180.65 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71709606A335; Fri, 20 Nov 2026 23:41:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 71709606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256:X25519MLKEM768) (Exim 4.100.1) (envelope-from ) id 1xUYEb-000000002eA-2Mzf; Fri, 20 Nov 2026 23:41:37 +0000 Date: Fri, 20 Nov 2026 23:41:29 +0000 From: Daniel Golle To: Detlev Casanova , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Nicolas Dufresne , Alex Bee , Hans Verkuil , Jonas Karlman , Sebastian Fricke , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/7] media: rkvdec: hevc: apply request controls first Message-ID: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The HEVC run preamble looks up the control values before the request is applied. Applying a request can reallocate the array of a dynamic array control, so the pointers taken before may point to freed memory. The slice count and the information whether the RPS controls were set are also those of the previous request. Userspace can trigger the reallocation by passing more elements of such a control than in any earlier request. Apply the request first and look up the controls afterwards, as the VP9 code does. Fixes: 3595375c2301 ("media: rkvdec: Add HEVC backend") Cc: stable@vger.kernel.org Signed-off-by: Daniel Golle --- Changes since v1: - Rewrite the commit message - No code change drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c b/= drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c index 2b8e04dd15727..c249e3f16f42c 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c @@ -429,6 +429,8 @@ void rkvdec_hevc_run_preamble(struct rkvdec_ctx *ctx, { struct v4l2_ctrl *ctrl; =20 + rkvdec_run_preamble(ctx, &run->base); + ctrl =3D v4l2_ctrl_find(&ctx->ctrl_hdl, V4L2_CID_STATELESS_HEVC_DECODE_PARAMS); run->decode_params =3D ctrl ? ctrl->p_cur.p : NULL; @@ -460,6 +462,4 @@ void rkvdec_hevc_run_preamble(struct rkvdec_ctx *ctx, } else { run->ext_sps_lt_rps =3D NULL; } - - rkvdec_run_preamble(ctx, &run->base); } --=20 2.56.1 From nobody Wed Nov 25 17:19:49 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.142.180.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795218119; b=4hW/PlMVgoh7CtfnREldspcEOswNvQT403TWWkSSilMxNEsoHC/r1EqTSvfP2naknD1Z DSaeC3G/lPpzPE2lqWHPorWq+8W4efQFzU48c4tJBmiPZyV18nEtD+H5Owyu1tvrlXSYs OTIvVdcsaKcavN9R/CXsk1DzYHBTa+Yofd4j3IHmUhs9d0J+3Gkf9dmjvwXHr+wj0WuDB OCJDw9gyKO06Ela19U+8qu3fkUGKRO8I0lW2wq2KG8a18h8EI1izG1gkeKQdBV8wd8mVM OvfLl5r9WZrpn5bg2w5iV16WQ4yLze8FST3+4o1WBJiTjKs/xK4BwFSTWAbO9+MbwAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795218119; h=DMARC-Filter:Received:Date:From:To:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=eQV0TtdjwA2l+DJGgyIwBU2JmOAWMeSkZF1hw7dK8hQ=; b=xPluZ3UhM0VLRnsmjW4DYc7rrPWxazJeaR6kpJH1SwkkvhP4b6w5asaXsJrMGV9t9MSf EJWDjwWYs1nxNKwcfQMG8rW87oSbwR+jYWP5ZtFVv8OYn5EO69iBrpomlzgjk8dA0e7bD x46V6Sa8NGg4FPq+cww/ddvgYx+k5z2wgEUt9UoL/rn4znAZ+sSgidMRkdinGTMWs62D2 xPqDA8craQ1q9eXXdc78wngUgm2xsPJUkWkEWzpfC3HxR2insNk49rrV2GU0aM1ws9d7J dHe5j4vpdPA7dyPxgvTHQB3fTwo9zwgpmX0ao7CWk6EAGWScaFUY1dDub4acVJe2v2Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.remote-ip=185.142.180.65 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70310606A33B; Fri, 20 Nov 2026 23:41:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 70310606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256:X25519MLKEM768) (Exim 4.100.1) (envelope-from ) id 1xUYEp-000000002eL-2HrS; Fri, 20 Nov 2026 23:41:51 +0000 Date: Fri, 20 Nov 2026 23:41:43 +0000 From: Daniel Golle To: Detlev Casanova , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Nicolas Dufresne , Alex Bee , Hans Verkuil , Jonas Karlman , Sebastian Fricke , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/7] media: rkvdec: vdpu383: complete refused HEVC requests Message-ID: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the RPS controls are missing, the VDPU383 HEVC back end fails the job after the request was applied, but without completing the request's controls. The request then never completes: userspace waits for it forever and MEDIA_REQUEST_IOC_REINIT fails with -EBUSY. Complete the controls before returning the error, as the VP9 code does. Fixes: e3b5b77e3689 ("media: rkvdec: Add HEVC support for the VDPU383 varia= nt") Cc: stable@vger.kernel.org Signed-off-by: Daniel Golle --- Changes since v1: - Rewrite the commit message - No code change drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c b= /drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c index 3462d995d4cf0..e9d8b590f0d58 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c @@ -553,6 +553,7 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) if ((!ctx->has_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) || (!ctx->has_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) { dev_err_ratelimited(rkvdec->dev, "Long and short term RPS not set\n"); + rkvdec_run_postamble(ctx, &run.base); return -EINVAL; } =20 --=20 2.56.1 From nobody Wed Nov 25 17:19:49 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.142.180.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795218136; b=LiDtuu9bmvPHgkLCmnD39rkCaAubogAm9qqYr7dbA/TMQjZg3D/E2uytfInoKpOyJMFU lPZK0rfALXnPnVkvlll5o8AvaytsniGCy3mOdRGDLTlyYcOEdYQjdy4BeSfaD4B3hX761 OscuvMu+AyQPorolYmKbK9Y1KPK9iCQdYucoRUSM9TolO/SWzcardIot8Zx86CmAEymww 03AEJQNaNrLcpXKgj14QXoO6bCae1TNd7hrilGue8at/YjGOXOSFmn8R9zAsNFYVDqQR+ 2sQd2QGNLTbBLHHs1YzmpaAVU6gELYtuKEDKD5Ny1kImLzQNnQNNr5yDDzL3rRyYs5A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795218136; h=DMARC-Filter:Received:Date:From:To:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=dfLaICCFFs23kF3QbDbJpGN/JagEIg84ZRjiNRLMMHI=; b=K57XFFh3Mh9oje1PjDrwryHq0TmwlZvHZ3Zz8Hj8z1mcZ0I+xzuiyhpxoZY+pLXHsHDa OO4zk73Gavu/0VhdDLO/ZDfhdl8m/qqLfDQhHpcv6ndvtMqfI+wdXjRlNVqU5jaIF7tzB RjFVI8Rzuz3YvG+j3n0afnu+Ivzj+VQkto9fbNgO8ppt8uzpwULIaW7XnPxFkoV1TCJWP Ri4gV+4EbIFTt8JK74Hbi+r4Y1/sbEafFxfmESexRDWEO0/JcbSSNClJTgP0DjcguK3iJ beXIDTuC+U0bpYI7K7/aN+n3V96LwG4wCDGbRuZDhRpB8oSV9RFNddRhvcte633R0Lw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.remote-ip=185.142.180.65 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBDD1606A33D; Fri, 20 Nov 2026 23:42:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BBDD1606A33D Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256:X25519MLKEM768) (Exim 4.100.1) (envelope-from ) id 1xUYF6-000000002eg-3IM4; Fri, 20 Nov 2026 23:42:08 +0000 Date: Fri, 20 Nov 2026 23:42:00 +0000 From: Daniel Golle To: Detlev Casanova , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Nicolas Dufresne , Alex Bee , Hans Verkuil , Jonas Karlman , Sebastian Fricke , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] media: rkvdec: vdpu381: refuse HEVC jobs without RPS sets Message-ID: <114caf6a80ded7185458027c729bbb4b4a4ba17b.1795217229.git.daniel@makrotopia.org> References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a stream uses reference picture sets and userspace never set the EXT_SPS_ST_RPS or EXT_SPS_LT_RPS control, the VDPU381 HEVC back end only logs a warning and starts the decoder anyway. The hardware then uses an RPS table which does not belong to the stream and gives wrong pictures at best. On the VDPU346 of the RK3568, which uses this back end, such a decode ends in a failed IOMMU reset and the system stops responding until the hardware watchdog resets it. Fail the job with -EINVAL before the hardware is started, as the VDPU383 back end does. Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 varia= nt") Cc: stable@vger.kernel.org Signed-off-by: Daniel Golle --- Changes since v1: - Move before the check of the control size, was 5/7 - Test ctx->has_sps_st_rps and ctx->has_sps_lt_rps as a result of the new position, the next patch replaces them in both back ends - Rewrite the commit message .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c b= /drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c index e1936e87f45be..7627282c15f0a 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c @@ -596,21 +596,18 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) =20 rkvdec_hevc_run_preamble(ctx, &run); =20 - rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list, - &hevc_ctx->scaling_matrix_cache); - assemble_hw_pps(ctx, &run); - - /* - * On vdpu381, not setting the long and short term ref sets will just out= put wrong frames. - * Let's just warn about it and let the decoder run anyway. - */ if ((!ctx->has_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) || (!ctx->has_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) { - dev_warn_ratelimited(rkvdec->dev, "Long and short term RPS not set\n"); - } else { - rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache); + dev_err_ratelimited(rkvdec->dev, "Long and short term RPS not set\n"); + rkvdec_run_postamble(ctx, &run.base); + return -EINVAL; } =20 + rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list, + &hevc_ctx->scaling_matrix_cache); + assemble_hw_pps(ctx, &run); + rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache); + config_registers(ctx, &run); =20 rkvdec_run_postamble(ctx, &run.base); --=20 2.56.1 From nobody Wed Nov 25 17:19:49 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.142.180.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795218162; b=xBjU1Lz7FrsSWxPiPFf6/HJnP2V6RE1yx5nEkpcTmxPF7F17LybkoNxOJKXNntl7Zvzz V/q03yLZD7diNwPfKEXXKz7vxHhj9wtYiffH7/szFEct0NptW6ZLhzgflAZTm+X7iNKYa YbDkeE9EhzTIlU+ie06EZhCw5KTvktdq+76UdeZh3vPrTnRUV88cObSAO3bB5i5jpUx/7 38Zhr2vrTk8RH2uiu6kkfDm1kU5veEzWbfoXJ4QdCFa1+gZex6LfKbPI/VNFzYZkyM9wh giwd/APRmVzDfupnLuwBhDz6goQiy5lilI6Ch5S0D2pEY6d7mv/mw6Gyx4zdb8hBaZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795218162; h=DMARC-Filter:Received:Date:From:To:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=EmTTjpiwcFOXJi4W2Zi3h/Yk6GAi9STPmCYXBs3Yfps=; b=tO1l+N+94pNijRyGn2aRGsxYJTuuU7xuib392+GsHPkS/TTajc9uJWdcTtvJcXvfTahI LJYwrl4Wsl7n+Im574jpkwR5nBnp08iDZwxtnrknaNjRxndPsKlZJn3R5NbvaiExx93Mq PWssfO7galYnHuT0OeAlH/iWltuTjp0QGciLBXxMfTBs5oV+xzaINlFMaF0Wa32QqsS5q vrIDLXqMlTaNKd/3Hv/fHPUVjV+Ns0nDQ0eLFjldo9BjXVMKuGnEVbbmBLB/NpO7k5BK5 n5nKO9lhj7+qUFAq0OdwzWZ6u/OhuZ95dMI8vgAf9fJGXnxQHlUTpNEKMRZrQreV0tg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.remote-ip=185.142.180.65 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32C20606A6A9; Fri, 20 Nov 2026 23:42:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 32C20606A6A9 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256:X25519MLKEM768) (Exim 4.100.1) (envelope-from ) id 1xUYFT-000000002f2-0gyc; Fri, 20 Nov 2026 23:42:31 +0000 Date: Fri, 20 Nov 2026 23:42:23 +0000 From: Daniel Golle To: Detlev Casanova , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Nicolas Dufresne , Alex Bee , Hans Verkuil , Jonas Karlman , Sebastian Fricke , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] media: rkvdec: hevc: refuse RPS controls shorter than the SPS counts Message-ID: <3244aca607a6714f92dd330d5f3fdfcff2d4a508.1795217229.git.daniel@makrotopia.org> References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The SPS control tells how many short-term and long-term reference picture sets a stream has. The sets themselves are passed in two separate array controls, EXT_SPS_ST_RPS and EXT_SPS_LT_RPS. The driver reads as many array elements as the SPS announces, without checking that userspace passed that many. A larger count in the SPS makes it read past the end of the array. Compare the array size with the SPS count when a decode job is prepared, and refuse the job if the array is too short. The controls can be set independently, so this is the first point where both values are known. Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 varia= nt") Cc: stable@vger.kernel.org Signed-off-by: Daniel Golle --- Changes since v1: - Move after the VDPU381 refusal, was 3/7, so that a control which is too short fails the job in both back ends (Nicolas Dufresne) - Change the subject, was "media: rkvdec: hevc: bound the RPS reads by the control size" - Rewrite the commit message, and say why the size cannot be checked when the control is set (Nicolas Dufresne) - The VDPU381 hunk now applies to the refusal instead of the warning, no other code change .../platform/rockchip/rkvdec/rkvdec-hevc-common.c | 12 ++++++------ .../platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 4 ++-- .../platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c b/= drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c index c249e3f16f42c..797a16517ed59 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c @@ -448,18 +448,18 @@ void rkvdec_hevc_run_preamble(struct rkvdec_ctx *ctx, V4L2_CID_STATELESS_HEVC_SCALING_MATRIX); run->scaling_matrix =3D ctrl ? ctrl->p_cur.p : NULL; =20 + run->ext_sps_st_rps =3D NULL; if (ctx->has_sps_st_rps) { ctrl =3D v4l2_ctrl_find(&ctx->ctrl_hdl, V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS); - run->ext_sps_st_rps =3D ctrl ? ctrl->p_cur.p : NULL; - } else { - run->ext_sps_st_rps =3D NULL; + if (ctrl && ctrl->elems >=3D run->sps->num_short_term_ref_pic_sets) + run->ext_sps_st_rps =3D ctrl->p_cur.p; } + run->ext_sps_lt_rps =3D NULL; if (ctx->has_sps_lt_rps) { ctrl =3D v4l2_ctrl_find(&ctx->ctrl_hdl, V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS); - run->ext_sps_lt_rps =3D ctrl ? ctrl->p_cur.p : NULL; - } else { - run->ext_sps_lt_rps =3D NULL; + if (ctrl && ctrl->elems >=3D run->sps->num_long_term_ref_pics_sps) + run->ext_sps_lt_rps =3D ctrl->p_cur.p; } } diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c b= /drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c index 7627282c15f0a..db836536e601b 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c @@ -596,8 +596,8 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) =20 rkvdec_hevc_run_preamble(ctx, &run); =20 - if ((!ctx->has_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) || - (!ctx->has_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) { + if ((!run.ext_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) || + (!run.ext_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) { dev_err_ratelimited(rkvdec->dev, "Long and short term RPS not set\n"); rkvdec_run_postamble(ctx, &run.base); return -EINVAL; diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c b= /drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c index e9d8b590f0d58..c409d21c08598 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c @@ -550,8 +550,8 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) * To be on the safe side for this new v4l2 control, write an error in th= e log and mark * the buffer as failed by returning an error here. */ - if ((!ctx->has_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) || - (!ctx->has_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) { + if ((!run.ext_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) || + (!run.ext_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) { dev_err_ratelimited(rkvdec->dev, "Long and short term RPS not set\n"); rkvdec_run_postamble(ctx, &run.base); return -EINVAL; --=20 2.56.1 From nobody Wed Nov 25 17:19:49 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.142.180.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795218233; b=auKoT93OG4K43yt7omQ8R0rMxrVLTlPMNKehEecB+FYUR1oAHBOjvYcw/FJ9SV38Itcn FAgUo2SXLGEbqirRa2xx29ne0lWJSFWJcOcknkY8DCHh8k5xlBqqZ9CZ7ch/EEqhMs9rm IWsaCQXheCx38moGAYBKVhKc5uC+qdlK0MS/2LfnP4XXOQ8eNoit24hBWYKhqs+lTjPYK 24IRHHhPAHWhUV8pxig8KIwrjse++TTIKX0LopTTSF6CYGPhf6KcmvwUsdcDXUdkl7P5N otNFQ+/CAzcxv6wugRIQQj+b+/6Yyv9b3eKwDOKcfWSDE6Lflrg5vaXIoPibjO395Pg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795218233; h=DMARC-Filter:Received:Date:From:To:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=eLGEzNTcKoM/8jFUGygGBt6uX1lUc0G4SgecjM91zfI=; b=X6tWODkKHAgsb4Gr4LtA0tSJpVqzLLsou7RhF5lvy7omiqmNMO873jrHMBO4J3hpqZ0N ND2Ssiz41FC0Yst/ROLhccQ6/bPSht03+bQZZJbChBqF+v5WK+kJs95WV8nv6iuDKx4vi ezBWyzOefTrvO/ftKS//mHXQg1CZ3IjBhn0jdFfV6nm5McbE1zkvuppw6VPWuwcrs3pMQ c+sbAGCp6ZWsxIW356R9eIX0YF4yAzkmOvZSSFooi0T5hiwXTtEsQRfh6KcZoEuBR7H/F Hj3mHJUHeSyXxAsHpqKN/EqaF24Bq1goZn8gRmLz2Wp/NaLDeO8D2Seznuj0TrVEOnA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.remote-ip=185.142.180.65 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F01C1606A696; Fri, 20 Nov 2026 23:43:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F01C1606A696 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256:X25519MLKEM768) (Exim 4.100.1) (envelope-from ) id 1xUYGe-000000002fn-3iFT; Fri, 20 Nov 2026 23:43:44 +0000 Date: Fri, 20 Nov 2026 23:43:37 +0000 From: Daniel Golle To: Detlev Casanova , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Nicolas Dufresne , Alex Bee , Hans Verkuil , Jonas Karlman , Sebastian Fricke , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] media: rkvdec: hevc: bound predicted short-term RPS sets Message-ID: <5a7d297bc6dfc93495e16fa4b47eb9f9a31aebbb.1795217229.git.daniel@makrotopia.org> References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A short-term reference picture set can be predicted from an earlier set, and can then hold one entry more than that set. The control validation allows 16 entries per set, which is also the size of the arrays the driver calculates the sets in. A set predicted from a 16-entry set overflows them, on the stack and on the heap. ITU-T H.265 7.4.8 limits a set to 15 entries, and the hardware table has room for 15 entries per set as well. Skip the prediction when the reference set has more than 15 entries, as is already done for an invalid reference index. Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 varia= nt") Cc: stable@vger.kernel.org Signed-off-by: Daniel Golle --- Changes since v1: - Was 4/7 - Rewrite the commit message - No code change drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c b/= drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c index 797a16517ed59..3b281c16a75ed 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c @@ -223,6 +223,8 @@ static void st_ref_pic_set_prediction(struct rkvdec_hev= c_run *run, int idx, (rps_data->abs_delta_rps_minus1 + 1); /* 7-60 */ =20 ref_rps =3D &calculated_rps_st_sets[ref_rps_idx]; + if (ref_rps->num_delta_pocs >=3D ARRAY_SIZE(use_delta_flag)) + return; =20 for (j =3D 0; j <=3D ref_rps->num_delta_pocs; j++) { used_by_curr_pic_flag[j] =3D !!(rps_data->used_by_curr_pic & (1 << j)); --=20 2.56.1 From nobody Wed Nov 25 17:19:49 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.142.180.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795218247; b=V20ZwN3sBi9efC9SmtdrbxiRcWysDH+dwwrZF+tI5QSkWzDhp5GDL5e5H3vvnugm5KrW fxbwy7X4V5Z1OhosuVHkKbXfNWw1JnMJsKZ81qvQXSif2nf+NTZXAyV8RhgTVConLIDDw xrRf6X1eghvKxMaKH7MGU+XJzPHGICyBmBjwTGkQJ8QbVsouUyJGiCT8zf5yPqKyoXh/2 TZRjrdzXgqM/OA+/TnbWvNt2/F+GQ3eQ6TZYCADdehEeYwz47fWhXCa1jXr+qRgDcQzwV +KkbgrbD8FHMFey1jOjXwIgndrcnGjePXNuJqHmPzdMRq0uZ22Ws29hibn3Pp9he1Jw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795218247; h=DMARC-Filter:Received:Date:From:To:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=XklkwbJvpSMa1UIUNZWOZidyZsUbNUw0lk5xd4FvB3c=; b=yU3zJQ3/Gj7MyheNEbgwIbG10CILnRxVmO4f3jM/YlDbNj8ZsvMltJOBfbHbd+dnHxxS yNId9OGnd2WVv5Dg4VCWM0DEp3f+XtlB2a70AYooatSRuIyBjYs1OP+ABuEjYegOFJWcC OXb9ZrWR88gJLU70VC7Xqv/9p6LZQDWur4qX3nUTR2Me+hxj6Hk7PUOOTPJ0sA/lC1weg lI21A1841KAuYo8iCtr+IHxgASZBrjkk+QixTlP972KlvNa8vGmeZq8jTxzJ0ttVEdpX/ djfg2FgZgfJJRnTSFEJW08Ds81jQLE4Ps8crzdFAvsLcKokrLh+ItlnVH4ASdWxi9SA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.remote-ip=185.142.180.65 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACC98606A338; Fri, 20 Nov 2026 23:44:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ACC98606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256:X25519MLKEM768) (Exim 4.100.1) (envelope-from ) id 1xUYGt-000000002fz-3IEG; Fri, 20 Nov 2026 23:43:59 +0000 Date: Fri, 20 Nov 2026 23:43:51 +0000 From: Daniel Golle To: Detlev Casanova , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Nicolas Dufresne , Alex Bee , Hans Verkuil , Jonas Karlman , Sebastian Fricke , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] media: rkvdec: hevc: cache every short-term RPS set Message-ID: <1628863e476edf7ea506eb269a742449721bbfbd.1795217229.git.daniel@makrotopia.org> References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The driver rebuilds the short-term RPS table of the hardware only when the EXT_SPS_ST_RPS control changed, but it compares just the first set with a cached copy. A change in a later set or in the number of sets goes unnoticed, and the hardware keeps the old table. As the cache starts zeroed, a stream whose first set is all zero never gets a table at all. Inter pictures are then decoded with wrong references, as seen with JCT-VC DELTAQP_A_BRCM_4 on an RK3568. Cache all sets together with their number. The control framework limits the number of sets to 64, which is the size of the cache. Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 varia= nt") Cc: stable@vger.kernel.org Signed-off-by: Daniel Golle --- Changes since v1: - Rewrite the commit message - No code change .../platform/rockchip/rkvdec/rkvdec-hevc-common.c | 12 ++++++++---- .../platform/rockchip/rkvdec/rkvdec-hevc-common.h | 9 ++++++++- .../platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 2 +- .../platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c b/= drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c index 3b281c16a75ed..e3449ab0d415b 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c @@ -330,14 +330,17 @@ static void st_ref_pic_set_calculate(struct rkvdec_he= vc_run *run, int idx, } =20 static void rkvdec_hevc_prepare_hw_st_rps(struct rkvdec_hevc_run *run, str= uct rkvdec_rps *rps, - struct v4l2_ctrl_hevc_ext_sps_st_rps *cache) + struct rkvdec_hevc_st_rps_cache *cache) { + u8 num_sets =3D run->sps->num_short_term_ref_pic_sets; + size_t size; int idx; =20 if (!run->ext_sps_st_rps) return; =20 - if (!memcmp(cache, run->ext_sps_st_rps, sizeof(struct v4l2_ctrl_hevc_ext_= sps_st_rps))) + size =3D num_sets * sizeof(*cache->sets); + if (cache->num_sets =3D=3D num_sets && !memcmp(cache->sets, run->ext_sps_= st_rps, size)) return; =20 struct calculated_rps_st_set *calculated_rps_st_sets =3D @@ -357,11 +360,12 @@ static void rkvdec_hevc_prepare_hw_st_rps(struct rkvd= ec_hevc_run *run, struct rk =20 kfree(calculated_rps_st_sets); =20 - memcpy(cache, run->ext_sps_st_rps, sizeof(struct v4l2_ctrl_hevc_ext_sps_s= t_rps)); + memcpy(cache->sets, run->ext_sps_st_rps, size); + cache->num_sets =3D num_sets; } =20 void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvde= c_rps *rps, - struct v4l2_ctrl_hevc_ext_sps_st_rps *st_cache) + struct rkvdec_hevc_st_rps_cache *st_cache) { rkvdec_hevc_prepare_hw_st_rps(run, rps, st_cache); rkvdec_hevc_assemble_hw_lt_rps(run, rps); diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h b/= drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h index 2a9b7719ab2d5..f6a3dec6ff4ad 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h @@ -35,10 +35,17 @@ =20 #define RKVDEC_RPS_HEVC_SIZE ALIGN(1032 + 64 * 384, 128) =20 +#define RKVDEC_HEVC_MAX_SHORT_TERM_REF_PIC_SETS 64 + struct rkvdec_rps { u32 info[RKVDEC_RPS_HEVC_SIZE / 8 / 4]; } __packed; =20 +struct rkvdec_hevc_st_rps_cache { + struct v4l2_ctrl_hevc_ext_sps_st_rps sets[RKVDEC_HEVC_MAX_SHORT_TERM_REF_= PIC_SETS]; + u8 num_sets; +}; + struct rkvdec_hevc_run { struct rkvdec_run base; const struct v4l2_ctrl_hevc_slice_params *slices_params; @@ -65,7 +72,7 @@ void compute_tiles_non_uniform(struct rkvdec_hevc_run *ru= n, u16 log2_min_cb_size u16 width, u16 height, s32 pic_in_cts_width, s32 pic_in_cts_height, u16 *column_width, u16 *row_height); void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvde= c_rps *rps, - struct v4l2_ctrl_hevc_ext_sps_st_rps *st_cache); + struct rkvdec_hevc_st_rps_cache *st_cache); void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_ctx *ctx, struct rkvdec_hevc_run *run, struct scaling_factor *scaling_factor, diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c b= /drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c index db836536e601b..8388421a68a48 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c @@ -117,7 +117,7 @@ struct rkvdec_hevc_priv_tbl { struct rkvdec_hevc_ctx { struct rkvdec_aux_buf priv_tbl; struct v4l2_ctrl_hevc_scaling_matrix scaling_matrix_cache; - struct v4l2_ctrl_hevc_ext_sps_st_rps st_cache; + struct rkvdec_hevc_st_rps_cache st_cache; struct rkvdec_vdpu381_regs_hevc regs; }; =20 diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c b= /drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c index c409d21c08598..47f236295f1e5 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c @@ -124,7 +124,7 @@ struct rkvdec_hevc_priv_tbl { struct rkvdec_hevc_ctx { struct rkvdec_aux_buf priv_tbl; struct v4l2_ctrl_hevc_scaling_matrix scaling_matrix_cache; - struct v4l2_ctrl_hevc_ext_sps_st_rps st_cache; + struct rkvdec_hevc_st_rps_cache st_cache; struct vdpu383_regs_h26x regs; }; =20 --=20 2.56.1 From nobody Wed Nov 25 17:19:49 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.142.180.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795218267; b=WM1mcu43FA6i/gnW1gNVrZKLmBdajyPT/9Q4xQFXk5+EvnzcbbfeIOe16NbYpjcRT76Q 4BKWx7NqwGyIJ6C6bxHx2scgg1X23FDNY12Eg8yAeWbRilJxuf3k4G0FaFq7neCqOTezr WyWNXVXoL1K+oy5EjlBQZWgJ7A2Bxck5Jq39wdSN6HsifZupIVtVa2VUfs78IjXtLQEF3 LF1OFGtW3q+XMSZRQ96avehJwGndXX8t5/2672S23bSCWKAJ6MPPYzIF7PCCTMwOTsdLd Ach80PTgzMzWGuQBtPITmzdi5wIKT7b2GK/2CofhsvMJbkm2DiACS8GXw26p/0+aE1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795218267; h=DMARC-Filter:Received:Date:From:To:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=LJpIE8ztP+KbGnnCOb1LC8LShPiTmCttfBKwQc2Yr7s=; b=j56LdonZ8/gX8r6LGL1b1LKLTR3XxRp2YeD1RpcLYQBDjl44jfhH/oYzzmftgAO/W4gf nJg4Qzd/0mEC6eNYAI6ysUc9QMaSCQrIG9ZvgJ1PdD1yNpcTCFUdSpX8ozp5H0AHFGbun YwtFPdP5dsBJLZaMrXs7Ry79DPGrgSAMtl7nVeBx8NfGIwupcUvFqNmPsb0NWrBpgV64D DLR2FnUU5mpRnFTwouIpBml6cOyn6VBDLJ+npOkLX2B34fkqrgOjevrr0+5zySSaZCMbj l05Yv9WeeT1xzYaIUtAaNVVJiMRlfny2lilJzUavjjXK56JMq0pU3GJHhaUsxII+nNw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.remote-ip=185.142.180.65 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFA73606A687; Fri, 20 Nov 2026 23:44:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EFA73606A687 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256:X25519MLKEM768) (Exim 4.100.1) (envelope-from ) id 1xUYH8-000000002gK-0Biv; Fri, 20 Nov 2026 23:44:14 +0000 Date: Fri, 20 Nov 2026 23:44:05 +0000 From: Daniel Golle To: Detlev Casanova , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Nicolas Dufresne , Alex Bee , Hans Verkuil , Jonas Karlman , Sebastian Fricke , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] media: rkvdec: hevc: check the RPS scratch allocation Message-ID: <4644e528c71a780a238edb23e41f54f1359e1c3d.1795217229.git.daniel@makrotopia.org> References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The buffer for the calculated short-term sets is used without checking that its allocation succeeded. Return -ENOMEM and fail the decode job in both back ends. Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 varia= nt") Signed-off-by: Daniel Golle --- Changes since v1: - Rewrite the commit message - No code change .../rockchip/rkvdec/rkvdec-hevc-common.c | 26 ++++++++++++++----- .../rockchip/rkvdec/rkvdec-hevc-common.h | 4 +-- .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 7 ++++- .../rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 7 ++++- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c b/= drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c index e3449ab0d415b..80df05bacaeba 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c @@ -329,24 +329,27 @@ static void st_ref_pic_set_calculate(struct rkvdec_he= vc_run *run, int idx, st_rps->num_delta_pocs =3D st_rps->num_positive_pics + st_rps->num_negati= ve_pics; } =20 -static void rkvdec_hevc_prepare_hw_st_rps(struct rkvdec_hevc_run *run, str= uct rkvdec_rps *rps, - struct rkvdec_hevc_st_rps_cache *cache) +static int rkvdec_hevc_prepare_hw_st_rps(struct rkvdec_hevc_run *run, stru= ct rkvdec_rps *rps, + struct rkvdec_hevc_st_rps_cache *cache) { u8 num_sets =3D run->sps->num_short_term_ref_pic_sets; size_t size; int idx; =20 if (!run->ext_sps_st_rps) - return; + return 0; =20 size =3D num_sets * sizeof(*cache->sets); if (cache->num_sets =3D=3D num_sets && !memcmp(cache->sets, run->ext_sps_= st_rps, size)) - return; + return 0; =20 struct calculated_rps_st_set *calculated_rps_st_sets =3D kzalloc(sizeof(struct calculated_rps_st_set) * run->sps->num_short_term_ref_pic_sets, GFP_KERNEL); =20 + if (!calculated_rps_st_sets) + return -ENOMEM; + for (idx =3D 0; idx < run->sps->num_short_term_ref_pic_sets; idx++) { const struct v4l2_ctrl_hevc_ext_sps_st_rps *rps_data =3D &run->ext_sps_s= t_rps[idx]; =20 @@ -362,13 +365,22 @@ static void rkvdec_hevc_prepare_hw_st_rps(struct rkvd= ec_hevc_run *run, struct rk =20 memcpy(cache->sets, run->ext_sps_st_rps, size); cache->num_sets =3D num_sets; + + return 0; } =20 -void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvde= c_rps *rps, - struct rkvdec_hevc_st_rps_cache *st_cache) +int rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec= _rps *rps, + struct rkvdec_hevc_st_rps_cache *st_cache) { - rkvdec_hevc_prepare_hw_st_rps(run, rps, st_cache); + int ret; + + ret =3D rkvdec_hevc_prepare_hw_st_rps(run, rps, st_cache); + if (ret) + return ret; + rkvdec_hevc_assemble_hw_lt_rps(run, rps); + + return 0; } =20 struct vb2_buffer * diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h b/= drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h index f6a3dec6ff4ad..32f192743c8c8 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h @@ -71,8 +71,8 @@ void compute_tiles_uniform(struct rkvdec_hevc_run *run, u= 16 log2_min_cb_size, void compute_tiles_non_uniform(struct rkvdec_hevc_run *run, u16 log2_min_c= b_size, u16 width, u16 height, s32 pic_in_cts_width, s32 pic_in_cts_height, u16 *column_width, u16 *row_height); -void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvde= c_rps *rps, - struct rkvdec_hevc_st_rps_cache *st_cache); +int rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec= _rps *rps, + struct rkvdec_hevc_st_rps_cache *st_cache); void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_ctx *ctx, struct rkvdec_hevc_run *run, struct scaling_factor *scaling_factor, diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c b= /drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c index 8388421a68a48..2a239114759a2 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c @@ -593,6 +593,7 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) struct rkvdec_hevc_run run; struct rkvdec_hevc_ctx *hevc_ctx =3D ctx->priv; struct rkvdec_hevc_priv_tbl *tbl =3D hevc_ctx->priv_tbl.cpu; + int ret; =20 rkvdec_hevc_run_preamble(ctx, &run); =20 @@ -606,7 +607,11 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list, &hevc_ctx->scaling_matrix_cache); assemble_hw_pps(ctx, &run); - rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache); + ret =3D rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache); + if (ret) { + rkvdec_run_postamble(ctx, &run.base); + return ret; + } =20 config_registers(ctx, &run); =20 diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c b= /drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c index 47f236295f1e5..52554c75f47f4 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c @@ -542,6 +542,7 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) struct rkvdec_hevc_ctx *hevc_ctx =3D ctx->priv; struct rkvdec_hevc_priv_tbl *tbl =3D hevc_ctx->priv_tbl.cpu; u32 timeout_threshold; + int ret; =20 rkvdec_hevc_run_preamble(ctx, &run); =20 @@ -560,7 +561,11 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx) rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list, &hevc_ctx->scaling_matrix_cache); assemble_hw_pps(ctx, &run); - rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache); + ret =3D rkvdec_hevc_assemble_hw_rps(&run, &tbl->rps, &hevc_ctx->st_cache); + if (ret) { + rkvdec_run_postamble(ctx, &run.base); + return ret; + } =20 config_registers(ctx, &run); =20 --=20 2.56.1