Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2645356ybb; Mon, 30 Mar 2020 10:05:49 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuILFiDOwj3mSgddm+/oAR0WJonRh4U/VGSR8GL7vjE0oMrGFjm/L6rb//URtItIqeWgPYB X-Received: by 2002:aca:ed54:: with SMTP id l81mr218228oih.69.1585587949518; Mon, 30 Mar 2020 10:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585587949; cv=none; d=google.com; s=arc-20160816; b=vu3xu2JsbQrZbTznKdUhQG6yxxfN1Xjw6+1s3XhYX3q87bDA+6etoNgy8GCrNAEQQD n6yOC7ySzeqSr0FgtuS+sXQt6z3U+GYU+yWxTYwRqrs5F5LFSyL99d1gfZixGNxR9hOr tZwxd3F07qRKO0lpFaumvqWqHKEN7dU3m5Tn1+q7YvSvb9/NwUTdEFvaM5/nbkUzeVKE bJ6XTIdN1CmIJUK3zRrINII4a8F1B1Kgepi2KrXnkHI6nBhWtBWK8SaAh3JQXTD3jSc2 vyew5ZQFsYVISPXe2BbP0rC94Oncd+VaeMXOJBRhwQ4qWSsIy68tvuZtfh6Q9fU3kcsW icCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=qqStv1Lo1qg4gRg7lDrcQqRCTc9QZc+NG4mrfiQbFjE=; b=eYDYp3jZ2bK3RYJSt3WQf6o1jp1X/fUY1STpt9i6uSNGD2QS6KMXOb7r5KJAzZLi37 DzkDj3NgkAA7wPR9G6klzRECfTUC+Kl/zKjkdep2TCoqR7QePoMLw9E8vlXn5glwzC0R J//1UiJELfmEzmArx5YhxJJdr3fJOe8KkaQeDrJyCb76/uQpHMWuZ1zmTKIq1nLfziWd 0IIdDRGqLYjhx/8TYT0fREqzFZfyQiUVXPTH2qoPo9nkUZZuXLjD+VG88zUs+H/VPD9u 03DwZBOMC1qFvgne8qoEMvLZokOKMrJIZu5QD4Np75H00VpS46ZZkP/8WDVbquh2t7OT URTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=Uh4bVVfa; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s70si6671918oos.6.2020.03.30.10.05.34; Mon, 30 Mar 2020 10:05:49 -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=@broadcom.com header.s=google header.b=Uh4bVVfa; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730034AbgC3REp (ORCPT + 99 others); Mon, 30 Mar 2020 13:04:45 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39231 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728716AbgC3REp (ORCPT ); Mon, 30 Mar 2020 13:04:45 -0400 Received: by mail-wm1-f67.google.com with SMTP id e9so10900466wme.4 for ; Mon, 30 Mar 2020 10:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qqStv1Lo1qg4gRg7lDrcQqRCTc9QZc+NG4mrfiQbFjE=; b=Uh4bVVfaNPgqBDf14A/tNlnFlIMgcAjfpCWcb+Uzrx//iiYZNWzYxkVZtoxnnBGNE7 JUng1z3YWhf3Ee4gCS+2rK3YV4eaABGB5nQVH/R8tVtdVZInAAMkT1GD+hjo00JOuZqN FvOAi1z1lfK4wW+rdBnYnyco/ZYm94ggobg0Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qqStv1Lo1qg4gRg7lDrcQqRCTc9QZc+NG4mrfiQbFjE=; b=pYilXCgcLj9dfbR5RnqCic0Uqjl7N6pdF8LsJuNcJ5DlfAqVhfCa2hAnSnS0cBrxxi lHPn4d/uEDkj/QJfKRL+S2UqeVtFU8si74Fk8gSFEZ7L7LGqVuTdrwCPT+cWPk5UBbZv cK+cd8xgmUsBM8gnpX97msLaRJ0hSn1jMIs8GtNKdER5g2jyX6dmyQOr7HTJ9GeRkVo3 jWdjhjEtVs59AmGeSnewrCRq27NUkICym2/clQjTInENemyZcm9ZjizzF6/8jPt2lPy1 v0Mr/hiJlP1fcBkXmNt/N4udrCp54ALMArVWHzwOX6QbCKSGKlkR9o8lcWvy4f1dFCK7 JDJQ== X-Gm-Message-State: ANhLgQ0krXt70HtMUZ529jS9J9u6HHI6AktTDHBky41be81JnCK3dXDG klCtIDQXG6HL/R7SxPZIPDvt6ISBthX0Kin7 X-Received: by 2002:a05:600c:2202:: with SMTP id z2mr263068wml.64.1585587881418; Mon, 30 Mar 2020 10:04:41 -0700 (PDT) Received: from [10.230.26.36] ([192.19.224.250]) by smtp.gmail.com with ESMTPSA id t126sm192175wmb.27.2020.03.30.10.04.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Mar 2020 10:04:40 -0700 (PDT) Subject: Re: [PATCH 1/3] PCI: iproc: fix out of bound array access To: Bjorn Helgaas Cc: Srinath Mannam , Lorenzo Pieralisi , Florian Fainelli , Ray Jui , Andrew Murray , bcm-kernel-feedback-list@broadcom.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bharat Gooty References: <20200326204807.GA87784@google.com> From: Ray Jui Message-ID: <0fec2db0-fb56-615d-eed4-d702d1bc37fb@broadcom.com> Date: Mon, 30 Mar 2020 10:04:35 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200326204807.GA87784@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/26/2020 1:48 PM, Bjorn Helgaas wrote: > On Thu, Mar 26, 2020 at 01:27:36PM -0700, Ray Jui wrote: >> On 3/26/2020 12:48 PM, Bjorn Helgaas wrote: >>> ... >>> It's outside the scope of this patch, but I'm not really a fan of the >>> pcie->reg_offsets[] scheme this driver uses to deal with these >>> differences. There usually seems to be *something* that keeps the >>> driver from referencing registers that don't exist, but it doesn't >>> seem like the mechanism is very consistent or robust: >>> >>> - IPROC_PCIE_LINK_STATUS is implemented by PAXB but not PAXC. >>> iproc_pcie_check_link() avoids using it if "ep_is_internal", which >>> is set for PAXC and PAXC_V2. Not an obvious connection. >>> >>> - IPROC_PCIE_CLK_CTRL is implemented for PAXB and PAXC_V1, but not >>> PAXC_V2. iproc_pcie_perst_ctrl() avoids using it ep_is_internal", >>> so it *doesn't* use it for PAXC_V1, which does implement it. >>> Maybe a bug, maybe intentional; I can't tell. >>> >>> - IPROC_PCIE_INTX_EN is only implemented by PAXB (not PAXC), but >>> AFAICT, we always call iproc_pcie_enable() and rely on >>> iproc_pcie_write_reg() silently drop the write to it on PAXC. >>> >>> - IPROC_PCIE_OARR0 is implemented by PAXB and PAXB_V2 and used by >>> iproc_pcie_map_ranges(), which is called if "need_ob_cfg", which >>> is set if there's a "brcm,pcie-ob" DT property. No clear >>> connection to PAXB. >>> >>> I think it would be more readable if we used a single variant >>> identifier consistently, e.g., the "pcie->type" already used in >>> iproc_pcie_msi_steer(), or maybe a set of variant-specific function >>> pointers as pcie-qcom.c does. >> >> It is not possible to use a single variant identifier consistently, >> i.e., 'pcie->type'. Many of these features are controller revision >> specific, and certain revisions of the controllers may all have a >> certain feature, while other revisions of the controllers do not. In >> addition, there are overlap in features across different controllers. >> >> IMO, it makes sense to have feature specific flags or booleans, and have >> those features enabled or disabled based on 'pcie->type', which is what >> the current driver does, but like you pointed out, what the driver >> failed is to do this consistently. > > There are several drivers that have the same problem of dealing with > different revisions of hardware. It would be nice to do it in a > consistent style, whatever that is. > Sure, agree with you that it should be handled in a consistent way within this driver, and the current driver is not handling this consistently. >> The IPROC_PCIE_INTX_EN example you pointed out is a good example. I >> agree with you that we shouldn't rely on iproc_pcie_write_reg to >> silently drop the operation for PAXC. We should add code to make it >> explictly obvious that legacy interrupt is not supported in all PAXC >> controllers. >> >> pcie->pcie->reg_offsets[] scheme was not intended to be used to silently >> drop register access that are activated based on features. It's a >> mistake that should be fixed if some code in the driver is done that >> way, as you pointed out. > > That's actually why I dug into this a bit -- the > iproc_pcie_reg_is_invalid() case is really a design-time error, so it > seemed like there should be a WARN() there instead of silently > returning 0 or ignoring a write. > I think 'iproc_pcie_reg_is_invalid' is a fall back protection. We should aim to prevent this from happening in the first place using whatever means we determined appropriate, and do that consistently. In addition, I also agree with you that there should be a WARN instead of silently returning zero (for reads) and dropping the writes. We'll be looking into improving this as you suggested when we have a chance. In the mean time, I think both of us agree this is out of the scope of the issue that this patch is trying to fix, which is actually a pretty critical issue that can cause potential corruption of memory and the fix should be picked up ASAP (and for older LTS kernels too). Thanks, Ray > Bjorn >