From patchwork Thu Mar 9 12:27:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 661362 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0059EC64EC4 for ; Thu, 9 Mar 2023 12:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229577AbjCIM2S (ORCPT ); Thu, 9 Mar 2023 07:28:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjCIM2Q (ORCPT ); Thu, 9 Mar 2023 07:28:16 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 872C7E1C80 for ; Thu, 9 Mar 2023 04:28:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678364895; x=1709900895; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=UtTmCgHupJ+hImF/+YBHCqqgh95ITYLtA1s6b0w/TrE=; b=F5shBe2f7LpRq6HZZ0hGlrTLMRBqWtEEMfu5qlVZEHXjhkoffYHw7M// MSbT9f02qzYFPxn7bqU0zyPJOWdC07PJ19eMtE70mIeHG9McnxnJX9anF 1J7MgvVnWByo9amhK7uMfLGWBEaHEMHFdTdIkjEsoqBQCWSz/C12NC3Qh WlDEeMzaUSaXtBwvqHdzxEd2RZghGwXUlvmt1lKe6eXr/7WFDBzMPiB4u BMYN9OMXw2zA3Cq1NUn09R5jSnCORTG/TmiAng5f1lcM/I5HkOM1GczMA vdtph05tgdc6wppnd0Nzz/u89ungQEVQwxW+3+S4MSVR3JTbKmm6gb/+C w==; X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="335135437" X-IronPort-AV: E=Sophos;i="5.98,246,1673942400"; d="scan'208";a="335135437" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2023 04:28:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="746306592" X-IronPort-AV: E=Sophos;i="5.98,246,1673942400"; d="scan'208";a="746306592" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2023 04:28:07 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by kekkonen.fi.intel.com (Postfix) with ESMTP id C6E48122D85; Thu, 9 Mar 2023 14:28:04 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1paFMk-006oWc-K5; Thu, 09 Mar 2023 14:27:26 +0200 From: Sakari Ailus To: linux-media@vger.kernel.org Cc: Tomi Valkeinen , hdegoede@redhat.com, Laurent Pinchart , Kieran Bingham , Kate Hsuan Subject: [PATCH 1/1] media: v4l: subdev: Make link validation safer Date: Thu, 9 Mar 2023 14:27:16 +0200 Message-Id: <20230309122716.1624141-1-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug. Ignore the error but print a debug message, as this is how it used to work previously. Fixes: a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()") Reported-by: Hans de Goede Signed-off-by: Sakari Ailus Reported-and-tested-by: Hans de Goede Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 1bebcda2bd20c..dd911180ec899 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1209,6 +1209,17 @@ int v4l2_subdev_link_validate(struct media_link *link) struct v4l2_subdev_state *source_state, *sink_state; int ret; + if (!is_media_entity_v4l2_subdev(link->sink->entity)) { + pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n", + link->sink->entity->name); + return 0; + } + if (!is_media_entity_v4l2_subdev(link->source->entity)) { + pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n", + link->source->entity->name); + return 0; + } + sink_sd = media_entity_to_v4l2_subdev(link->sink->entity); source_sd = media_entity_to_v4l2_subdev(link->source->entity);