From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 24AD33CF1F5 for ; Wed, 19 Aug 2026 21:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787175310; cv=none; b=V/apvs6qBEOuuogwvfZ8BzULfxsRQOCsoABEJXu/EZ7VueKVYNWAB7mpFssfnEOZ2UCY0A07evKVNa+YXVqQ+V+oZJiGrXrmiNnm42dfarGGHTQJFJv36MdfnPf3qLTLsQ637US0zTuwLXLk+Lx5FAmarnJHVlGmuA/nEa/ClS4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787175310; c=relaxed/simple; bh=XCyWI21c6Ia4UYKaZMPJwr2tuL0rzz7GONunasW8keE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l7fDDl8q2BY1aWeNVLmcnZSCEppFcn1JYd/iK9azkPyy21Vs0fbKX9LRcYlOj+TkxqR6uyDYEhLlmlWmO8LV8x5tjxF/uWCK9P11w08apn6ch9Npmab0L0E+w8UmBLxyhq+c3P4oFX8tZRA8vV0wCyIRNPVfHiQ0EFz9lFQOqBA= 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=Hkt2rffq; arc=none smtp.client-ip=209.85.128.49 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="Hkt2rffq" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-49800c6a846so16032605e9.3 for ; Wed, 19 Aug 2026 14:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787175303; x=1787780103; 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:content-type; bh=XoBJmiYxKbOhM9EJaI6KrJ7+GoQWOfMWCpsZ2kanZl4=; b=Hkt2rffqbv+NASAbl+uxj2WE1L7qNfmhlq0C00DdEAk8t486A9L9M17dNbstMf9bm8 UhG1jfiiz3dJbAFfiG6IJYBvg1y6poSnk2WafHZoTnXx6KvOUKesERfoHTYK7+zzU8Sc n+WN01NGHAPtzRxZyfOzSkV1u4zg/GVaHXhhqbJjacTDeXeFG+4owynBNAsB5ibp4CF+ lpwjEdHXky132FYCkp8NM4C51kgSAJ1+mLyF3wFGlrKlup9Yf+1E/GgJPMgRIGlTQ/Ik AJ55Nl9uPDzRRMoKL8EReLga2Accp5yk2I+8Dq+4wCiD+LWOFjsbkCxNi4/B56z+su1G ptRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787175303; x=1787780103; 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:content-type; bh=XoBJmiYxKbOhM9EJaI6KrJ7+GoQWOfMWCpsZ2kanZl4=; b=gApGZ41NaXLBDRgE4S+3yvGQuj+5jt4zFzmfaLd9b9lJQkSDqjlT6zEn6IfntPeF+8 1ILzoYYsFs5qp8POAH994sH18wazyph8BusE+PGQwDgDEi+bNZ3PwlZ1I7te/VV7gyDz riQ+OQ+Pr3FEwE9v75tZ7vnN8cQZ6Pb2nROrizWOWB+fnfZ8hZ10IVL8KXwZMLieyNUN kxE+K6PJc+uQqlPEPpsNMUIaonddsS2w0izrR/D0hWPEr26iAJ8lzADuhSivTi+vSs9A bM6i4maSs6JOCm1QbbkVLCCt2uDRDSYa64gyGZ5+n7AQHIgEEijKC72XZUL2vsQK3USj ZHZA== X-Forwarded-Encrypted: i=1; AHgh+Rr29TAdl4EZ44qJrZ1kJx76ASN97Hizf+Lrlj3q7SYqeSDxsvEo+X/xHBWL0SblytwZfRp/UsTdsqIF180=@vger.kernel.org X-Gm-Message-State: AOJu0Yxba4FdpzVxfyYU7dy2bK20RtK/TTg+/9inKt4FKBcgegd+bci0 DiCdbj3bS+PvPY9uWEGirqu6Es+StvGjMsV1PmUn4bJxbMzz4O6tGsjR X-Gm-Gg: AR+sD12KNN3LA6a9osZO1LKuuq8Le3fyXm2WROq9zx9+tafQcoXkOBkyh/2+hgjwfEP lVfXAnVSvMPKskMo4PisVZAVOLQcI9Ycfkrp2hhy258y4xlWqvhqf4DO0e+xm+5uL6yb9Eurwey 0V2T73UYv/m29IqIy3jH8nnPti4P5F8CLHsf9e9sEl8ZTPV0CBka8WlrWPZDk81Ii8KLKe4swnD KL/18hf3Rxf9z064q4ZGFv6WM5JgFj+n3H5rjKHJfC7kEoGN4POZS2WbVd38ZML5utaHA+POKVJ DG1eyQFAC3Z/ozuinXtT+/qdv7Y7AoLhc+DrPdAWsAZqrZAT8+W8avjDfqiSOtzgQuBK95UR6i0 PHM94QTvCjaFnQSMeK9KB0JC85zbqcA0zuYv7EMO8tqrEEwkc01uK29ZlC5n6gVWPsDE0YxrSho uEnT/KpbRsuwSd8d/bauXM5M7UCoQkMNe0rzO4lFGxWj1xc7N3SI6dSqnhb23JnDaYVGZwf8rNM CDpkRiu0qtEbTWFITFDVrFiLc6boIXgnebS+NXVvhReMum/ X-Received: by 2002:a05:600c:37c6:b0:499:60bf:c6f7 with SMTP id 5b1f17b1804b1-499aa1dbb12mr157441035e9.13.1787175302615; Wed, 19 Aug 2026 14:35:02 -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 5b1f17b1804b1-499b19dba34sm9633365e9.9.2026.08.19.14.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2026 14:35:02 -0700 (PDT) From: David Carlier To: Jacopo Mondi , Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org, David Carlier Subject: [PATCH v3] media: v4l2-isp: reject zero-sized parameter blocks Date: Wed, 19 Aug 2026 22:34:56 +0100 Message-ID: <20260819213459.1220894-1-devnexen@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260818105642.65381-1-devnexen@gmail.com> References: <20260818105642.65381-1-devnexen@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: 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, but a block matched against it is only constrained by that header size check. Reject such a block explicitly: the driver does not implement the type and cannot tell whether the block content is meaningful, and accepting it silently would leave that content unconstrained until a later kernel implements the type and starts validating it. Fixes: 3cb6de6fafb8 ("media: v4l2-core: Introduce v4l2-isp.c") Cc: stable@vger.kernel.org Suggested-by: Jacopo Mondi Signed-off-by: David Carlier --- drivers/media/v4l2-core/v4l2-isp.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/v4l2-isp.c b/drivers/media/v4l2-core/v4l2-isp.c index 1eb46e080afa..efe994b4c4d7 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; @@ -99,12 +106,25 @@ int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb, return -EINVAL; } + /* + * An empty type info entry denotes a block type the driver + * does not support. Reject the buffer instead of ignoring the + * block: accepting it silently would let userspace fill it + * with data that a later kernel, once it implements the type, + * would validate and possibly reject. + */ + info = &type_info[block->type]; + if (!info->size) { + dev_dbg(dev, "Unsupported block type %u at offset %zu\n", + block->type, block_offset); + return -EINVAL; + } + /* * 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. */ - info = &type_info[block->type]; if (block->size != info->size && (!(block->flags & V4L2_ISP_PARAMS_FL_BLOCK_DISABLE) || block->size != sizeof(*block))) { -- 2.55.0