From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 4BA38420868 for ; Thu, 20 Aug 2026 11:17:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787224651; cv=none; b=ttxGMCMDQhHwF0DBS1HapN5qx44VBVRed6Of7fvicZ3YUZM51JEaBvEAs5i5bu7mHz/p/ErSkihoqoqLQ9ooBxbVj4+FCI8UA9wcCrn1aF/eca19Vq1tUalhEEaHU47giiavZypv2O0wIg5La4ze0L/dkV4Mx8Fky2WBBXx/TEo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787224651; c=relaxed/simple; bh=hJkDm3W+fV7ZpBCUJIAmMowzdA2NGP/qVikG0lIhhuo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AmZafpo4OMJnS1ofdgTi1A4Ys57WAxKPQSegMW5BmmmUrlgMQJJkQtpaZAOHvU5DmCgj3R1UMtyglKy8aOSRZxvge7dUwsjc069tBb7Wc9W3lgW9vjZG6MJAn0VhhvBGxJZaYMtzdJFIDy4vAuzJW9pKiMf0IYCUwhCT1QlVmjA= 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=IYhBugEs; arc=none smtp.client-ip=209.85.221.47 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="IYhBugEs" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-47f71156e1aso981009f8f.3 for ; Thu, 20 Aug 2026 04:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787224646; x=1787829446; 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=o/+XjvBzWoD2MQbLHFqUD6b0gTe8eLRAGn6npcOPS8I=; b=IYhBugEsjgG2ts7uUHamFNSjeJwcgbAkMzSBmmSOzY/siiFzBVlLQmMthstqNu2lSw tDOOQOEnC4wsj/D/qfwwiHEWczJjZ/VhpHv/sYq4/uQePt1YYjLjJLFJ7wuSD5xvbWHZ 1WTAlB0rlQSiYClUIpZv23Xha38nXdxr9HT6x8qFaWnCY/F1SXCcbHIFpWnELxBYHFpI GxBCtIrgVq5i3OaiAI3h+c8cN8OTf0iA06K8ixhB9bdAVZgVtg3FDtgid7XuOdjx1beV pH2TxLAXneY6gjxQ3GNVzHIq2shx2LyYaUaZsTEqWrx3VlvvvriyK36rdD/Z5DxvDEvV j1Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787224646; x=1787829446; 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=o/+XjvBzWoD2MQbLHFqUD6b0gTe8eLRAGn6npcOPS8I=; b=GRg62FZYX4pymmUv9ULE5AapwM0ATBTU5uGDySwU4B57etP2GjeYmu/FHPtlW+41nk xQ+qEIMAMZrJ9Nuil8oLkgOeB87PG7j0xV0XLrWCXOKl/YtibVO2u8rwoSOI6nMBG9WV moS2SPUKA4cKMHsiuqfmoHEBuMRKILl2r5qvOoYeisfP4XA6IAMh2nwL6TUbQ6BrWNc0 Y+Am5EHvKcR4y9piSNhvEcmRPRSDer+0GXHVZviTC6wNkfZyDs3JfVTGK3uZYlG2xYbw zX+6XiU80BX7rkAgk9CvT+fulwgc7NttJzlpwAskzYuExWPFfW5Om9mxOmX40bphgi61 AQtg== X-Forwarded-Encrypted: i=1; AHgh+RpUqcbZFfKF8sLpirFiYRwqfKc3hpZKIx9uzvvzD+BTKMB/ewfKmjrPNwDLy6InHN2oiOPEFv+Hw6he2nc=@vger.kernel.org X-Gm-Message-State: AFuF++n6eXnlf5ArftodkBTPgtlkJ/AqXefy6ieqhIEX+3xIqhlTmnN6 /jMsIpAS/fuf8JTwmy7r5AN8j5pUjuKDI89gHf4pbicTGPJ/ob+9EYbT X-Gm-Gg: AR+sD100OxZExdOq1cwVW/2PP4QH634Lex3Dlro6fy0CQ02l1TH/9Dz6nnVxh+PnR2G /+YZgHTQ8UK3xIdaPTb7dLueq75r42386BRwW0MXeyT5AjW4tFYnAI96fPEiMI5rGYE1ELEy67A ZQn4QGiakF+/3W3xWjPo1jmKbcL/fahZc77fyNmq/i7x2bG63irhBCTwofidYibkcWTy3E4N1G9 +RqiMGzU5X2Px87YAmzKBKOKiGE5tJT1bLHnfjBKjpCb++8JJ0sB1Uun1eHhxrWJpsV6FWq+sik hVg+G2/4E66svEy4e+rYyEqfeU1jRVv+NqQSk3IeGOxXCMRKsvVcdi49hMpybhqXuVCH18Uo/z1 192++0z2rUE+vrRe5lCiLQOPtKpL7PgWU6Jmsv6iUFmxDmCoZo0BtMD86Ww4ZJiKsWgF66Q8A65 lBP9clWMx/fsEmede/D4WMna8AAi9/poO3e47HbU7l1ksYqnzcm37DI1bNPBkf3QyZXzKu5NWdX I6PQA1HDLyzFiCNMnO6GjE9S5UX+fCeKrZFueAFgaZBmdRS X-Received: by 2002:a05:6000:41c7:b0:481:5167:abda with SMTP id ffacd0b85a97d-482b1e9e2a8mr21500418f8f.9.1787224645446; Thu, 20 Aug 2026 04:17:25 -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-482b14b8050sm12957987f8f.19.2026.08.20.04.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 04:17:24 -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: Thu, 20 Aug 2026 12:17:22 +0100 Message-ID: <20260820111722.1233915-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, 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 --- v3: - reject a block whose type info entry is empty instead of skipping it, so a type the driver does not implement cannot become unconstrained uAPI (Jacopo) v2: - skip an empty type info entry instead of matching the block against a zeroed one - reworded the commit message, which no longer leans on rppx1 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