From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 A70C2305697 for ; Wed, 17 Jun 2026 02:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781662771; cv=none; b=iFFJFHNGvvhM6Zqnu090uYNzwEcT4tHK+DoYp7Sw2LtxT0FPx0n7+XZYcZyxBa3H6hgVTr38pviu9yTyDvvin1yhppjXavx3bNjzvkRwoVsbQGpfZzK09nTlaAsXzHNdnRlEzeCwMUGSeB9esrtWtbLwLyWKnHYFXK2KxQTd/6o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781662771; c=relaxed/simple; bh=Mx0g8BYiH4JJVDQ/qQsay5AAAsvT94G+UkuQhrIJeSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BjTMUCZJRwx1DwmL7ViKEUH9x5XOineD4EbyY/PQbrlfmFoFjvpmqFpE/ra3o+kPuwbHdGJaUIItO7TakRarlJT2FKtC8VHqpCXKDUaUNZGqPk5fds065OAOgrqQN8dwkSBTFVXC5CItvCifOygbjK0GksPSZfTBMBQZnyu8qsY= 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=LvPXP63X; arc=none smtp.client-ip=209.85.222.179 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="LvPXP63X" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-9185503e6a5so70822785a.0 for ; Tue, 16 Jun 2026 19:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781662770; x=1782267570; 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=Sml+UeKb9+6PbEr3ie8aYF51m/8hlVenyLRv+O5D8SY=; b=LvPXP63Xy5hRJuX5xFLEqvgMgjgONr1gb35QnyMK/nuyBjQ4MH2G+8oJV7oli+XkPC ZXhz5/HSGW4sRn7xAC8zJBD7gKNcNn8ClVmSGYvXj4Sl5jyImiKExqs4H7eYdTsVU5ny euFe9zlQfISeUjAN1oH+x4xmxYjrPYgsg8QccvE5RziQ5fb7koNcP73TC+U+ao4CfB0n 8wsuYvzQ4L/ZzYBVW5Xw3wMYRAuCXB4HEQ2gOdlF9N1LenJX+8/4ephNuYPQ3hsXaWUx 0cOfNCYshNEOXz/6qww/pQ3CNcmA4vcGnbfjUo4PDd5/aQZdfkqhamto8XDQvQqrQEVC TZJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781662770; x=1782267570; 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=Sml+UeKb9+6PbEr3ie8aYF51m/8hlVenyLRv+O5D8SY=; b=i/epO1KEBgwjDHYk2mFQak3nvxWXwYlCE4wkVTXCqiGMRO3zuuXRgtnSFPuzXznMSg i/LuFLumUrEvwAwon0fb1GRbNzAaqUUF0h7x7A+9ZajPAbd/9Ix24CoBuxUxmYYU+qTA CmlJeY9HSchxtTkLvQe0/q+nB/1kGteBz03K1wwa6qo4MvLZ8oePW/iH3jSDsA6pHy2M 16I7zvQGTRZM95GM9YdmAC0fp3R0pYelLu21sf0ZkgFa4YyQmyEMey8+p++LmquXGLUt c2r0CB05egF5VZxukovPTwcxBQWUac8pqDXlc8QF9RDlYTgB+PcHkF4fOV3fIOC7pnZu IEJg== X-Forwarded-Encrypted: i=1; AFNElJ8zfRhBkrHVIyNBOhXf6X/bufrj6aLlho+jLE1vcxTN1UqE9v4FzxmX/kBzUvI9ur/iYQoLAlwyB73Hljo=@vger.kernel.org X-Gm-Message-State: AOJu0Yxp+tcUnqjyuQ5v0rBWpZ8YkRKrKeQRx68VzcRqiBMk2ASaivxR J9wplN/U/iUzt8MWwhgTHjo7EN3JzB62cwiuFmapgjRnKv2X98Ep49y5 X-Gm-Gg: Acq92OEkBztUYc5QEix0ytmMg6VVuM8BTqlUhmRzSm9F9oAY/mDZX+KjtNXDjjp7zAo hGzDZazlnak9OYwRXWZGs0bxFa8bXV7OCcaonLIzUuUSz2sYpQy9ybJ2tlDlbnCHxqKzHw98y0s 9as7UG+BBHY9W3XPmE4Q+pBaUu08Hbn2v33pJoo8XDLug5pSTrjeuhRqWnn6T/TYF/BQdlONlrF kcdZE0U1lzTz1GKt6XvAvzIMjEGJCPmglrpY3CE+/lnsebItLPavcfSQ7iqv/lUhtlamTlEZ3td t4eiliT+PR2TBMSV3n1msJ5/5JDah9T4moo/Pb7AyGsK/79jyOxvlm061gUrYbylf1KFWmLpUdH Jt0NqzjzMNKJ6xl1SsTiZTxWSY6teLdus7rb1bGbzPUCWMlLgWFI9iyQkoia8Qu2u+MlKzt1hok BmDmjBeIDWwhP17y6TZE2h0yB1tpyF9luLCflOv0h+NbKGFJxtAYUCLeR4AR+hmF6c4lSQPgJ9l jC3QMnb3KTd3KRWMSjPvysqJ74kHMRd X-Received: by 2002:a05:620a:25cc:b0:915:351b:3ad5 with SMTP id af79cd13be357-91dcdd72cbfmr167100085a.29.1781662769637; Tue, 16 Jun 2026 19:19:29 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2026 19:19:28 -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 2/9] media: v4l2-ctrls: validate AV1 tile counts Date: Tue, 16 Jun 2026 22:18:59 -0400 Message-ID: <20260617021906.2746743-3-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 The stateless AV1 decoders use tile_info.tile_cols and tile_rows as loop bounds and as indices into the mi_*_starts[] and *_in_sbs_minus_1[] arrays, as the divisor for context_update_tile_id, and their product bounds the per-tile descriptor buffers, but std_validate_compound() does not bound these u8 fields. Reject a V4L2_CTRL_TYPE_AV1_FRAME whose tile_cols or tile_rows exceeds V4L2_AV1_MAX_TILE_COLS / _ROWS, or whose product exceeds V4L2_AV1_MAX_TILE_COUNT. A zero tile count is left to the consuming driver so the zero-initialised control that existing userspace submits is still accepted. Fixes: 9de30f579980 ("media: Add AV1 uAPI") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- drivers/media/v4l2-core/v4l2-ctrls-core.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c index 6d478e1a5ef22..fb20ad13dfec7 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c @@ -790,10 +790,30 @@ static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg) return 0; } +static int validate_av1_tile_info(struct v4l2_av1_tile_info *t) +{ + /* + * tile_cols and tile_rows index the per-tile descriptor arrays and + * bound the tile loops in the stateless AV1 drivers; the product + * bounds the total tile descriptor count. + */ + if (t->tile_cols > V4L2_AV1_MAX_TILE_COLS || + t->tile_rows > V4L2_AV1_MAX_TILE_ROWS) + return -EINVAL; + + if ((u32)t->tile_cols * t->tile_rows > V4L2_AV1_MAX_TILE_COUNT) + return -EINVAL; + + return 0; +} + static int validate_av1_frame(struct v4l2_ctrl_av1_frame *f) { int ret = 0; + ret = validate_av1_tile_info(&f->tile_info); + if (ret) + return ret; ret = validate_av1_quantization(&f->quantization); if (ret) return ret; -- 2.53.0