Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3816216rdh; Tue, 28 Nov 2023 04:54:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKhQlw7e2z5ds7eiXc6zYNPwf/ZjnCWzxjecC8W34ieCcC6th1rTOdEHVvq+Kk1+rdWkl0 X-Received: by 2002:a05:6a00:93a7:b0:6be:4228:6970 with SMTP id ka39-20020a056a0093a700b006be42286970mr16864768pfb.21.1701176070138; Tue, 28 Nov 2023 04:54:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701176070; cv=none; d=google.com; s=arc-20160816; b=cGvyY6xSYJz/VHpkaT9H9nbklimPCp1TTAmrNaMPwgiYTVALgsRf784imLhYbV9HNA emHeH8Vz4027m/b7dRNOkhHccj0eyFhfeHfWZZDQGyjOyN2xsEaxAF43OhrMzT23kjzG HBcULKi1qZJT3ViuEVoY7pNddPsRy54dQc5haphQEBIdkFHhzIafskh11nMsyVhD09Ty syToZuTCRUUlPZgEYVeFVl4YuNlPjfsbqr6PFBUEWZf+pqkLbDkVf3PcM6n2R8XPr8yi HKYzrBZd5f6scOcOyBkwXIl1iAE+OmAcxpZtW5B/Vaswatpj9w6K7c4Vn3+dAp4EhxM6 Bp+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from:dkim-signature; bh=eRRdXX744Ror6v+Fur9Vwwf7uAlxgeKktZhlNiw1Aa4=; fh=BoRo4dkTZsQhF8XRvZq/qFspxK2u5G2gAOmvAAqEMpM=; b=hpGgqdLqE69zsugtS9+89mPlE5fpqZ2KKN2aWnuLOruvSBu+fOKWgsptgJytnGOrJC HAryfkeei1cH+N7NJXTR3UDLND43eQe2vTtDTJc39Ke//QU2n1HneOribvtEFnckvhRz vUzVJGYPInll3jTDM3LBXGJp6zx0d3HvvC1saLW3/3Y83ARkDX+ihTX0JXD1bNPH7UJW 2GhD16FaHlt2t98ngJTMzMTXQOA/jbEdK091P6BpjrGa5VmvsiG5l+bn61GTm4vVxJMs aPyXamE1zGMBxhtufdeivttclkT6DxMg+6IyMXhvg14WqLg9J0woqwNQr4vixOghupP2 Oqlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gXTbmgMB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id m23-20020a634c57000000b0056da0ae25a2si11647361pgl.32.2023.11.28.04.54.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 04:54:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gXTbmgMB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 73BAC8041EDA; Tue, 28 Nov 2023 04:54:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344751AbjK1MyI (ORCPT + 99 others); Tue, 28 Nov 2023 07:54:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344747AbjK1MyF (ORCPT ); Tue, 28 Nov 2023 07:54:05 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59B1DD6D; Tue, 28 Nov 2023 04:54:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701176051; x=1732712051; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=5K++CR/OvistPw0XQfzY/YBgYQVr3P4OlOvmEu/zZC4=; b=gXTbmgMBI9JWxWh3pdsub7ntkhG2pDcAauw3qNg36I6GATPTC1nyAgF9 vPqc8UZTaYjGQko9j/LBoakBrn20KrtCNFcnC9ovXoOQ4uwSbpNKaYpqz ZfQLgyagThHQnCT2KdQSFyeGtTSWsQT+oqzKFeAVl/Pnc7FICIRkSGCU/ cBrDXNB1sWOjs9Jen0SnmTSvWbKm41Dfu/yqTvWJRWnrUDgHL23qM5R2q zS+ZxdJJuoI1VxYFsx6okVE2xRwNcNW6bxIFW4hk6aS3VKQtc85yiWD7M obPkymzN+aNXptgxxh7fIsf4rM+0ElMlIhlqQboYXv1fPHQ/+puycU12R A==; X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="377943906" X-IronPort-AV: E=Sophos;i="6.04,233,1695711600"; d="scan'208";a="377943906" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2023 04:54:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="1015900733" X-IronPort-AV: E=Sophos;i="6.04,233,1695711600"; d="scan'208";a="1015900733" Received: from mravivx-mobl.ger.corp.intel.com (HELO localhost) ([10.252.42.57]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2023 04:54:04 -0800 From: Jani Nikula To: Maxime Ripard , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt , Jonathan Corbet , Sandy Huang , Heiko =?utf-8?Q?St?= =?utf-8?Q?=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard Subject: Re: [PATCH v4 05/45] drm/connector: Check drm_connector_init pointers arguments In-Reply-To: <20231128-kms-hdmi-connector-state-v4-5-c7602158306e@kernel.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20231128-kms-hdmi-connector-state-v4-0-c7602158306e@kernel.org> <20231128-kms-hdmi-connector-state-v4-5-c7602158306e@kernel.org> Date: Tue, 28 Nov 2023 14:54:02 +0200 Message-ID: <87h6l66nth.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 28 Nov 2023 04:54:27 -0800 (PST) On Tue, 28 Nov 2023, Maxime Ripard wrote: > All the drm_connector_init variants take at least a pointer to the > device, connector and hooks implementation. > > However, none of them check their value before dereferencing those > pointers which can lead to a NULL-pointer dereference if the author > isn't careful. Arguably oopsing on the spot is preferrable when this can't be caused by user input. It's always a mistake that should be caught early during development. Not everyone checks the return value of drm_connector_init and friends, so those cases will lead to more mysterious bugs later. And probably oopses as well. BR, Jani. > > Let's test those pointers instead and error out if any is NULL. > > Signed-off-by: Maxime Ripard > --- > drivers/gpu/drm/drm_connector.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c > index b0516505f7ae..2f60755dccdd 100644 > --- a/drivers/gpu/drm/drm_connector.c > +++ b/drivers/gpu/drm/drm_connector.c > @@ -229,6 +229,9 @@ static int __drm_connector_init(struct drm_device *dev, > struct ida *connector_ida = > &drm_connector_enum_list[connector_type].ida; > > + if (!dev || !connector || !funcs) > + return -EINVAL; > + > WARN_ON(drm_drv_uses_atomic_modeset(dev) && > (!funcs->atomic_destroy_state || > !funcs->atomic_duplicate_state)); -- Jani Nikula, Intel