From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 801F73E9C20 for ; Tue, 16 Jun 2026 06:38:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781591882; cv=none; b=CeBEmN3+x6sg5+EA1egZOlWzspD0prppCGMYMEn1qLFD8RxP7eRhbDg3W8VdO7QFbYuuZ3Zshf3R5/Xw75rUf3xdrPnUbrNPUDwsCowwigvAg/pB6vpnaFnmHYM4B2XyxVg5Sw70M5yFUaAhuAWRUIld1DSneQ0M81bV3SQfKIU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781591882; c=relaxed/simple; bh=btIkIXXn864fEQMVWfkqCQPV3/nuHcEOithXtaAwfqw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=W5ZIsqEBEBs1kMfK1cVOOP/3r5pUP2c2mZ3OYPxZMmbRxeuJu20+cez8tOS3QznTiwy2k9K2mwVEQGsev7izL4Nmc6mq8KQKH5dofNeq3gafW/+L8cYz0hEzaoD25N2Hzm/liZg86vQPN4vpCf1XVlhrvJX71yQp0/8z1WeOxPU= 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=m2Yz3XWR; arc=none smtp.client-ip=209.85.214.177 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="m2Yz3XWR" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2c0b944f6edso42922245ad.2 for ; Mon, 15 Jun 2026 23:38:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781591881; x=1782196681; 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; bh=fWy2d5NXFNLsaFmC8EODzyXU08rXb/JNeRRY/4BT3to=; b=m2Yz3XWRsBnaDWlgTni2BRKjwvXLYakJw5kxrZUeVJ6EphawKLC6xfCKNOtb/6ngcI GZgX4UkzzHwvC5joGJso6TlEcpIyVW3NvQDzLDzo02d0pj6UN4NUaC5rkp2PEnw1IW3K K/KxZatJmhQwtcYUnaztwWe/YTytnaRfTQP1lG9njdh6Wt24gV1I1E5BeGv2ay2867yo RZgL6TxjhUeBFdMxPHEoSud7nij4oBuKu4kBULtHD2iu9coESVPR+aGEH17vtGLnYK2a pXYhuYE82loP0BnI8DoA2t8E++XQw6I5T+lvK8GsdRAUwsMnd4j/ju9P3ziyLr3dH5jc tw/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781591881; x=1782196681; 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; bh=fWy2d5NXFNLsaFmC8EODzyXU08rXb/JNeRRY/4BT3to=; b=JQULCehL44cHK7OG0N7F/n9se1XCPcLBKEWCSsezs9dAo2QZfKnZUDPeN7YfZOKqKA 4kz7vQX+ZOBqjfG6OHrYCkNb9mFTbUod1JqY1OAuqUA76wXF9ei4ooIIXUMeTEb0o9ht w3cANgYYs0MSME3ogsdRQC1dd6nWT04+OpWWIYFVYwVQmX0R4sF3jzrhzejHE/72AJRh KwbLdmLJF62/mtXEwlw9+llwWqmW+fV44x4SXdbsVhPe2uCwz7Q9H/7Ubm9uGh2vCadM arODC37bUaYYYrLIgeY883iNifCvxNmJjrTPjj3axjZ2+BB47KlB7hy9Fp+3Muh35GYs x2BQ== X-Forwarded-Encrypted: i=1; AFNElJ/M5j8LwgC9I1Q0k8STBWvMvUuNCnyvSDSzAaXQruaHiue8wcZDtI3RE6Ddw41kb8jCbFwHDTdUorerCgs=@vger.kernel.org X-Gm-Message-State: AOJu0YztATSFv+hVoehHk3Zc2zpqKfybG7u2Bt4GHetoyIICJYeTNe7h K2g5kLU1WR6cRmR1ZobZk7sMrYAtYf/5rRoU8iLRCBNqUE/7xrUww8p8gPs3aLO7 X-Gm-Gg: Acq92OEzwFFextr3hlYkcyGYeausS1NHUsP+a9NGKgIW7anGXnft67SNAkJpxoGQdmU iKX7mfuqJug+QGD0f9OdRfcun3ls4LLpo7APf+mMEpDJZ+Put6H6QkFc43dPWdvf2vi9Fl4Hohx 2XxVyN5pbWHdSyvIax8lPVNbAPHrYT4I04Hwal5zBfQ/Tz7AUU1F5egaU3Mqw5+HuCea2KT5MO0 8HeSZBoDHDcIivzlr3VrV8XlD30Bk8AW3vqdx2DHCPhKJgflzPL9RKtycf07tCevQlHi4TvlYY+ r/0MY9RuSmQWc/B7SE2xFMZ7MmqJBeZatYEMdCBQICRi4lNwR6cuCCJLIuY2WVekclCvXE3FKBf F3b5egX1fXCeNQjaqu45c42u1rPGeup88o+BVOUnizF1SdH21vlwyYWSOwYX/h50yd61hGy7hC2 6b8EqexmUk7wLdiO4St8qOXtknm+hBucJ9bFrUS1XKIAo9z9LQPG1F X-Received: by 2002:a17:903:f8e:b0:2c0:d8ee:7d66 with SMTP id d9443c01a7336-2c6642a221amr150179635ad.36.1781591880834; Mon, 15 Jun 2026 23:38:00 -0700 (PDT) Received: from localhost.localdomain ([49.207.217.37]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c4328a4c1fsm120743685ad.53.2026.06.15.23.37.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 15 Jun 2026 23:38:00 -0700 (PDT) From: Biren Pandya To: linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , linux-kernel@vger.kernel.org, Biren Pandya Subject: [PATCH] media: v4l2-subdev: Fix Use-After-Free risk in fwnode pad matching Date: Tue, 16 Jun 2026 12:07:54 +0530 Message-ID: <20260616063754.42163-1-birenpandya@gmail.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In v4l2_subdev_get_fwnode_pad_1_to_1(), fwnode_handle_put() is called immediately after fetching the endpoint's parent node. However, the pointer is subsequently passed into device_match_fwnode(). While device_match_fwnode() only performs a pointer comparison and does not dereference the pointer, passing a dangling pointer is a Use-After-Free violation. If the memory allocator immediately reuses the freed fwnode address for another node, the comparison will yield a false positive. Furthermore, static analysis and KASAN strictly flag passing dangling pointers to functions. Fix this by replacing the manual fwnode_handle_put() with the __free(fwnode_handle) scoped guard, which guarantees the reference is safely held for the remainder of the function scope. Fixes: 8fe784b9abb2 ("media: v4l2-subdev: add v4l2_subdev_get_fwnode_pad_1_to_1") Signed-off-by: Biren Pandya --- drivers/media/v4l2-core/v4l2-subdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 831c69c958b8..24c95082ded5 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -8,6 +8,7 @@ * Sakari Ailus */ +#include #include #include #include @@ -1243,7 +1244,6 @@ const struct v4l2_file_operations v4l2_subdev_fops = { int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity, struct fwnode_endpoint *endpoint) { - struct fwnode_handle *fwnode; struct v4l2_subdev *sd; if (!is_media_entity_v4l2_subdev(entity)) @@ -1251,8 +1251,8 @@ int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity, sd = media_entity_to_v4l2_subdev(entity); - fwnode = fwnode_graph_get_port_parent(endpoint->local_fwnode); - fwnode_handle_put(fwnode); + struct fwnode_handle *fwnode __free(fwnode_handle) = + fwnode_graph_get_port_parent(endpoint->local_fwnode); if (device_match_fwnode(sd->dev, fwnode)) return endpoint->port; -- 2.50.1 (Apple Git-155)