From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 4EB2644AB80 for ; Tue, 18 Aug 2026 10:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787050610; cv=none; b=ctAdlqMJHHAqOhMw/QghBJJ8aOU7KZLSvjDkoqt9I0kW8YmyUeLvtuPomk43pHC6z0Fy5F7900JIRvf21bXDbzQhuJS/bkWGi44JaHIoIjYPpOH7uevCrTAVdY4DE7vOQkTtx1zMbvbcBez564UNjb8SmxzRd8bLUl931bxp3kw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787050610; c=relaxed/simple; bh=LtJEwEmUeUmRecVw8rIzf4qNZ0bPe8mKIWeBWWWXbl8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kWPVvdQ2ikEOUfDBIVu+/hQXINfkxdhTV1jtLvwxAVpEWboFH+uQCyg8aPImnfugDVsQIT1iT4cHI2ZBcaz8fSEjgLg8eFwb8lx2GyzLLOcdHHQKAqcAQv3I4gnWTlk1lIJ1Ep2CVbnKjTAjMv25Wlz/vjApJv/7ntwXs6EqcFw= 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=DD8ATTlC; arc=none smtp.client-ip=209.85.221.44 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="DD8ATTlC" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-47f904e80eeso4356710f8f.1 for ; Tue, 18 Aug 2026 03:56:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787050606; x=1787655406; 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:content-type; bh=r9shV1QZCHqW8FXaqflZ+eE8Gymv9k8sKCSVo4d0l9E=; b=DD8ATTlCWDBKGbXeqqeHdJwfA5+hY20YA0vcT48IUWCi7WwQHzTw7UFPtKeLh7zKDQ hVIp6Mh3Zy9r+hlkcV7tq4lfSRj8KarOMH1hsU0wtU5TsMwPpQojH+nbj6GlOLbIeLv4 +jhZO00vcRxiZHNXGgeF3S+hR3L32dB4COdBPhYuHCNQFm0yKxrmuDtj6bqNZ+dc+YXg +YtFIbR4weY1BBQz0B7rP74nQ/MdPXSdv8GEvvNZrTZ3qEM7+90jFhcskr9MeYecdSFy qEbjkpuDZQpGRMLUGgTgtiysv0GbpIBS/C1CEamLhE0U4nsXfqErXQbL14F8RQRKrdoG uHSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787050606; x=1787655406; 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:content-type; bh=r9shV1QZCHqW8FXaqflZ+eE8Gymv9k8sKCSVo4d0l9E=; b=Q0rVVBN1LPMiFL72oeYxOBFWQaRNcnaisXfTSJJ7qfjteytEGJLxl0KUhrTYq2Jn40 Z5NUxEW2rMX+9qxHXJW6CPNcdSLJikSrthfurRZuQr5AIKOxwRewBoUUANMD2iphQ+Yf 4ux7L5s8okNwnpv73ALH+l6+yWZ4K9nsw+8KKgKXIQZVjHHISQLOhafG4lnCiazdLN5m QIcDKf9MivhH6wUhLnGTU47cMaFuPy7GK+cpC3LjZPCw/2HlgrM/aRXjeqz5QbFJ7OSh WukgqHEaLVTYWkaOuUlakGc4zwYk6KwtWwhXuaoC/UVUSlPX5biZ0u+GDcEQAYvdprhs Ls9A== X-Forwarded-Encrypted: i=1; AHgh+RpXqiNwLlMCLyytPFA9Z78kbqKT8glh+5oIqwJk5ETPAUHs9PCrIOl2Y4dPxqPGeddbgJAGJxMzCl4heJU=@vger.kernel.org X-Gm-Message-State: AOJu0YylXtIR3di2zFVCrRt/WMB2Wwp8Uqh6iBOxWzODlHbmzLpQiCgd suyKBs7rjkLErupw+T7SMA5qZJTpT0p4fhfd30LfdUEV61SNn7zbPdi4LGbkMw== X-Gm-Gg: AR+sD11NDLFsZBHVf89fkSRg8ai6GnknzLcfCwmY/GZciHcnmW0ZTO9/4H647qnmvgY d06VbK3MF/g+apxaey2rhbm9pcw8wLSnNVrySv21gHpEquWWL0vLsucwaq929Nwi/EX+yU07qCj cB0tF+vili/nDfiJbJfB53Kps7T78ipMPAufxOx4eh6Z7re8INdairtkDe4oDqAQzPbtkmFryou 6AnViC4lRgh6bb09eeX+lnVYyMi/9RHZ8SYlP7RT0/f091WsjyKXpSFzs1Rub1J31Gjd6cZKCwn ecGankBNHgJP/SqtIDnBS8W8tKG8I845fnAi255DtmNnFzAJ/iHVSCzMvysdK3/FU3w/nAhQt1n PiHm/hg0iPNM+SOn2JqLP02DLA0nz0hM6Q0HLZRwzF3wmWUBP7OHpr9Egvn3ZRvwisZn29GnYTK OCJxnoagT1CNr7O3WDx94rM4jtFIpm013roKVO112Uz/OxUcIe26xkCmfxE8oivG95lPOyexgDL 7OLbbF2y2vmUxerstLsRZyz/t/+g6ZNCA8ftyXVIxxLZ9pz X-Received: by 2002:a05:6000:2994:10b0:47f:86af:8fe7 with SMTP id ffacd0b85a97d-482a90e928fmr10235086f8f.22.1787050606226; Tue, 18 Aug 2026 03:56:46 -0700 (PDT) Received: from dohko.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482a5b816f7sm10433069f8f.34.2026.08.18.03.56.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 03:56:45 -0700 (PDT) From: David Carlier To: Jacopo Mondi , Mauro Carvalho Chehab , Michael Riesch , Daniel Scally , Laurent Pinchart , Hans Verkuil Cc: David Carlier , stable@vger.kernel.org, Sakari Ailus , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] media: v4l2-isp: reject zero-sized parameter blocks Date: Tue, 18 Aug 2026 11:56:42 +0100 Message-ID: <20260818105642.65381-1-devnexen@gmail.com> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit v4l2_isp_params_validate_buffer() walks the blocks of a parameters buffer by adding block->size to the current offset, but never bounds that size from below. A block with size 0 is not caught by the block->size > buffer_size test, and the comparison against info->size passes as well when the driver's type_info[] entry is an uninitialised hole, both sizes being 0. The walk then makes no forward progress and loops forever. Drivers build their type_info[] arrays with designated initialisers indexed by their block type enumeration, so an enumerator left without an entry leaves a zeroed hole rather than failing the build. Drivers call the validator from vb2 .buf_prepare, so such a hole turns a VIDIOC_QBUF on the parameters video device into an unkillable task spinning with the queue mutex held. Reject a block smaller than its own header. A block's size includes its header, so anything below that is malformed whatever the driver table contains, and rejecting it is what keeps the walk moving. Blocks carrying only a header to disable a block are exactly that size and still pass. An empty type info entry can then no longer stall the walk, so skip such a block instead of failing the whole buffer: drivers may reserve uAPI block types they do not implement yet, and are free to ignore the block when processing the buffer. Fixes: 3cb6de6fafb8 ("media: v4l2-core: Introduce v4l2-isp.c") Cc: stable@vger.kernel.org Suggested-by: Jacopo Mondi Signed-off-by: David Carlier --- v2: - skip a block whose type info entry is empty instead of matching it against a zeroed entry, so a type the driver does not implement is ignored rather than failing the whole buffer (Jacopo) - reworded the commit message, which no longer leans on rppx1: its missing AWBG_POST entry is being fixed at https://patchwork.linuxtv.org/project/linux-media/list/?series=29170 drivers/media/v4l2-core/v4l2-isp.c | 41 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-isp.c b/drivers/media/v4l2-core/v4l2-isp.c index 1eb46e080afa..439477b2b941 100644 --- a/drivers/media/v4l2-core/v4l2-isp.c +++ b/drivers/media/v4l2-core/v4l2-isp.c @@ -84,6 +84,13 @@ int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb, return -EINVAL; } + if (block->size < sizeof(*block)) { + dev_dbg(dev, + "Invalid block size %u at offset %zu\n", + block->size, block_offset); + return -EINVAL; + } + if (block->size > buffer_size) { dev_dbg(dev, "Premature end of parameters data\n"); return -EINVAL; @@ -100,23 +107,31 @@ int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb, } /* - * Match the block reported size against the type info provided - * one, but allow the block to only contain the header in - * case it is going to be disabled. + * An empty type info entry denotes a block type the driver + * does not support. Skip the block, it is up to the driver to + * ignore it when processing the buffer. */ info = &type_info[block->type]; - if (block->size != info->size && - (!(block->flags & V4L2_ISP_PARAMS_FL_BLOCK_DISABLE) || - block->size != sizeof(*block))) { - dev_dbg(dev, - "Invalid block size %u (expected %zu) at offset %zu\n", - block->size, info->size, block_offset); - return -EINVAL; + if (info->size) { + /* + * Match the block reported size against the type info + * provided one, but allow the block to only contain the + * header in case it is going to be disabled. + */ + if (block->size != info->size && + (!(block->flags & V4L2_ISP_PARAMS_FL_BLOCK_DISABLE) || + block->size != sizeof(*block))) { + dev_dbg(dev, + "Invalid block size %u (expected %zu) at offset %zu\n", + block->size, info->size, block_offset); + return -EINVAL; + } + + if (info->block_validate && + info->block_validate(dev, block)) + return -EINVAL; } - if (info->block_validate && info->block_validate(dev, block)) - return -EINVAL; - block_offset += block->size; buffer_size -= block->size; } -- 2.55.0