Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 4389539BFF1 for ; Sun, 14 Jun 2026 17:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781459597; cv=none; b=g2lw1stzzGOEkOwC/6Q6hXWNeWpbGpoXi4sw1aWBNsdIizvHpeKUBIdjMIVin8HjOYQ8S4NDOVWgyC1N/edHAWtCpZKCYPcOzoY3PkGz6zHZK+B1sawru2Sn1YF2L6vVdCDnlssjn+V7wd/7Gqw7M7us6NUoZ3QaVJYumrn2VuI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781459597; c=relaxed/simple; bh=N2hAp83u/oqVbMes7YLRZAZjMpGI+8n1giXaShw5BjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ch9uBhc+/VOQnLJzrabFhMtYxTWA4exp8gGwiFvPJ8Pq6YRmAsOjNjfdekWqFPmLBCIJ+U9BPwdQWNbej++aQxF7Kf9Rjk3I6EkrACpt19BKftptFsl6WcP3P32+lQgJjPB7hRp6yJ3fK9cH4I+c4WfTHOfjvBogw1FLOIJk8dI= 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=XlZnOhYe; arc=none smtp.client-ip=209.85.216.48 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="XlZnOhYe" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-36d98c9b596so1595694a91.3 for ; Sun, 14 Jun 2026 10:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781459595; x=1782064395; 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=GY3uERKW0203JlRK3+ZltRV41Bjt0TN6PDYkVIm//9w=; b=XlZnOhYeccCPMjmyCtlt5WuWvcic9q4qPFIb35l8CJtzYCaUzYrDYtpTiRBlNyRhvo BlcFGekFvFTjL2rw0Ox2P50wM35uCf09zwv427RsZ19URXU7Mmj1qkEbCoLKMwfGf0VZ OpCnKQH7I1BDa3DPLvYQWShP17AmGkSsiabLn8UQE2brWDChpOaMNH8zS3LTjb4MACRA Z4rBpES5zywUrHBV1UwapXG2FOMn5Rlm26B74FJvfsjluqmSKlWvySHyt093GWzseUeM WuG+0ucqbIiNO19XpeisLMz9p3XgiyR8KBdvp6gJaY4/5A2pODQ+1GsjoGT/ZjTOfUbf aI5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781459595; x=1782064395; 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=GY3uERKW0203JlRK3+ZltRV41Bjt0TN6PDYkVIm//9w=; b=Jtz1HgLFHKs9QJQu5OqaBlDvp2XkcBdhO5lx3Um4p9u+TWPVUAGbSsrXFF4Vuff7PU B4nNJEKDa/uwuR+rDll3zG9kwd9aNzx6BrhXVl5/2tlOdoTF86gjFzjGq5huDqNhMLeh Vgs26BjoqYklxVSV4m5f2OTQjpBWzZV8loPIO3sAcjV5BLWl9/v8G7Aj/LypBmnZ8yre Ni90rNE4hmTPTE5wqBg3tKW4Cd6n+3dMMB9kfesCNk3xlsCCCj3goFFyXaZfPTPCStW8 vgPOfI4Y7URdrg8fN7EdgsA5P3l4lvwhM3llDAbShC+jxK83K5KPujGa2uUqPNLCyBq6 nRbQ== X-Gm-Message-State: AOJu0YxyMQBaYSGZam/qrGbSAvsFGJHSkm5TUwE6seeLe3Hvkfrm0+F5 rCZCHBiNHsXjTVVAwCbDusuxMOCGVc9CHfN7We9tqWpBgfp3WcRfR5ZoMnHtPmdy X-Gm-Gg: Acq92OFHdmoQrZXUlYUK0k/xyJoEU7n4tvsNDA6NpkAtsa+Ew8+Lpl/B1UNISkcHlE8 5sMRP7wWqwHHOqZatICSOmJ1K+klYUFDwjHMiXsdh4FdBMhlqRAn4qQpTGmj0xWgjmcyqjupSSv HQdt0gOay813ITSLwInEB6n+b56briXGmNt+jwHXKXe2a4HZEjC4NBKJYPFcKBFgRDiQmJllEKT aF9bwt2iRgH6ZlvfH2e75mRFPO6T9GZriZyxEINNO9rwayK+0xZWDC1xj2jAJjpG4wOUqClUXh2 aVB7MFg05E+oPr0WI9gK0G1WDnV+syATWnfEhLhzvoKOl+ERSE1NbMQsU2W1EEF1Z5azSaq0f1S tKv2msJleFoRKs1FaYaQuDy1IE+f9W/j14dqoTjYtMez0l6fz/cAt7S7mD5GDH+8khJAkoYISQn ATQd0e+zVMb+b5BOpxj5uAqBq9H7rQLeZCMnWmPPBDFOuMeNjUxJQC6DJnYzmJXiA= X-Received: by 2002:a17:90a:d004:b0:36d:81b3:61a1 with SMTP id 98e67ed59e1d1-37a01c34487mr11232148a91.7.1781459595503; Sun, 14 Jun 2026 10:53:15 -0700 (PDT) Received: from localhost.localdomain ([49.207.217.37]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-37a1eba8e9asm7913694a91.2.2026.06.14.10.53.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 14 Jun 2026 10:53:14 -0700 (PDT) From: Biren Pandya To: linux-media@vger.kernel.org Cc: Biren Pandya , Mauro Carvalho Chehab , Laurent Pinchart , Hans Verkuil , Tommaso Merciai , Geert Uytterhoeven , Lad Prabhakar , Biju Das Subject: [PATCH v2 3/3] media: platform: rzg2l-cru: Add missing media_entity_cleanup() + fix UAF Date: Sun, 14 Jun 2026 23:22:12 +0530 Message-ID: <20260614175221.6619-3-birenpandya@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260614175221.6619-1-birenpandya@gmail.com> References: <20260614175221.6619-1-birenpandya@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch adds a missing call to media_entity_cleanup() in the probe error path and remove function to properly release media entities. Additionally, it fixes a severe Use-After-Free vulnerability in rzg2l_cru_group_notify_complete(). If media_create_pad_link() failed after successfully registering the video device and IP subdev, the function returned directly without unregistering them. If the probe function then tore down the parent structures, any subsequent userspace access to the stranded video node would result in a Use-After-Free. This patch adds a cascading rollback block to unregister the video device and IP subdev on failure. Signed-off-by: Biren Pandya Assisted-by: Claude:claude-opus-4-8 --- drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c index 3c5fbd857371..3ccd895c09fe 100644 --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c @@ -50,12 +50,12 @@ static int rzg2l_cru_group_notify_complete(struct v4l2_async_notifier *notifier) ret = v4l2_device_register_subdev_nodes(&cru->v4l2_dev); if (ret) { dev_err(cru->dev, "Failed to register subdev nodes\n"); - return ret; + goto err_unregister_ip_subdev; } ret = rzg2l_cru_video_register(cru); if (ret) - return ret; + goto err_unregister_ip_subdev; /* * CRU can be connected either to CSI2 or PARALLEL device @@ -71,7 +71,7 @@ static int rzg2l_cru_group_notify_complete(struct v4l2_async_notifier *notifier) if (ret) { dev_err(cru->dev, "Error creating link from %s to %s\n", source->name, sink->name); - return ret; + goto err_unregister_video; } cru->ip.remote = cru->csi.subdev; @@ -84,10 +84,16 @@ static int rzg2l_cru_group_notify_complete(struct v4l2_async_notifier *notifier) if (ret) { dev_err(cru->dev, "Error creating link from %s to %s\n", source->name, sink->name); - return ret; + goto err_unregister_video; } return 0; + +err_unregister_video: + rzg2l_cru_video_unregister(cru); +err_unregister_ip_subdev: + rzg2l_cru_ip_subdev_unregister(cru); + return ret; } static void rzg2l_cru_group_notify_unbind(struct v4l2_async_notifier *notifier, @@ -300,6 +306,7 @@ static int rzg2l_cru_probe(struct platform_device *pdev) error_dma_unregister: rzg2l_cru_dma_unregister(cru); + media_entity_cleanup(&cru->vdev.entity); return ret; } @@ -316,6 +323,7 @@ static void rzg2l_cru_remove(struct platform_device *pdev) mutex_destroy(&cru->mdev_lock); rzg2l_cru_dma_unregister(cru); + media_entity_cleanup(&cru->vdev.entity); } static const u16 rzg3e_cru_regs[] = {