From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (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 4B81F2DCF4C for ; Sun, 14 Jun 2026 15:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781452576; cv=none; b=XpF3ozdKiW5CD7EGIXln8uQhHaZoohCc+KlnZvqAQW3kBXseXFchq04bWR6s0emdNNvymyRSPBrXOm/jnfayEmL3gT3UbbtUswAs1xyHegreWGLfEdtlm9CBzBD5wrFwxKVDlX4MPBUW/fT5u1cBmtDdmqgz4rarL2BSp+iqJfw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781452576; c=relaxed/simple; bh=tVPqm+88/MGsyYDFQSKa03GedhxJEBM5kC1842fbWvY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=eBckhaNA+1zAFFHXVlZEVjAdienAfDfhpkA3K36VbxAKsByXb/4uDoieB88o+QN7sUYpeijyianJ9fHut/DSIOcJmjQzs9RJ5daVTNDl31VDHeH8zo6qmgr2e8kYlvZi5IobKS+nWkw4wuRDrKf5JcJs/m+yscxnRbHxvuditMs= 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=mj00RsYd; arc=none smtp.client-ip=209.85.219.46 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="mj00RsYd" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-8ccf0fa0aacso39347786d6.2 for ; Sun, 14 Jun 2026 08:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781452573; x=1782057373; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=U0kPJubfXi7k53ak7UhChAyiQgIHcIYyeOvCqkt9GAU=; b=mj00RsYde/S6UTT1SiVccJ++VH4dpnuADpeplD0VS4Qo0Q0EposmqQ+c5BcCFbIor6 7vmrcA0lz61x+wTXiRjpxlw9s5w1A+XI5S35Dg+Y6NSZB3kRQaAJ8yk2wmJk20GVivtN 7U75oBkOaV9nZYAgKRLE7sOyZ33E77iExurb6+o5R0tMP5+yQCDX21usI6hGICjJC8+m TIQJ2ORRf3CTigwR8T69oWDwRFlkHi82hF6JIUNN2gtBWW8gaAwSmHYDJ0clLm8Y9wSi p6157gWsUHZETYNB3EqYDmwXUjbn72I6p4bnVwav6BPQcQ+5GkTNSEsNO7rogVPc2vSV bY/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781452573; x=1782057373; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=U0kPJubfXi7k53ak7UhChAyiQgIHcIYyeOvCqkt9GAU=; b=YMmDumxF6v9/QqO5AuSMJqoTtmFS9EgJq8SV8d4LoTOJ4j/SLT68o9alJ4OdDRLz2E 2EfdSWJTT5F2jcNbUEnoBsBshW61R8Z3XHhhBAsdmx2g7EIZXstKkloDVqY60XBllNx6 NF8ciUvZF/WLYImMUVcg9acOc4VBigsvxSKJghcMDcCgmXQigzhxugX4NG4pBq2JNJv9 ZBRgzThVd1oUxLBUwpSmSAflw4Dl+slX7ara4rgx7bR9YQ293uBj9vD1VrqEOgbvVVso VoR5i+e/woPxeGAeMhtDTiBepWMUe+HmBLQIx3wYkrF/GJJEKSfaseeOmapCHMmg4Enq l7ng== X-Forwarded-Encrypted: i=1; AFNElJ9kntl3bSZQ1RmVmokawmUdY9pBpjDYnve7KiyhOl2PwT8+2H/jjk88+RbHLaYIh3fRb1oOyEolZQ0Q9yY=@vger.kernel.org X-Gm-Message-State: AOJu0YzGY17QjolegWAvWAEiYLrcp2xSqbwzyjb1IUKePp1RJSDCucuO qigR8nFGCn/ABvZEpwndgyWQAzBzEm8be3GVrEz6UnRTQANPjEVV2saK X-Gm-Gg: Acq92OEPjc+pid3L5gToLNc+e0EKVsibXAdLbupwrrWNuYNorUSiwpeqdvClPU5LR/h ppUCWBOBkGiPHtBZ92kH0KKNbul9vh9wWt56NikJw7yzxrJFqsjH7sw9pQWu0X3fDoL5nX1HZmI Ygya2GrfynWEwoM3VFE//B1VyTG+yhV161eSK81UhbqGnJimwuNh/awZr8fyYmKe2ZqSzsE/+a7 5eR/8PZZr/EbJEAFeyPMsOLA4WUlIhFnrj0BxiRzYt19DF8YZ8adIwQIZaJMRQcP4YR2J2u3BFG fZ3XXxZ0wP+NrBnTwMnLaLDPOEQL+S96mpnlxCN5OoyVV/bDn9TT8CYYQib/MhBDRgV4gmD3flh wqlW7UTCQgK8hBSwg7eGWRKhnNoWodvKVheFwQeCgyt9Urzpsfm/TO+oe+suQDhctdIjUvd45sb 51ANxqZkvpa2sgZAe/FNz6x8g0r+BlXE0w1sjZ+aWgP/fE0SvPCfoD7di8nzbSJr4Th6G2e+7Y7 uxTpohlU5irkay7NTYUeMI3BDo6f5hnA+nxCDcxS6o= X-Received: by 2002:a05:6214:1c4a:b0:8ac:a6a5:1f41 with SMTP id 6a1803df08f44-8d44e97d5d1mr119072016d6.27.1781452573124; Sun, 14 Jun 2026 08:56: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 6a1803df08f44-8d30522cbeasm82008446d6.44.2026.06.14.08.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2026 08:56:12 -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 v2 0/6] media: v4l2-ctrls: bound stateless HEVC/AV1 tile counts Date: Sun, 14 Jun 2026 11:56:02 -0400 Message-ID: <20260614155609.3107600-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit The stateless HEVC and AV1 V4L2 controls carry tile counts that several SoC decoder drivers consume as loop bounds when laying out fixed-size hardware descriptor buffers, but std_validate_compound() does not bound them. A process with access to a /dev/videoN stateless decoder (on a typical desktop or SBC, the active-seat local user via the logind/udev uaccess ACL, no extra capability) can set a HEVC PPS or AV1 frame control with a tile count far beyond the array capacity the drivers assume, making them loop past their fixed buffers. Patch 1 caps the HEVC and AV1 tile counts to the uAPI array capacity in the core. Patches 2-5 add matching bounds in the consuming driver loops (and bound the driver-interpreted HEVC pic_parameter_set_id / AV1 context_update_tile_id indices the core does not reject). Patch 6 adds KUnit tests for the core validation. I did my best to reproduce these with the hardware I have, but apologies in advance if I missed something because the soft repro. Test matrix: patch 1 + patch 6 run the real std_validate_compound() under KASAN on x86_64 (rejects out-of-range counts, in-range and the zeroed default pass, stock and patched); all objects build clean W=1; the ARM SoC decoders are not reachable on the x86 host, so the per-driver writes are not reproduced here. Changes since v1: - Patch 1: only reject AV1 tile_cols/tile_rows above the array capacity; do not reject a zero count. v1 also rejected tile_cols < 1, which made std_validate_compound() return -EINVAL for the zero-initialised AV1 frame control that userspace and v4l2-compliance submit, regressing the visl compliance run (reported by the linux-media CI). The divide-by-zero that a zero tile_cols would cause is guarded where the divisor is used in the rockchip decoder (patch 4), so no functional protection is lost. - Patch 6: drop the "zero tile_cols is rejected" KUnit case (no longer the core's behaviour) and add a benign case asserting the zero-initialised AV1 frame still validates, plus a tile_rows upper-bound case. - No changes to patches 2-5. Michael Bommarito (6): media: v4l2-ctrls: validate HEVC and AV1 tile counts media: rkvdec: bound HEVC tile loops and PPS id to the array capacity media: verisilicon: hantro: bound G2 HEVC tile loop to the buffer capacity media: verisilicon: rockchip: bound VPU981 AV1 tile loop and guard divisor media: mediatek: vcodec: bound AV1 tile-start copy to the array capacity media: v4l2-ctrls: add KUnit tests for compound control tile validation .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 5 +- .../rockchip/rkvdec/rkvdec-hevc-common.c | 22 ++- .../platform/rockchip/rkvdec/rkvdec-hevc.c | 8 +- .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 2 + .../platform/verisilicon/hantro_g2_hevc_dec.c | 6 + .../verisilicon/rockchip_vpu981_hw_av1_dec.c | 29 ++-- drivers/media/v4l2-core/Kconfig | 12 ++ .../media/v4l2-core/v4l2-ctrls-core-test.c | 130 ++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls-core.c | 27 ++++ 9 files changed, 224 insertions(+), 17 deletions(-) create mode 100644 drivers/media/v4l2-core/v4l2-ctrls-core-test.c base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8 -- 2.53.0