From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 8CBA9311C1B for ; Wed, 17 Jun 2026 02:19:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781662778; cv=none; b=U24S3V92CY4gYdH/G1kfG42Rf0yH38Ep7PC3WBnKDEwnltEVw8WF7BrLNN4SeiY/hTAZdwujMtIWnIQDMo3zAm00DFDW+BvC8bdQ6hhu+nPavfcxWRYy2lP/7RIGsdeEFJL+zmBYng6gVyxWmauX5VajJcsy+vE6HBvin2fwJ+A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781662778; c=relaxed/simple; bh=4U6WPsMzlM6SIn0yw6dtH3bu4VGHKh0G5LBtys4d550=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L7UlIK86rKeYX16PRyfr9TdyC9sRp7YQ6Az8Dqpfs9hWOhPxBg6Q57WR1nCNg/PQv5xCvL/tetsR1E95XfOMDfgyt60zjT3yaDuVlVejQ+KtZADFq2YYgERresnKhHv3kro5FDK5jcmpg8P9lIlKJgOXb1hmIZsM55uvMGAvx3M= 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=Oz3zpsm3; arc=none smtp.client-ip=209.85.222.178 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="Oz3zpsm3" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-91587626ae1so595967285a.3 for ; Tue, 16 Jun 2026 19:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781662776; x=1782267576; 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=UuBm79rRC3GqReCC3VjX/W1uFvcufiVMiTRTGLknay4=; b=Oz3zpsm3KbGfPDR+600hmEX2zFX9wIHgCJ4yo8IuUW3anP1+qF7shb1CnytYO1ufmK NRqi6nGRFFQsIMkbWxrVedS3X8jrkGU8LGH4dEQxat6f925EnVbCdP8bnqG8m9exVet9 r2LhDxy6jNy9ls2eNL66LajZwcXucsvKN1oT38q7+r7OJB+hPc9Tx5ZUgjxnjOlORySI 75ZKGvsPHS1LTwyJTNaLNgx052L6Qg1ER/nq7jrmtXtj0IqGk6SKZMuas+yHhFKS32dG mQBpr1yU1AAvohp7zjUQ08yMaZksceRKtqKy7MO3pa7KSW5rBBxSomFj4Y53a0Pkpx1K /DHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781662776; x=1782267576; 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=UuBm79rRC3GqReCC3VjX/W1uFvcufiVMiTRTGLknay4=; b=RLiU/HFJ5N5odacu3Ld9WSMALYliYXJ0PBgRwtwyLNLXKMdzwGODdQLEKvw/5Pd9Mo 98eWI6H2J79+YV4EaFYaJV+EO6lFYAwnrsx4KMUtxKXIyyui1zY8ICSeSMGBkrpS7af0 QL5w5a7NMNIwt1kl72S2Qcbr/RND+lDCJJ8CxT28GplKVu44+61/CWKjn6YKS6o8yY/Q Pule2AU45sNEa5jbZuxFJ2OrC3VeLF/HQrIj4UZ1CgA+SKuPRrF5V9z2yP1BCk57C+uM G/0iQlWHT1V8D01fPrDdGV/HroxO2pgj2qxe8mIwnsqPeBfkLYZVERdDqm9a7xHjnqMt qIdQ== X-Forwarded-Encrypted: i=1; AFNElJ/3k/TYu4h/ZQSesc0Y8mGjb4snPLOBPWhzUUuGrLttY4PuKOTn4WE4PSDlUCaFSNkeY7Ol+/1Di89JxX0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxy1ynCiTfqiM9kP5QvUB9CXuUAHSarI0k2okBcRz4wBpx4pQAK w4S+U3ZhvcbAeCFLXVmTQt2qtpK9FY2JqPMAJR6hEVFMeA8voQi6t1xR X-Gm-Gg: Acq92OHwHePGewerp5Gd3Gx/oyc+rItbpnn9ZB1mPTegJsgxv8VUKdWOM76674ZzOOS w0AI6okWQAWSeG+9u1OsXC/2SqpU4UGc43r6aF39OGaBcAC0lZGa4/0ZqzUD+3zGAWjY4RM7RKQ ZvIWzyEAGZiEHnplE01gJ8DbxIPOtaUX3DMjag3puP3vRiLjnrvmUa/LgdbUaN5Xsq8GVZ+HbkB Bym/f+CYIrP6r4y0aNsToDOfTM5r0rLnnne/ZMzVHYLWcLzaeEImGGdjl2C/AFfWYLtnv5IO/3t ILojQKgCyw12axs3H0+KyVH6uI61FsnYXQq4dyNaJNElgsYInkt1ZlL9LNiXylQl4wKyOTWaPzO yiyL6/syPAAhaMybjznzhaOQXJNdDR5cfZ09aR4KKYaxf6XYNtujGvQFeIC2ygqjlSgG1JdGI9g vBaRzLF4vkpdo5Y/SFXwpEy0LyhNBc6LEzGg0Je/h5MtyMuQgo7goKbp7v1MHInMcRD+dv1CB0u O1B14MVAmsYzcEzfv20fzfyY+QeZrjg X-Received: by 2002:a05:620a:17a6:b0:915:9125:e649 with SMTP id af79cd13be357-91d8dcae125mr414112385a.44.1781662776545; Tue, 16 Jun 2026 19:19:36 -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-9161a006e35sm1657646285a.28.2026.06.16.19.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2026 19:19:36 -0700 (PDT) From: Michael Bommarito To: Hans Verkuil , Mauro Carvalho Chehab , Sakari Ailus , Nicolas Dufresne 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 v3 6/9] media: verisilicon: rockchip: guard VPU981 AV1 divisor and tile buffer Date: Tue, 16 Jun 2026 22:19:03 -0400 Message-ID: <20260617021906.2746743-7-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260617021906.2746743-1-michael.bommarito@gmail.com> References: <20260617021906.2746743-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, which holds AV1_MAX_TILES entries; tile_cols and tile_rows come from the bitstream. Guard the division against a zero tile_cols by initialising the context-update values to zero and computing them only when tile_cols is non-zero, and stop the descriptor writes once the tile_info buffer is full. The tile geometry written to the hardware registers is left unmodified; the per-dimension and total tile bounds are enforced by the control validation. Fixes: 727a400686a2 ("media: verisilicon: Add Rockchip AV1 decoder") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- .../verisilicon/rockchip_vpu981_hw_av1_dec.c | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 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 e4e21ad373233..fd00dbd79fe46 100644 --- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c @@ -578,16 +578,30 @@ 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; + int context_update_y = 0; + int context_update_x = 0; + int context_update_tile_id = 0; u8 *dst = av1_dec->tile_info.cpu; + u8 *dst_end = dst + av1_dec->tile_info.size; struct hantro_dev *vpu = ctx->dev; int tile0, tile1; + /* + * tile_cols and tile_rows are bounded by the V4L2 control validation + * (V4L2_AV1_MAX_TILE_{COLS,ROWS} and V4L2_AV1_MAX_TILE_COUNT). Guard + * the divisor here, and keep the descriptor writes within the + * AV1_MAX_TILES tile_info buffer below; the register values use the + * unmodified tile geometry. + */ + if (tile_info->tile_cols) { + context_update_y = + tile_info->context_update_tile_id / tile_info->tile_cols; + context_update_x = + tile_info->context_update_tile_id % tile_info->tile_cols; + context_update_tile_id = + context_update_x * tile_info->tile_rows + context_update_y; + } + memset(dst, 0, av1_dec->tile_info.size); for (tile0 = 0; tile0 < tile_info->tile_cols; tile0++) { @@ -598,6 +612,10 @@ static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx) tile_info->height_in_sbs_minus_1[tile1] + 1; u32 x0 = tile_info->width_in_sbs_minus_1[tile0] + 1; + /* Stop once the tile_info descriptor buffer is full. */ + if (dst + 16 > dst_end) + break; + /* tile size in SB units (width,height) */ *dst++ = x0; *dst++ = 0; @@ -622,6 +640,8 @@ static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx) *dst++ = (end >> 16) & 255; *dst++ = (end >> 24) & 255; } + if (dst + 16 > dst_end) + break; } hantro_reg_write(vpu, &av1_multicore_expect_context_update, !!(context_update_x == 0)); -- 2.53.0