From patchwork Tue Jan 12 14:02:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shradha Todi X-Patchwork-Id: 12013687 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=-19.0 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, USER_AGENT_GIT autolearn=unavailable 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 CECF4C43381 for ; Tue, 12 Jan 2021 15:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74E0823134 for ; Tue, 12 Jan 2021 15:09:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389915AbhALPJz (ORCPT ); Tue, 12 Jan 2021 10:09:55 -0500 Received: from mailout3.samsung.com ([203.254.224.33]:44266 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbhALPJy (ORCPT ); Tue, 12 Jan 2021 10:09:54 -0500 Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20210112150911epoutp0313cc1a25cb930639fe39567d1c863fc0~ZhJ0Gva8W2462824628epoutp03E for ; Tue, 12 Jan 2021 15:09:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20210112150911epoutp0313cc1a25cb930639fe39567d1c863fc0~ZhJ0Gva8W2462824628epoutp03E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1610464151; bh=u0BvEO9atwxSB4/hI99enjFl2P1vLmAKRGdyk/BKm7w=; h=From:To:Cc:Subject:Date:References:From; b=aV5g88+PsO/7jE5M0FJ7mAY1rjhw0RdnXHEz0QalAYi5397gu8UEFRtTiIBoCYekt 4Dx/I+mFpdfKacxVudscdfv3I+diugBoW5q8inGws69lPxqXhtLe3kJYBJn18G36CE fonON5BzzPN7LCQoLC55ewyBHNtwCbGiXUeInpB0= Received: from epsmges5p2new.samsung.com (unknown [182.195.42.74]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20210112150910epcas5p323697deb48e837ddf7d9450903a56964~ZhJzTLRfE2340623406epcas5p3D; Tue, 12 Jan 2021 15:09:10 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 02.3B.50652.69BBDFF5; Wed, 13 Jan 2021 00:09:10 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20210112140234epcas5p4f97e9cf12e68df9fb55d1270bd14280c~ZgPpVYDKz2419824198epcas5p4d; Tue, 12 Jan 2021 14:02:34 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20210112140234epsmtrp1daf670ec05288d67e2947e2945b2692e~ZgPpUkJpU1138511385epsmtrp1e; Tue, 12 Jan 2021 14:02:34 +0000 (GMT) X-AuditID: b6c32a4a-6b3ff7000000c5dc-e6-5ffdbb9607e2 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id E6.6A.08745.AFBADFF5; Tue, 12 Jan 2021 23:02:34 +0900 (KST) Received: from ubuntu.sa.corp.samsungelectronics.net (unknown [107.108.83.125]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20210112140232epsmtip1dd05c46eb52829da09e5d97069e9d2b6~ZgPnHe6Gi1104111041epsmtip1L; Tue, 12 Jan 2021 14:02:31 +0000 (GMT) From: Shradha Todi To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Cc: bhelgaas@google.com, kishon@ti.com, lorenzo.pieralisi@arm.com, pankaj.dubey@samsung.com, sriram.dash@samsung.com, niyas.ahmed@samsung.com, p.rajanbabu@samsung.com, l.mehra@samsung.com, hari.tv@samsung.com, Shradha Todi Subject: [PATCH v4] PCI: endpoint: Fix NULL pointer dereference for ->get_features() Date: Tue, 12 Jan 2021 19:32:25 +0530 Message-Id: <1610460145-14645-1-git-send-email-shradha.t@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNIsWRmVeSWpSXmKPExsWy7bCmuu603X/jDdo/6Vgsacqw+DhtJZPF hac9bBZ3nt9gtLi8aw6bxdl5x9ks3vx+wW7xZMojVoujG4MtFm39wm7Re7jW4sZ6dgcejzXz 1jB6LNhU6tG3ZRWjx/Eb25k8Pm+SC2CN4rJJSc3JLEst0rdL4MqYc3Ebc8El4Yqb76ewNjB+ Fuhi5OSQEDCR+Lf0A2sXIxeHkMBuRomtTRtYQRJCAp8YJRae04RIfGaUuDVzBxtMx9nPT1gg ErsYJRZ9W8MG4bQwSbxpv88CUsUmoCXR+LWLGcQWEbCWONy+BayIWeAPo0TP/QZGkISwQJjE i1+fwPaxCKhKHPnXBBbnFXCVaPvUxAqxTk7i5rlOZgj7FLvE4W+CELaLxOyu7+wQtrDEq+Nb oGwpiZf9bVB2vsTUC0+BDuIAsisklvfUQYTtJQ5cmQMWZhbQlFi/Sx8iLCsx9dQ6JhCbWYBP ovf3EyaIOK/EjnkwtrLEl797WCBsSYl5xy5DXekhsWrdNmjIxUqs6lrENIFRdhbChgWMjKsY JVMLinPTU4tNC4zyUsv1ihNzi0vz0vWS83M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SVZ T3zePLKcpPU08napwZeyRzo8Iiw8PkYNwcYmHAzKAtc+aWS9tTGvXlsSVb9Yu+lJyf530k8v zlBXfuolP7/tlnC299UJXLYO7dPuHrmm4POBQ/xZ99ut6Rc23OJ6Y2VysdzIVTH0A3/sJbfa wimnmrhlDPhWV6ufZ715N+rlvGspIuryG1sXHnV+3H06rZl7yYMVn5cpOvC6TmfeXyO4R+tT 3/L7s1f+upQRuiyfce/msnV+S7K+Rsy3a9j164K+tpvrVh8Ts0DB6OJ17EbHwrnT/uVI/FzD 8dKEddc3JtM6Gw73+0d2KrEUZyQaajEXFScCAKflqyWnAgAA X-CMS-MailID: 20210112140234epcas5p4f97e9cf12e68df9fb55d1270bd14280c X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20210112140234epcas5p4f97e9cf12e68df9fb55d1270bd14280c 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. When the patch is not applied and EPC features is not implemented in the platform driver, we see the following dump due to kernel NULL pointer dereference. [ 105.135936] Call trace: [ 105.138363] pci_epf_test_bind+0xf4/0x388 [ 105.142354] pci_epf_bind+0x3c/0x80 [ 105.145817] pci_epc_epf_link+0xa8/0xcc [ 105.149632] configfs_symlink+0x1a4/0x48c [ 105.153616] vfs_symlink+0x104/0x184 [ 105.157169] do_symlinkat+0x80/0xd4 [ 105.160636] __arm64_sys_symlinkat+0x1c/0x24 [ 105.164885] el0_svc_common.constprop.3+0xb8/0x170 [ 105.169649] el0_svc_handler+0x70/0x88 [ 105.173377] el0_svc+0x8/0x640 [ 105.176411] Code: d2800581 b9403ab9 f9404ebb 8b394f60 (f9400400) [ 105.182478] ---[ end trace a438e3c5a24f9df0 ]--- Fixes: 2c04c5b8eef79 ("PCI: pci-epf-test: Use pci_epc_get_features() to get EPC features") Reviewed-by: Pankaj Dubey Signed-off-by: Sriram Dash Signed-off-by: Shradha Todi Reviewed-by: Kishon Vijay Abraham I --- 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 e4e51d8..1b30774 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -830,13 +830,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;