From patchwork Fri Dec 18 15:45:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shradha Todi X-Patchwork-Id: 11983207 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27C4BC2D0E4 for ; Fri, 18 Dec 2020 22:51:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3E5623B99 for ; Fri, 18 Dec 2020 22:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726244AbgLRWvl (ORCPT ); Fri, 18 Dec 2020 17:51:41 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:27384 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgLRWvk (ORCPT ); Fri, 18 Dec 2020 17:51:40 -0500 Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20201218225058epoutp020f2a434fb0be040aea753660ac5aa0c7~R8U3ERaSE3229732297epoutp02x for ; Fri, 18 Dec 2020 22:50:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20201218225058epoutp020f2a434fb0be040aea753660ac5aa0c7~R8U3ERaSE3229732297epoutp02x 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 pBYfYpTmYFES51X6cSZOSCA9sSQ1O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7MEKquezNm/R3UD3/un9zolrthtSNA/kPPt97SPVXnip0Ml2D694T998/SJXCbJ WNnXj07P7ln3oTWjq7cqVGZbUfl+D23lrmdFFjpv5z4r0u9k6FFd0DG/M7duZqZS9b38Mm3N D5o1zRyVa1/u3vPs++zzeq+lTsVc0y4ontbwS0v/tdKRK/s+VPsfaqqdv7Xdq+q35WElluKM REMt5qLiRAA8rxwrlAIAAA== X-CMS-MailID: 20201218154704epcas5p1446559adbd4a5b267a4c940b5f744970 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20201218154704epcas5p1446559adbd4a5b267a4c940b5f744970 References: Precedence: bulk List-ID: X-Mailing-List: linux-pci@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;