Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795522773; b=nDk9BfvjE+2MvsJAJ2KYu//7JGfFhUz7Q0M6UbTJOkdAspI3xsqkdaLv4oU6BaHBGH7S 4HWGKCh5Oq/8JrvrtaV6xMjdir+dDXza9t+aQtvGT6kULlogHJ6HklUomlD/2U575xdvD RQMn0mP0DCWBiQiKdpdIvwNiP/DOxDJ7EfWbrqwGJSdWZ36m6aiIBP5NwsG5nymCsOYbB POVI6TXUs0hS6M4b+dJhs+Ut4PITSY7wgzgJlfZsKx/U2vkfcrFl1oCMQc+w3pEQLxIyy H4Jh6ShdcH4DJyYRvTGxxS2Sq40JQ5WVd7LO3JarZi7krgkqFgtgAC1g+uvqoGVeCJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795522773; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=V8j/7x8rOY24muk9yPjpnNTz4+yzbaLuw/EWCrjOA/0=; b=QNOtn8ZHU7u7pH3aoRw3UgeDJ1C/GnawvKvc4stOG0YuKF7eruED7+D1XAPQSXC1hoeh Z88p0PXVFHw8dRFBj/6/5nTStqZCQDOi6xhQq2GIjp3eS89llyWAhufgJ81rdSJeZ8fLp Du3j7HhnenNHKAEatoZmAsdCC3ChykwLCkwKLd/CnQCH6JYNlJX4VUoG8o6cigebm4JLW AhpI9KG+mMNLmdcXry3GEA/U7iH+aq0+AvWvAcRAqLPY2mUZT/TSO8PzVZNUOqnSwQ/Uq VCeBilrvpwI+nE/uwZjiIMRNPksl4Bc1kPRPK0yjU1fHoRzvbGb09fDLgf9fCwVueFw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=LSXIIhvf; arc=none smtp.remote-ip=74.125.82.169 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89C61606A31E for ; Tue, 24 Nov 2026 12:19:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 89C61606A31E 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.a=rsa-sha256 header.s=20260707 header.b=LSXIIhvf Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-33fb4680717so11687660eec.1 for ; Tue, 24 Nov 2026 04:19:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795522772; x=1796127572; 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=V8j/7x8rOY24muk9yPjpnNTz4+yzbaLuw/EWCrjOA/0=; b=LSXIIhvfDUn6KxtqknDVWtbk4AT5uBrpHhNoS11CBzz7o0ujd7HkanuJZDBhs2Mzwd 5Niv5ww8jtPhybLx9GO3l8F12HU+Hu7DJuthhPwg58Wzvi3cN1i5PG+VFpL21RzXTGAQ B+39aBLj1i9uZRrnQ8VzOUP5dytUKRohe1vCUs8AIwvTOQc1CrInIIGcQfd5KPLpVJxO ZL5yP90qCMzc+beCP9zDj+Dx9dC9mQMx3KzBPyJdQdk40xO0N1XNikFY2BmPKw4H24J0 qCufH5NIMwYxh6HpQuvS4xY+Z7VZc+uEjpHRDgTztJqwKaKg4GptrFNqB7W49bgUUig1 g07A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795522772; x=1796127572; 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=V8j/7x8rOY24muk9yPjpnNTz4+yzbaLuw/EWCrjOA/0=; b=rGn5/VMWEvjwGHHMruzVTBBT0FosfS2n37aaGwTwqfsfAl2bMpcrthNMntfibL/Lv1 Oy/JdZlJxsIVvCVHG5G/Mr7YUm+T716fZvfeb7lvRqC3oxlGhfFmPD4e/d2Sq1KIdmNv UuNNQwOvlZzx3wXAEQsexH0QCnQA9tNRrg4dykIF/HPkOBfLt7PQEU+FKeqaf8Mitb8X 1YYsRf5mvHgih3TrFx+SQ7/Fqhdm2UWd2JbculXavI/9p5gLMbwyUCtpvYcX8QHy3bE8 jKlviXlWbClkyqYRsRjInT2vRnPko2yfdOFLPIG+PXjfN4ilenIW2hTPvOwxYXZJ1QMg D+WA== X-Gm-Message-State: APuU4Z9h5vhyuOcEILWJSKM2hXrXXdeXh8B6dgY97hcy7sNhUoWgl8bo Yx6ASNYLXjxMKAJahwVxdNZBX0/00Xpg7Tuknr0ohg9QAMndcqqCMx6/ X-Gm-Gg: AZFdTZdj6WD15nsIeHoiAbygyu/B/G+qmE99rOAjnx4VgSfdgEuf91QSBRtDG93iQun 9UiN/pbeQoDqtJV7UQUJu3Cnmud7Ev5/UTmHoMf1JUtgOvh6qSyDblh7Nc0Mkw5gGFf+1firoNO BTC8gvRrhZr+5ka+OQOQh2DBkcokhiTRNaqMVbQEacoXc4A3yVQSwpuA0dJ+5snkT9qwFKQe1py 8yvnWQoDDcwk9XRxWIvP3adEbv+fvH9S+ktkUSdlt2KFCDiz2+PYfj8ycQuNv5+/8+/bJyrg3gd YZZcU0XFuS5hH6EKgMX0ZOUzDwL0w9pm1M8jdz98Qep+BBwiaAWc19nXFK6K/bNM6R+L6arJTfS v0uYSq8XygIJqZ4cYbGR7j9JoDdzvMGwMGdEemZsEcbNWhmILtqvqlM/zqJZ782uwJH5/1IYz3o fe35N6cS9RUFQ5flR2SuL1FbwMBo8ANBxoz0SWqQFeK1eQHdwm3HSTYL1VOONz2+6jBQhRiNpJg KAbi/erJIcKpIwtIPRbb1BW+8iMWkMEjt5uDsSYYs7zuPTbMIDMJBP7aSCvzfEAeR3oe328XoOI w/nknRSWCuRnUAJKaM+O/NzOoyEv65HuC4v+RTJ2pdeRJGWrhK0SCcpyjxDVqoNcjzd79nhbx6x 4W9ejEBdaHNYxQ3T52dC+yRj3VhosjVQLl14= X-Received: by 2002:a05:7301:6582:b0:374:e25e:a533 with SMTP id 5a478bee46e88-38570154017mr27803686eec.35.1795522771545; Tue, 24 Nov 2026 04:19:31 -0800 (PST) Received: from hyeonjun-ThinkPad-X13-Gen-1.. ([124.197.199.8]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38566fdce48sm48153278eec.14.2026.11.24.04.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 04:19:31 -0800 (PST) From: Hyeonjun Hong To: Mauro Carvalho Chehab , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolas Dufresne , Benjamin Gaignard , Hyeonjun Hong , stable@vger.kernel.org Subject: [PATCH] media: v4l2-ctrls: set handler error if array allocation fails Date: Tue, 24 Nov 2026 21:17:30 +0900 Message-Id: <20261124121730.1598114-1-hyeonjunhong330@gmail.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The control framework lets drivers create controls without checking every call: a function that fails stores the error in hdl->error and returns NULL, and the driver checks hdl->error once at the end. v4l2_ctrl_new() does not follow this when the allocation of ctrl->p_array fails. It frees the control and returns NULL, but leaves hdl->error untouched, so the driver sees no error and carries on with a NULL control pointer. vivid hits this with its pixel array control. vivid_create_controls() returns 0, and vivid_create_instance() goes on to call vivid_update_format_cap(), which passes dev->pixel_array to v4l2_ctrl_modify_dimensions() and dereferences it in v4l2_ctrl_lock(). Reproduced with fault injection (failslab and fail-nth) by failing that allocation while loading vivid: KASAN: null-ptr-deref in range [0x0000000000000020-0x0000000000000027] RIP: 0010:vivid_update_format_cap+0xc83/0x1b30 [vivid] vivid_probe+0x37de/0x90b0 [vivid] platform_probe+0x9e/0x140 really_probe+0x1cb/0x6b0 The allocation was first added for dynamic arrays only. Commit 5f2c5c69a61d ("media: v4l2-ctrls: allocate space for arrays") then extended it to all array controls. Set hdl->error to -ENOMEM in this error path, like the other allocation failures in v4l2_ctrl_new() do. The vivid probe then fails with -ENOMEM. Fixes: fb582cba4492 ("media: v4l2-ctrls: add support for dynamically allocated arrays.") Cc: stable@vger.kernel.org Signed-off-by: Hyeonjun Hong --- Found with a fault injection sweep over the vivid module load path (fail-nth, one failed allocation per load) on media-committers next. An LLM assistant helped with the sweep tooling, the analysis and the wording of this changelog. Tested by re-running the sweep with the fix applied: failing the p_array allocation, including the one for the pixel array control, now makes the vivid probe fail with -ENOMEM and no longer oopses. drivers/media/v4l2-core/v4l2-ctrls-core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c index 6e751a043a21..12a799824c44 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c @@ -2263,6 +2263,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, ctrl->p_array = kvzalloc(2 * elems * elem_size, GFP_KERNEL); if (!ctrl->p_array) { kvfree(ctrl); + handler_set_err(hdl, -ENOMEM); return NULL; } data = ctrl->p_array; -- 2.34.1