Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2490306pxu; Fri, 18 Dec 2020 14:53:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzaydWoCI8MNdEIQ3+lno7dxomLTG3N5rbjOOw1SmnkzJGIw79rt2ZeNS0s9h+rjtc3fhQ X-Received: by 2002:aa7:c3cf:: with SMTP id l15mr6810554edr.282.1608332019231; Fri, 18 Dec 2020 14:53:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608332019; cv=none; d=google.com; s=arc-20160816; b=OyQxXd6jfm2doP9k+p8YMEdzueDDp8rxhR3JvgnhaMUpf0mnjwiFGZFlz46f0IjOIU tncYOmxGnHsOELSM/69rxIk51bGg5SSTT4qSplFtGHTYeMgWA0GvIamdQx4Alv/uI8GJ VqTTLcqejL9w1IUknO+aMKzWMHB94PbmDb/YLiIkbewQ0S4yAH5b0U3xY9lrHnB3/pAE /isO1OApY14s9Z1zmYPcNKAGuG+sAw9vZOca3PJo/B7lovJf/IrvOfCnBHG51l7+q4XS LsOyMWXLA3A+aCaomSKjpKqax7clLXYInPgpufCFZk00Mt1bdH8JZz9Fg/wz3vfhmbJi ag4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:message-id:date:subject:cc :to:from:dkim-signature:dkim-filter; bh=Z2NFqj8VfHHzdtjUbgSEQIilQ+fIwqpC7aWCnUGTR2g=; b=qrhpQA/FW1v7A5vvT6gegJcluzC0IRpedXhB35e3bF/iDQTyVTXymvgEjAyJe/CS37 +bTtO4JSSIqXL/b9uoFfRgIUeyyGYK2tkSkQ+A+ivGZJR6bGrsV4D/4hlttBb7X74kkP rJ3t0UAFhJNXO0Cc7SLHTNTokdx38sF9+EE83dJbVovjS6uRZMpzBqB7qyQGxECqT7s1 Wn+OgSWNsc+TD/FTiOlF7MUGm/5GtN2kFOch/4ThtiHhOWlTtZK4yxasvLPcNm/ShaY+ 84eHFXOActdk4YjNTX0KnSAVdu7Q/CAOhB/gzqlEmRSxVmnekp8N2cE5pcXjNCtEn2A6 gdMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=FQ2BdZma; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si4289895eje.134.2020.12.18.14.53.16; Fri, 18 Dec 2020 14:53:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=FQ2BdZma; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726279AbgLRWvp (ORCPT + 99 others); Fri, 18 Dec 2020 17:51:45 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:52362 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgLRWvo (ORCPT ); Fri, 18 Dec 2020 17:51:44 -0500 Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20201218225058epoutp0196cd83ee7d92b1129b76cc1fd06d7b8b~R8U3IjNo-0714907149epoutp018 for ; Fri, 18 Dec 2020 22:50:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20201218225058epoutp0196cd83ee7d92b1129b76cc1fd06d7b8b~R8U3IjNo-0714907149epoutp018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1608331858; bh=Z2NFqj8VfHHzdtjUbgSEQIilQ+fIwqpC7aWCnUGTR2g=; h=From:To:Cc:Subject:Date:References:From; b=FQ2BdZmaClWsZG5XIV2kbR5+0zSn6PrSVZRoc2KnOtmX1K3BKvGbCftk5HihBUcsh z3PeIH4O3LBxnM+wukxZxpnnVJOeAZVQlTQexYi4VgncaQKc+FytYOrZ+7z//Tm4n/ 1Y4j+IoWhTr+8hkkXYedJHvbPAq3YrC4l4FiKAyQ= Received: from epsmges5p3new.samsung.com (unknown [182.195.42.75]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20201218225057epcas5p4f495fd8fe622e1dbeb9cfab70bd3233f~R8U2VnzOw0934509345epcas5p4s; Fri, 18 Dec 2020 22:50:57 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id C1.E1.33964.1523DDF5; Sat, 19 Dec 2020 07:50:57 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20201218154704epcas5p1446559adbd4a5b267a4c940b5f744970~R2ivw4tl20804008040epcas5p1r; Fri, 18 Dec 2020 15:47:04 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20201218154704epsmtrp17777a88462abe3c39565ad1005f6c9ba~R2ivwE9EO1669016690epsmtrp1M; Fri, 18 Dec 2020 15:47:04 +0000 (GMT) X-AuditID: b6c32a4b-ea1ff700000184ac-e0-5fdd32514028 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id EF.83.13470.8FECCDF5; Sat, 19 Dec 2020 00:47:04 +0900 (KST) Received: from ubuntu.sa.corp.samsungelectronics.net (unknown [107.108.83.125]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20201218154702epsmtip1d520d154f76a28cbaf8a63578d78876a~R2iuiKap72025720257epsmtip1Y; Fri, 18 Dec 2020 15:47:02 +0000 (GMT) From: Shradha Todi To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Cc: kishon@ti.com, lorenzo.pieralisi@arm.com, bhelgaas@google.com, pankaj.dubey@samsung.com, Shradha Todi , Sriram Dash Subject: [PATCH v2] PCI: endpoint: Fix NULL pointer dereference for ->get_features() Date: Fri, 18 Dec 2020 21:15:16 +0530 Message-Id: <1608306316-32096-1-git-send-email-shradha.t@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJIsWRmVeSWpSXmKPExsWy7bCmum6g0d14g4a1EhZLmjIsLjztYbO4 vGsOm8XZecfZLN78fsFusWjrF3aL3sO1FjfWsztweKyZt4bRY8GmUo++LasYPY7f2M7k8XmT XABrFJdNSmpOZllqkb5dAlfGkjVf2Aou81b8vjuNqYHxJXcXIyeHhICJRMvxL6xdjFwcQgK7 GSXm3f/CBuF8YpT4sewQC0iVkMA3Rokvh41gOppn3WOBKNrLKHH7+CuojhYmifWzHjGBVLEJ aEk0fu1iBrFFBKwlDrdvAStiFljDKLFq6SqwhLBAmMSqCwfYQWwWAVWJ/zN72EBsXgFXiYPz D7FBrJOTuHmukxmkWUJgE7vEtiXbWSASLhJ7Nt5mhrCFJV4d38IOYUtJvOxvg7LzJaZeeApU zwFkV0gs76mDCNtLHLgyByzMLKApsX6XPkRYVmLqqXVg9zML8En0/n7CBBHnldgxD8ZWlvjy dw/UBZIS845dZoWwPSTOtm9lgoRWrMTG/xMYJzDKzkLYsICRcRWjZGpBcW56arFpgXFearle cWJucWleul5yfu4mRnDsa3nvYHz04IPeIUYmDsZDjBIczEoivKEPbscL8aYkVlalFuXHF5Xm pBYfYpTmYFES51X6cSZOSCA9sSQ1OzW1ILUIJsvEwSnVwHSnZdOjmc4ntxZN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SPVXnip0Ml2D694T998/SJXCbJ WNnXj07P7ln3oTWjq7cqVGZbUfl+D23lrmdFFjpv5z4r0u9k6FFd0DG/M7duZqZS9b38Mm3N D5o1zRyVa1/u3vPs++zzeq+lTsVc0y4ontbwS0v/tdKRK/s+VPsfaqqdv7Xdq+q35WElluKM REMt5qLiRAA8rxwrlAIAAA== X-CMS-MailID: 20201218154704epcas5p1446559adbd4a5b267a4c940b5f744970 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20201218154704epcas5p1446559adbd4a5b267a4c940b5f744970 References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org get_features ops of pci_epc_ops may return NULL, causing NULL pointer dereference in pci_epf_test_bind function. Let us add a check for pci_epc_feature pointer in pci_epf_test_bind before we access it to avoid any such NULL pointer dereference and return -ENOTSUPP in case pci_epc_feature is not found. Reviewed-by: Pankaj Dubey Signed-off-by: Sriram Dash Signed-off-by: Shradha Todi --- v2: rebase on v1 v1: https://lore.kernel.org/patchwork/patch/1208269/ drivers/pci/endpoint/functions/pci-epf-test.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 66723d5..f1842e6 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -835,13 +835,16 @@ static int pci_epf_test_bind(struct pci_epf *epf) return -EINVAL; epc_features = pci_epc_get_features(epc, epf->func_no); - if (epc_features) { - linkup_notifier = epc_features->linkup_notifier; - core_init_notifier = epc_features->core_init_notifier; - test_reg_bar = pci_epc_get_first_free_bar(epc_features); - pci_epf_configure_bar(epf, epc_features); + if (!epc_features) { + dev_err(&epf->dev, "epc_features not implemented\n"); + return -EOPNOTSUPP; } + linkup_notifier = epc_features->linkup_notifier; + core_init_notifier = epc_features->core_init_notifier; + test_reg_bar = pci_epc_get_first_free_bar(epc_features); + pci_epf_configure_bar(epf, epc_features); + epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features; -- 2.7.4