Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp411190ybh; Wed, 11 Mar 2020 03:35:34 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvmkkEmt6sAuqdlwBxuuDnZe/iI4GMFpWTZfHvUuzgO3hcQYCrirBJ8g2B/mfzrQm6lpoui X-Received: by 2002:a4a:a286:: with SMTP id h6mr171381ool.47.1583922934783; Wed, 11 Mar 2020 03:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583922934; cv=none; d=google.com; s=arc-20160816; b=hBVfG7WzJ9zjxJneOzPE3zqBkJg7FDB0DMhRwAsgoZ+0cogNvlgmujRLsmCVgpYP7F VzypFph1bEur11/vN1zngrM74c4YJjhVps+zxlgL0G6WxMqnvftFvzMJzgWs5dlUpsvY K2yy9BO0f3Ib8MH8bYxIxS8/4Yiel2nDUZtHYFbfbiip3dRLr8mAxi2hT6HiDIDNPRXO 4wtrdmTZl+Pk9W2L3xQud2IH7S6aQ7fdkJ5b9lV8Rea1T38a3YgSijnZ+Q8SP4qw5p5d 5cbJ/gLqZxH1exiAP1WI8C9Zz0m3PJ3kDkT014SSkNcNsrkCHBnhIcOfyxbdHODRx3xZ +iWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=62Jjuc6/Y2f5Kkiso4Xvn+Oim+hE7rByIazg5bBNNFc=; b=l4MGyCrZ+waGQ15qNh9RpxPRiVgJE89WqTj6C7YsAipqhPVTvoya7ExFVir4PL1L2u 9c5iKnRNJrgBTFf4wCBdTVUOINvIWEHyVB7n3+HzfoopCH5TieRzttmRy8GGXzw7ma1F tmRP8nhNJEg3+gcLChKVxfFnByK/YENxFuzm7K28kLeODwbw83RBJulBVsit3+UCWsVZ HLmU324wMxlkkw7zhuQZRnQzaYjKWZJA6Ryr0tv3nJ9yko8q6F7G3q5BpovTI6P0k8D3 6Dm4YUNcaxAaYFJLRyF1k++cc+3gczJ6CsPsNy3xB4yybRCrgVrpOi31KXoRfZEphuyN tG/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="Fa1Mst/D"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id o20si99996oos.59.2020.03.11.03.35.22; Wed, 11 Mar 2020 03:35:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="Fa1Mst/D"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728955AbgCKKes (ORCPT + 99 others); Wed, 11 Mar 2020 06:34:48 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:61397 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726672AbgCKKes (ORCPT ); Wed, 11 Mar 2020 06:34:48 -0400 Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20200311103445epoutp01fd170a3262182e243725c2bb47dd9e66~7OXjf67mg0723607236epoutp01d for ; Wed, 11 Mar 2020 10:34:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20200311103445epoutp01fd170a3262182e243725c2bb47dd9e66~7OXjf67mg0723607236epoutp01d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1583922885; bh=62Jjuc6/Y2f5Kkiso4Xvn+Oim+hE7rByIazg5bBNNFc=; h=From:To:Cc:Subject:Date:References:From; b=Fa1Mst/DFQzsQQ3rhgKg2CdAEy32LGEScI0fBVn2DAiB7K13uyksgGk1UjbPrJurc 4HKnRmcMSjm0aijbWYWqGpxSiKr8Q3PLVfVMq16vkd9xLpILdii2bTkOK/h2jwLR0O hN14+c3kYXQstHoDPX+KrvHqo8DaXKErf0pqzzJ4= Received: from epsmges5p1new.samsung.com (unknown [182.195.42.73]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20200311103443epcas5p12d9bfa8ad90323226af85bebe48394e7~7OXiK0hBp2624126241epcas5p12; Wed, 11 Mar 2020 10:34:43 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 53.21.19726.3CEB86E5; Wed, 11 Mar 2020 19:34:43 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20200311103443epcas5p2e97b8f3a8e52dc6f02eb551e0c97f132~7OXhpAlqY0906409064epcas5p2b; Wed, 11 Mar 2020 10:34:43 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200311103443epsmtrp2f3a4b66906b00296d07588e581cb6a9a~7OXhoUU822380023800epsmtrp2V; Wed, 11 Mar 2020 10:34:43 +0000 (GMT) X-AuditID: b6c32a49-7a9ff70000014d0e-a9-5e68bec380a4 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 1E.A6.06569.3CEB86E5; Wed, 11 Mar 2020 19:34:43 +0900 (KST) Received: from Jaguar.sa.corp.samsungelectronics.net (unknown [107.108.73.139]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200311103438epsmtip2c7aa065bd8c5b47fe95f57da41cb28f3~7OXc4Eu6C2573525735epsmtip2k; Wed, 11 Mar 2020 10:34:37 +0000 (GMT) From: Shradha Todi To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kishon@ti.com, lorenzo.pieralisi@arm.com, bhelgaas@google.com, pankaj.dubey@samsung.com, Shradha Todi , Sriram Dash Subject: [PATCH] PCI: endpoint: Fix NULL pointer dereference for ->get_features() Date: Wed, 11 Mar 2020 15:58:52 +0530 Message-Id: <20200311102852.5207-1-shradha.t@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJIsWRmVeSWpSXmKPExsWy7bCmhu7hfRlxBssf6lgsacqwuPC0h83i 8q45bBZn5x1ns3jz+wW7xaKtX9gteg/XWtxYz+7A4bFm3hpGjwWbSj36tqxi9Dh+YzuTx+dN cgGsUVw2Kak5mWWpRfp2CVwZrx81MBWc4a1Yt2I/UwPjE+4uRg4OCQETiRl35boYuTiEBHYz Smz4d4IFwvnEKHF8ew+U841RorFjF2MXIydYx+ujV9ghEnsZJR4cuwbltDBJXLvzFayKTUBL ovFrFzOILSJgLdHwahUrSBGzwBpGiVVLV4ElhAWCJZY/essKYrMIqEqs+XCYDcTmFbCUmLX2 JzvEOnmJ1RsOMIM0Swg0skm8XzoPKuEi8e77elYIW1ji1fEtUHEpic/v9rJB2PkSUy88ZYH4 tEJieU8dRNhe4sCVOWBhZgFNifW79EHCzAJ8Er2/nzBBVPNKdLQJQVQrS3z5u4cFwpaUmHfs MtRSD4mvEy4wgdhCArESU1s/sk9glJmFMHQBI+MqRsnUguLc9NRi0wLDvNRyveLE3OLSvHS9 5PzcTYzgCNfy3ME465zPIUYBDkYlHt4XdelxQqyJZcWVuYcYJTiYlUR44+WBQrwpiZVVqUX5 8UWlOanFhxilOViUxHknsV6NERJITyxJzU5NLUgtgskycXBKNTDmai7f66iwxCVuaVah68zo vOJbk4NOtZU9Y5x1+Vl9+JP4CeGpvNt4TWZUzpbaVVYU3l34ccpZy/6/2pPd332f7LXlckzN sbZkg5LsVuks+4eRcu9PX7re5vt1d8fNl9ZrZT+oSi4Mq4mbWxpeEhu7nHXGiYquRV57T4So pb3jyyk8xDKvNESJpTgj0VCLuag4EQBTPQyR7AIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjluLIzCtJLcpLzFFi42LZdlhJXvfwvow4gyuneSyWNGVYXHjaw2Zx edccNouz846zWbz5/YLdYtHWL+wWvYdrLW6sZ3fg8Fgzbw2jx4JNpR59W1Yxehy/sZ3J4/Mm uQDWKC6blNSczLLUIn27BK6M148amArO8FasW7GfqYHxCXcXIyeHhICJxOujV9i7GLk4hAR2 M0qsW7eMHSIhKfH54jomCFtYYuW/51BFTUwSs1/uYwRJsAloSTR+7WIGsUUEbCUa/nYwgxQx C2xilHh6uYsNJCEsECjR03odzGYRUJVY8+EwmM0rYCkxa+1PqG3yEqs3HGCewMizgJFhFaNk akFxbnpusWGBUV5quV5xYm5xaV66XnJ+7iZGcChpae1gPHEi/hCjAAejEg/vi7r0OCHWxLLi ytxDjBIczEoivPHyQCHelMTKqtSi/Pii0pzU4kOM0hwsSuK88vnHIoUE0hNLUrNTUwtSi2Cy TBycUg2Mui7/tTKrHLPjLrl/zNuWeLXQ2k5CxFtr9vFzUu3pT7OOc1z//k8rtCp3zvneI3ns Ec+e6MVZrXgjm+GS37vWuuLelE9KJ2N1dJJ2Ptavf7D+77e6V5Nzpi8VKZ8YdIvrtr3YljV+ TpaP3yffsjc4tG+DsldH0M/FQav/9C5ISRBffW6v/5bbSizFGYmGWsxFxYkA29JrryECAAA= X-CMS-MailID: 20200311103443epcas5p2e97b8f3a8e52dc6f02eb551e0c97f132 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CMS-RootMailID: 20200311103443epcas5p2e97b8f3a8e52dc6f02eb551e0c97f132 References: Sender: linux-kernel-owner@vger.kernel.org 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 --- drivers/pci/endpoint/functions/pci-epf-test.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index c9121b1b9fa9..af4537a487bf 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -510,14 +510,17 @@ 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; - msix_capable = epc_features->msix_capable; - msi_capable = epc_features->msi_capable; - test_reg_bar = pci_epc_get_first_free_bar(epc_features); - pci_epf_configure_bar(epf, epc_features); + if (!epc_features) { + dev_err(dev, "epc_features not implemented\n"); + return -ENOTSUPP; } + linkup_notifier = epc_features->linkup_notifier; + msix_capable = epc_features->msix_capable; + msi_capable = epc_features->msi_capable; + 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.17.1