Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp516239lqh; Sat, 4 May 2024 10:02:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXxI2sJMfMPm4qtqcs4K1hLE+qaysn3rOrvorMbyR3M8zoIEcTBqgVlQAg1pSP9g+GMKlcbYuKVzoSlqHRCXtCV4TwuLHZx35LP4SM83A== X-Google-Smtp-Source: AGHT+IGmqpjh1/e79HLVLnQ5tRafUNmlWSmz3qbtx2HgHHnLL+EUNJU3wfUICY6Qlm33bN0s36e/ X-Received: by 2002:a17:90a:5910:b0:2a7:455d:82db with SMTP id k16-20020a17090a591000b002a7455d82dbmr5558412pji.36.1714842120235; Sat, 04 May 2024 10:02:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714842120; cv=pass; d=google.com; s=arc-20160816; b=fl6PBMIXbfcrcVhGl6M8RRdh0EjAeOAyRz4OHl7h0Z+Xx0VBBDJV8LnD9pHiwUQUWg 7KnDwq74eBrE6wD2DQlburWSFBYmxCb779AXDlegM/8OLBEflQMKge0QBYg45N4tSM4w Zaq8KplYFqh3m/cmmLw0uUeMS115xshw+t2VGvoz9Y3216Tawjf0ZLa+rWYOqqPO+O2H tgeonooYyiHRkSisf6vH5K1B27bW1r331RjbM1+bKONoxAn9maN07ZGEhXZsBeGUQx+H BVJf4hPGZG4sA/fDfy96U78isi91FxDk+O6dk0hQL3LsW5pypGvRmsvXIkFypdH41ECW dUZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ANbQzLbC04OT96qrkLQKxGMSo5LbgtdU/enMtsBUeUQ=; fh=1H04ymjfKXylUujg4XnWlHDXVgKCrC/zeGIWsaUaTwQ=; b=UkMCZM+qcywhnR7j4euA0XAknS2MdIbveUsRQcJpV2BGLMK05/a1O9UKfOBYZFN6vA Ph5tx0gU/87k6Qn40ZbsmPPJ7PLsPOrsZHB5n7ubSB/x22SFvv5kdbZ5qOimlnS/dC7n 5ispikYUmsuyqiAmMKOrPpeCdcG22NQ1srVxhUTkZDm89/88tQEjA2fpJsG/Mm2DEvHI k3bbCZ8e5GhQk1wfd/LN563KGPLpS4ZmHUd+5/qXjNJ1wZ8iZeP+/RmRRzFmgHxPIkdv 5N4fPy0QPacLLN8n8cm4hs4LMp1CUabT5Ajjl1JKQ/wJKoVs92CPaz+V7ezPEB8kPVV+ gNxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ed/EGp+I"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-168762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168762-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f6-20020a17090a654600b002a52c77528fsi4095232pjs.157.2024.05.04.10.01.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 10:02:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ed/EGp+I"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-168762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168762-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 03905B21626 for ; Sat, 4 May 2024 17:01:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 933465A7AB; Sat, 4 May 2024 17:01:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Ed/EGp+I" Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 469703D971 for ; Sat, 4 May 2024 17:01:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714842108; cv=none; b=TsHtlGmcOEGdrJaC7y6Rfn4iEwpNkxLM8yl5Ny6q96Pp8h0CrqhhB6yUTieSj+wBjf7xEwSa5n9JS34UOo4BNBzmIJUG9g1rd2JNoHOaPbDJXuMS3zRZtrxMtdu84qSGf7lSNhO8osPA9Q5ZVcukcAs84qjFG/VqaWyDzSIk8Qg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714842108; c=relaxed/simple; bh=Ui289m/aD+ifRYLXt9sDXS8DUyCLcvxnyweT3Q+LgHQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=swxJSXYhj5aWT74w2HbWl+dmuqmGbKoXV5/EGENeRvaFHry40+cOYRti5ViwLaJwwKnYLydOtzL2vZ8W/NEY3KLh40MTDC/ZYGZk/s++SkvZI3sJenOYx6Y2qcD+Gd0NdzdG+PHv9S/UYsNUdX9mhbWmqkW2mbEWhskv+Ba9pFk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Ed/EGp+I; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6f45f1179c3so317284b3a.3 for ; Sat, 04 May 2024 10:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714842106; x=1715446906; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=ANbQzLbC04OT96qrkLQKxGMSo5LbgtdU/enMtsBUeUQ=; b=Ed/EGp+IeDo/igMDy7R6cZHQVwMcUksysOSOMFs8d491hHusOTh4aNR5JjSdETXXYj RhQY1RMxj2X3pveQ6c7LqD9mwRye2Cer3jWwFCKX8XhfcAzEA04c5HBOcnalECXbyneB q6Tpye+gy6NbcZMpGnF/9TxgUOh50G3x1CSbaFoKRWOBPhe038lWYq4VkyKfXPFs1GuC mdZNQJU1QKAJDFiCVwV2jGYxAPGilSx7mxJIM4uEgqsXyut9aLVTf1f/2gDwl8lt+/BB lBY6cMEGjbEWR3WN88sLgBEBlb8MYMDcam0oegcob/+/BLDlrNvOA3yvsi6ki0CwqRqc LbJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714842106; x=1715446906; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ANbQzLbC04OT96qrkLQKxGMSo5LbgtdU/enMtsBUeUQ=; b=KDI2U1wZQfDmJB2MznshG1NDka4CJnvphqDAQGQ2JM399W+6zWKlfJzByu3EjbNF+F 5OPNHUIBuZ36UEBXorzfqtCYHwBGpHjqsB5x5AKX89bwP1aBCO752sQWRVBdz93gPgXa /wDpQ+qfKSc/YQLnDWcRT8UAtICRgSvADARbzqTAP4VDDoupgeBhyy7471A8mjtZnCF4 xMVBlmdLNIbe8AhfTNd+iaxB3OWcH6wWPQwTYbIQi3lbYQHjhHEyAFRAT97mum3onyuq GFUUgJ71AzAqL5L0z0a1SdknDoOLcyrEkID/elDxrlkNVA50bug73SeW/zhA/fP97Uem K1lg== X-Forwarded-Encrypted: i=1; AJvYcCUoTAsvb34TxOzH8lwy4wNwjjU/474AIB3EcSvWgkZ/Nm1noxIi22fHGYYf0a0x3obn0alArbKAL7ZpcHFRbYgbP91C1xe1h+LTAL/P X-Gm-Message-State: AOJu0YzX9FaT9m2k7ZaFuP/IinGXbzAsp4CzngzWnUS6Sfy+7xkSIXuv M+RUqAtiVmNvUNmcBIHxq5GNUDhEUqLo4fgt74Tnm2xjtz3ievlj3vWe4xR2aQ== X-Received: by 2002:a05:6a00:92a5:b0:6e6:946b:a983 with SMTP id jw37-20020a056a0092a500b006e6946ba983mr6518136pfb.10.1714842106223; Sat, 04 May 2024 10:01:46 -0700 (PDT) Received: from thinkpad ([220.158.156.237]) by smtp.gmail.com with ESMTPSA id ls30-20020a056a00741e00b006f4123491d2sm4954233pfb.108.2024.05.04.10.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 10:01:45 -0700 (PDT) Date: Sat, 4 May 2024 22:31:39 +0530 From: Manivannan Sadhasivam To: Aleksandr Mishin Cc: Rob Herring , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Bjorn Helgaas , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Serge Semin , Niklas Cassel , Yoshihiro Shimoda , Damien Le Moal , Siddharth Vadapalli , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org, Bjorn Helgaas Subject: Re: [PATCH v3] PCI: dwc: keystone: Fix NULL pointer dereference in case of DT error in ks_pcie_setup_rc_app_regs() Message-ID: <20240504170139.GB4315@thinkpad> References: <20240329051947.28900-1-amishin@t-argos.ru> <20240503125726.46116-1-amishin@t-argos.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240503125726.46116-1-amishin@t-argos.ru> On Fri, May 03, 2024 at 03:57:26PM +0300, Aleksandr Mishin wrote: > If IORESOURCE_MEM is not provided in Device Tree due to any error, > resource_list_first_type() will return NULL and > pci_parse_request_of_pci_ranges() will just emit a warning. > This will cause a NULL pointer dereference. > Fix this bug by adding NULL return check. > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Fixes: 0f71c60ffd26 ("PCI: dwc: Remove storing of PCI resources") > Suggested-by: Bjorn Helgaas > Suggested-by: Manivannan Sadhasivam > Signed-off-by: Aleksandr Mishin One nitpick below. With that addressed, Reviewed-by: Manivannan Sadhasivam > --- > v1->v2: Add return code processing as suggested by Bjorn > v2->v3: Return -ENODEV instead of -EINVAL as suggested by Manivannan > > drivers/pci/controller/dwc/pci-keystone.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c > index 844de4418724..381f7b2b74ca 100644 > --- a/drivers/pci/controller/dwc/pci-keystone.c > +++ b/drivers/pci/controller/dwc/pci-keystone.c > @@ -382,17 +382,22 @@ static void ks_pcie_clear_dbi_mode(struct keystone_pcie *ks_pcie) > } while (val & DBI_CS2); > } > > -static void ks_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie) > +static int ks_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie) > { > u32 val; > u32 num_viewport = ks_pcie->num_viewport; > struct dw_pcie *pci = ks_pcie->pci; > struct dw_pcie_rp *pp = &pci->pp; > - u64 start, end; > + struct resource_entry *ft; s/ft/entry - Mani > struct resource *mem; > + u64 start, end; > int i; > > - mem = resource_list_first_type(&pp->bridge->windows, IORESOURCE_MEM)->res; > + ft = resource_list_first_type(&pp->bridge->windows, IORESOURCE_MEM); > + if (!ft) > + return -ENODEV; > + > + mem = ft->res; > start = mem->start; > end = mem->end; > > @@ -403,7 +408,7 @@ static void ks_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie) > ks_pcie_clear_dbi_mode(ks_pcie); > > if (ks_pcie->is_am6) > - return; > + return 0; > > val = ilog2(OB_WIN_SIZE); > ks_pcie_app_writel(ks_pcie, OB_SIZE, val); > @@ -420,6 +425,8 @@ static void ks_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie) > val = ks_pcie_app_readl(ks_pcie, CMD_STATUS); > val |= OB_XLAT_EN_VAL; > ks_pcie_app_writel(ks_pcie, CMD_STATUS, val); > + > + return 0; > } > > static void __iomem *ks_pcie_other_map_bus(struct pci_bus *bus, > @@ -814,7 +821,10 @@ static int __init ks_pcie_host_init(struct dw_pcie_rp *pp) > return ret; > > ks_pcie_stop_link(pci); > - ks_pcie_setup_rc_app_regs(ks_pcie); > + ret = ks_pcie_setup_rc_app_regs(ks_pcie); > + if (ret) > + return ret; > + > writew(PCI_IO_RANGE_TYPE_32 | (PCI_IO_RANGE_TYPE_32 << 8), > pci->dbi_base + PCI_IO_BASE); > > -- > 2.30.2 > > -- மணிவண்ணன் சதாசிவம்