Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3027740pxj; Mon, 17 May 2021 15:57:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzblc93o8atdEpftcSqN/VnTg1jp+SSIm5Z+TdaTe2w/O7mNuvoc399+crnZs9xWZ0kOIrk X-Received: by 2002:a92:db0e:: with SMTP id b14mr1631815iln.171.1621292253076; Mon, 17 May 2021 15:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621292253; cv=none; d=google.com; s=arc-20160816; b=SKGICWjFpfK2CJx2wtzP0lpFI+6BSDATeiPjbGd/mbj8EGJMXGaLhT3p/ctiCHkeaf DGxT8mhpK7qseB8sqwmqrm7giVcR14rXQ4pevEW9OX6qkIcviELb8Y7KJ6QQ63Rp5j34 OeRdolf6Foy2cr75RHh7yogqDLWeHhEk/OlK4EaG4aWT+0khjVDLotV9kuD2sigv73QF ujp/BJeXzh1R0aOVqNM3zN/7Af/CGOfYdPVppyeYtxMcThWUikNE0vWjDNF16dl0lA8Z Q91XGyq2gU8lEyHYy5ghhvsjjctQrkHR1aHE5uHuduZ3+6LnldY6YtOrU16RNyyP0RHR kp3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hfnR7STK7gJwDZQtCSQjl7VyQqozqETa3zGZ1KIiAGM=; b=wqQHiqJsKq07FmgZ0BtA/laZ3K5b6//eiI3jy9yHl7fPK2pO/KorHHQjLl1VlZvdh+ MEe2y0PKbA9CetEbNd2+XLlMJlqVYi70ErJklt/6nqR12i4oJWSF3gO3aBxHg+A9flTQ 38j8oVgjLzEOL+vqlYjFO6UzvY83ZYzhkFqHkpEks5LY7d/bDKGp8nVqHYsqFwG4Obk7 Bm6Zz18vnj99vluTeY1Ku7/1s0vZHe7dThS1Iv5Q+lH7LSv/5QEi9heQuALsU9kQXESR aLO5UeXXQknJ97rKKS7xglJEe+nfEyrWXXSQC721UuR3/NpyiATw3FthBhlSM5fGZVDD OqVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tmWt3Wg8; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a14si23140982ilm.103.2021.05.17.15.57.19; Mon, 17 May 2021 15:57:33 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=tmWt3Wg8; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235086AbhEQOSz (ORCPT + 99 others); Mon, 17 May 2021 10:18:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:46384 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238862AbhEQOQo (ORCPT ); Mon, 17 May 2021 10:16:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E2AE8613E6; Mon, 17 May 2021 14:09:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260581; bh=7/bwLLDK6Jz41tQ9GQRewnBn8v6OGo6N3hv9utidy64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tmWt3Wg8BpUr+yheJtAbWLN9w65lpwoJoxiqezCWhEwCLlq56vZ9UDN6z9nyuyPne eJc/SGAvshnObfVXfV6djEDPnxZyQvdlIIgbNPJXcBU+5mmufG9yjCRfi9lFGSUfqs hR9i9GRa6qZjcBSC28AMyedriKdmuXuW2jV4ZcmU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sriram Dash , Shradha Todi , Lorenzo Pieralisi , Pankaj Dubey , Kishon Vijay Abraham I , Sasha Levin Subject: [PATCH 5.12 139/363] PCI: endpoint: Fix NULL pointer dereference for ->get_features() Date: Mon, 17 May 2021 16:00:05 +0200 Message-Id: <20210517140307.324800269@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shradha Todi [ Upstream commit 6613bc2301ba291a1c5a90e1dc24cf3edf223c03 ] get_features ops of pci_epc_ops may return NULL, causing NULL pointer dereference in pci_epf_test_alloc_space 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. Call trace: pci_epf_test_bind+0xf4/0x388 pci_epf_bind+0x3c/0x80 pci_epc_epf_link+0xa8/0xcc configfs_symlink+0x1a4/0x48c vfs_symlink+0x104/0x184 do_symlinkat+0x80/0xd4 __arm64_sys_symlinkat+0x1c/0x24 el0_svc_common.constprop.3+0xb8/0x170 el0_svc_handler+0x70/0x88 el0_svc+0x8/0x640 Code: d2800581 b9403ab9 f9404ebb 8b394f60 (f9400400) ---[ end trace a438e3c5a24f9df0 ]--- Link: https://lore.kernel.org/r/20210324101609.79278-1-shradha.t@samsung.com Fixes: 2c04c5b8eef79 ("PCI: pci-epf-test: Use pci_epc_get_features() to get EPC features") Signed-off-by: Sriram Dash Signed-off-by: Shradha Todi Signed-off-by: Lorenzo Pieralisi Reviewed-by: Pankaj Dubey Reviewed-by: Kishon Vijay Abraham I Signed-off-by: Sasha Levin --- drivers/pci/endpoint/functions/pci-epf-test.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index c0ac4e9cbe72..bc35b3566be6 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -833,15 +833,18 @@ 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); - if (test_reg_bar < 0) - return -EINVAL; - 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); + if (test_reg_bar < 0) + return -EINVAL; + pci_epf_configure_bar(epf, epc_features); + epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features; -- 2.30.2