Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp6070319pxu; Wed, 23 Dec 2020 12:36:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4jh5x+Bq9SH57BxTwGhsGNam7DtThZ6mwYlt0eToFWI7QdpNzboxouJv2hR3H1Pdtm4mf X-Received: by 2002:a17:907:96a4:: with SMTP id hd36mr24670063ejc.393.1608755764716; Wed, 23 Dec 2020 12:36:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608755764; cv=none; d=google.com; s=arc-20160816; b=L+Ai4GFgVO7iDjkyWU8QUF9mtYyLu8620Y6BqRyBhjvwz+4qVVLnbc0BUIT37NAuZW 5szPzBcZ7pDE+yy12EQWFiAnPf/1NV8IF+QW7mfCp0TnD7crD7zY7eVSteIiBK4uXR1L N6BLPtzaceq5uX8fdwREiitDbv79BMxF4STm7CsrQ+NsR9VIdnWd6eqiMH/lSaHGwPAk Im8Tp/8INkoiyeWIIdW3yrVyLwNWbWmceuzz4swWlwwWEpLU2u8FYmC7a58U8mY19BFh vs9U07LYNlL2yx/75eqFSEdSSEMbxa1xd/WHjk6cSYeyGoHh28438KVSMAXkVP1yuwpi SI1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=bKef0x0Ion4/pxS/ZntEIVWnWtwxvrvZ62zULSRDSOE=; b=YCjoaFKNZIxXTuHLkfWcMlFvDRASUJVeOy4Gv3LJdFoZIoyeqmEPJWwJMsKQFztJBq S1eA5ilS8X3kvas2EerizbhrdMvBjlicuFRamXl3Z/t1T8gRlmIr+5xLr+1jIB1w3jIa lp+qgV65IxLUnceHDMZ8kTrvcKARfJXQJjOFeh+BxqIH80aBsVcKS8xqsFG8l6n6PORa /pwsLXZJuhL0TYEdAPeAKE57+byVqv8EAjC4vFbtbnq8cshFiBNTmvdN+P0mXt+WfRf2 fBWYtulwH+Sbf2sYrrC+q18GQ1FYzBXQRf2Hx5jiXQM4n/u9xIHpraFxsaZtMX5hXUIr G57g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZVEW79RS; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m11si14025156edr.583.2020.12.23.12.35.42; Wed, 23 Dec 2020 12:36:04 -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=@kernel.org header.s=k20201202 header.b=ZVEW79RS; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728854AbgLWUeq (ORCPT + 99 others); Wed, 23 Dec 2020 15:34:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:40500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbgLWUeq (ORCPT ); Wed, 23 Dec 2020 15:34:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E5B93224B0; Wed, 23 Dec 2020 20:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608755645; bh=KjJsg8AZUftQqGocU/eSTcEZqpjvbqUtQRkYl1ogUiw=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=ZVEW79RSwD4+/ME2eRqrtJc8rv/gDoR9dz7klfUU94kloC3EqChVrBKp/VoAmUtfx hKjIqvgNZwoMKFg3XpHSwO6pPJgbGk8Sdoo+aP6MWkFi31DSxTESDGDa22WphkajVx x8xIYsOkbd2e3o/TfC0wJSMoZEZVZgPVK1AlcA7DSiVx24/rnxid+2w5KcaXAATCet 6seWXT2wUDyCGBj7XrHVennonWRZaAdg5L2AjhkniX45eEPES/zBhMGXDkhRy09PrT CyNr2hOLJKWYzz/r7FrUyu13aF9/K7w1bElRK9ymLxi+BSeIvvB72XaBEE0bWkZiTr cobx2kzEau82A== Date: Wed, 23 Dec 2020 14:34:03 -0600 From: Bjorn Helgaas To: Shradha Todi Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kishon@ti.com, lorenzo.pieralisi@arm.com, bhelgaas@google.com, pankaj.dubey@samsung.com, Sriram Dash Subject: Re: [PATCH v2] PCI: endpoint: Fix NULL pointer dereference for ->get_features() Message-ID: <20201223203403.GA320059@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1608306316-32096-1-git-send-email-shradha.t@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 18, 2020 at 09:15:16PM +0530, Shradha Todi wrote: > 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. Can you add a Fixes: tag to identify where this broke to help people decide where to backport the fix? > 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 >