From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B107C3A6B8A for ; Sun, 14 Jun 2026 13:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781442616; cv=none; b=dW38WoMrD7BJ45/hJrotvyjhgByDZ+Xk7vps78MGFL8pEny+O4GPrIl5w4YcR/kWFfQUueTdO2qBCSktvuxOPS07TgD1UyYUSaKvR10ge6FjCe2WaFRxhfWsfTF1ZLEJ7/Rv1Nkj+cMKHqXHCFCM9NgdYKNJa2unSvpTrmpCHho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781442616; c=relaxed/simple; bh=/gK0otEQRDDJgFO4CGbacMlp+ViltBls5m/MIu+Y7hs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iuxb66DMAFUuPveNe9iOvluYyuX4WkdMKVD/Laq7NaMeFD5rqJJ3KjSKFvJziGJv8X3k39U538eagWKn3MnOnv5SApd0JA6rymAISbUnPtgy8IMubS0LD8H73z9YFhwhqy1hGwHDYYiuJK11K4avPx2ZgXk3jHo5lO2bQV/Gj24= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bL+UN2JW; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bL+UN2JW" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-91563abd6a9so113925985a.3 for ; Sun, 14 Jun 2026 06:10:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781442614; x=1782047414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lVl0d1DZ0/rxF5BIn+S5uaENMoHy7Qrp86HW8O6zq18=; b=bL+UN2JWB8IMskHpfTRDJw+aovpyEOXc9Sgje45LUAv6fgtkhKUkBNPs525EYcn9CM seMTZa48UOoOKaUtQd+vKDl5SuBh210z8/aCn+Bd2QZa3JvVPjy1yG58V7JOIG83J58b kJj/lCXSRXrYLzJEXFFgYMaEFp1SISSUa2b7SXU5gEgjUpUZLUqkO4aKPlkeQtFAha/s si+9oTVDICzvnsQ4cM7AeJL1KAHs8/BK57mZaRpeBX4I8nrcCNfqGJBxBVCO8vOciEsk JHf0mLUYrs7HtPkjbAnyQbeRcrI8mTov7ExUNxtL30ptwhOiqbphCOPlB+rrLYUtepfo Iy9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781442614; x=1782047414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lVl0d1DZ0/rxF5BIn+S5uaENMoHy7Qrp86HW8O6zq18=; b=nONAFpNGoNdvhnvXjKRUx5NTZqO5Duz1gMG823DzPNaVZXDPuE+HvSPaJJ33hN5DY2 JBuTTvldu0tjTPphsgOdzPGTicpuRIOLBzWTBUEsq0Uo6eKJ5OJYmrsNosAI9y6oR2R6 ru+KGWQY2XjqFJ/ve3NaT2PHN3+HmWCsfySd0OT2zWD6bUCx/95HTb6L3P9GOGeNSTxF QjoKBsJ6xeb/fe5Zgtye5ivpB9w1ZJjiE+49Ph3DAEA4A22Naay/UV4G7ev31zWlCm2/ 8h44o7usZDLSTq4juee3RtEr/lZbfBYzrlm6otR3YE/FxR/odisygKZ9KUgszWNm/S3q NmCg== X-Forwarded-Encrypted: i=1; AFNElJ8W8V7RWQsfioyAvidEtfkyC8qSFM+kAVknAQMBXWCI+6NpWrwNJ1H6YpRsu49neHaQixvg+qtsDWHy1Vw=@vger.kernel.org X-Gm-Message-State: AOJu0YwySigLqaikR1RoJgTWL0CpvFWepyS8WU9lbERv3eKFKaA0NkSd Z1pFzEWdmDhAkTXVHV2pc4Z+eRNus/FfCJi7zMgKIh7tWxHpj9d2TVpL X-Gm-Gg: Acq92OFuMDk7cm5X5cE4oL13poNPQXPZSc5Ztvl14bJxnn15TzFzGLwKKy89wc+D/ap VMCliYsgykxT2PhuYc6M4rIxVR6Dk+hzXVkMslul6IOJwyLsD13BYsCXFeyxLvllkh8jPLYdz9C iYs7jeTVgQgQvSJ5q86GNNeWIbfeN+rHGuqbDNCxASucw3yQVb4u1UNE0P50R/ZlfnwajUu8h6y tJwK3UxBeDWeani/6R5X0ftQunhW7gOQc5iyBvdH90+kmZ1xyJBb82OaNJsdiKRmNamtWub7k/5 kNSYdL4hSgkg6xvIPrBErcOL+6cImOvbehKIclTBuosJNnKzBqCXCuKVhyc91GgdWrdrGuk+pBv MZ/WeGp3jKAzXXuVMpS109CsQG64R1Z7Au3D7PGfdiF5x4dnauCThcp/IzDzCIrNMIC6MMrWZcE w9ldR5/WRGyHG3JVi+jhidOh4KTDhonQOkj7ECRMBKU1qi8Spk39nxif/2JZjatZ8TjPurgvcW4 7LUd43XOjAr7+mUF7dFiSlzBb1E8pzGxYMqxf69y28= X-Received: by 2002:a05:620a:26a1:b0:915:83fa:b3e0 with SMTP id af79cd13be357-9161bac7727mr1528176685a.5.1781442613683; Sun, 14 Jun 2026 06:10:13 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-91619f1b400sm752878985a.15.2026.06.14.06.10.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2026 06:10:12 -0700 (PDT) From: Michael Bommarito To: Hans Verkuil , Mauro Carvalho Chehab , Sakari Ailus , Nicolas Dufresne , Sebastian Fricke Cc: Laurent Pinchart , Benjamin Gaignard , Detlev Casanova , Ezequiel Garcia , Yunfei Dong , Jonas Karlman , Heiko Stuebner , Kees Cook , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] media: verisilicon: rockchip: bound VPU981 AV1 tile loop and guard divisor Date: Sun, 14 Jun 2026 09:10:01 -0400 Message-ID: <20260614131003.2524025-5-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260614131003.2524025-1-michael.bommarito@gmail.com> References: <20260614131003.2524025-1-michael.bommarito@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit rockchip_vpu981_av1_dec_set_tile_info() divides context_update_tile_id by tile_info->tile_cols and writes one descriptor per tile into the tile_info DMA buffer, sized for AV1_MAX_TILES. tile_cols / tile_rows come straight from the bitstream; reject a zero column or row count and bound the grid to AV1_MAX_TILES so the division is safe and the writes stay in the buffer. Fixes: 727a400686a2 ("media: verisilicon: Add Rockchip AV1 decoder") Signed-off-by: Michael Bommarito Assisted-by: Claude:claude-opus-4-8 --- This is a Rockchip RK35xx SoC block not reachable on the x86 KUnit host, so the driver-side out-of-bounds write is not reproduced here. .../verisilicon/rockchip_vpu981_hw_av1_dec.c | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c index e4e21ad..71d2ef7 100644 --- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c @@ -578,21 +578,32 @@ static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx) const struct v4l2_av1_tile_info *tile_info = &ctrls->frame->tile_info; const struct v4l2_ctrl_av1_tile_group_entry *group_entry = ctrls->tile_group_entry; - int context_update_y = - tile_info->context_update_tile_id / tile_info->tile_cols; - int context_update_x = - tile_info->context_update_tile_id % tile_info->tile_cols; - int context_update_tile_id = - context_update_x * tile_info->tile_rows + context_update_y; + unsigned int tile_cols, tile_rows; + int context_update_y, context_update_x, context_update_tile_id; u8 *dst = av1_dec->tile_info.cpu; struct hantro_dev *vpu = ctx->dev; int tile0, tile1; + /* Guard the divisor and bound the grid to the tile_info buffer. */ + tile_cols = tile_info->tile_cols; + tile_rows = tile_info->tile_rows; + if (!tile_cols || !tile_rows) + return; + if (tile_cols * tile_rows > AV1_MAX_TILES) { + tile_cols = min_t(unsigned int, tile_cols, AV1_MAX_TILES); + tile_rows = min_t(unsigned int, tile_rows, + AV1_MAX_TILES / tile_cols); + } + + context_update_y = tile_info->context_update_tile_id / tile_cols; + context_update_x = tile_info->context_update_tile_id % tile_cols; + context_update_tile_id = context_update_x * tile_rows + context_update_y; + memset(dst, 0, av1_dec->tile_info.size); - for (tile0 = 0; tile0 < tile_info->tile_cols; tile0++) { - for (tile1 = 0; tile1 < tile_info->tile_rows; tile1++) { - int tile_id = tile1 * tile_info->tile_cols + tile0; + for (tile0 = 0; tile0 < tile_cols; tile0++) { + for (tile1 = 0; tile1 < tile_rows; tile1++) { + int tile_id = tile1 * tile_cols + tile0; u32 start, end; u32 y0 = tile_info->height_in_sbs_minus_1[tile1] + 1; -- 2.53.0