Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1979888rbb; Tue, 27 Feb 2024 07:10:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU+GkIS1bwyxIRsu9YEmmA/4QcfTldap9LyLvpjqV9M6xdPZw3mAUqr7UhZpLtGTyWjZsZLkwxQ6Q38oRW1wavUFxRUxdyqa2FrAkUrlg== X-Google-Smtp-Source: AGHT+IFkaQ6Cqp/+20V/dE5N+4f71BjpoY+p7wnt2kQXoL7GxzwpjyeLcl6XmJialceamdbFbUe7 X-Received: by 2002:a05:6402:6da:b0:566:aa2:8433 with SMTP id n26-20020a05640206da00b005660aa28433mr3413210edy.36.1709046646071; Tue, 27 Feb 2024 07:10:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709046646; cv=pass; d=google.com; s=arc-20160816; b=nhggkVAPHFJduCmazHBtQ+zzm/yGgjiD/pPYObl6++Ac9bBCclKzkxJBVM5jCOzGyd J+0Vi0MYRvTu1bL3hMuBy9/Ubd28Iak9iLv2NIVRAIi4NghsAcUwSL2HfssUyJWFQJam 2QBik61K+41RgAV0/Mx+QXHGJ8FkiZ02ud1e15c6CEx5EIxmfGbYWd65PEUhkpY8h7JF wZKj0MofvQvL1GwryEYviU7lqurDfL0CZEEBITJ2L8QUiGtsNq3Kv+BMGT0b1EDN7NPM CMEucMZCvCMsVtndzVgjrW2x02j5fAd83Q4yX+MEZfDT40Ps9y+soGmtVVvYUSf5iSOp wn2Q== 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 :message-id:subject:cc:to:from:date:dkim-signature; bh=MVENUdXS50L+zC+Ep5z/nxeZqvbwlrXi2Z04dlfWzjo=; fh=AI8zWoUfE9GoE5Qv1gU5GUoX9LPQ+lBCHEIsvQsxQ5E=; b=yPN9RdkHU+uFKZ3AT921ljonAQxutmVBhvXlk/pMln3+k/eu7mSWj0LCA5T1PcDbdd 4ZGCP1tdxut2FeRevpUN4eenRKnvc3FESGrh7l5JMLLGXC/gMUG0yl9JVHHoEHAfgGS2 xn0R6hXfckkrTPH1Y1EJiY3joAHPzBoA4xa6peqqNex3NN3/eXpZynyojpcUYmQ/ex0v qWeX5v9bfMSOXAEZdfhVjB09pk3pnvhvEKDPmFsG7B/hcOkUnbOJmXg28dUJs0r3Ervv oOA94/oTt/vaOgNnmh/Ug1Umsg6YM3iaPLhP+mRQK7GiaUR0TelgcXV+gnyAam555Lo2 ujwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=M0FoZU6z; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-83474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83474-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z8-20020a056402274800b00566411c5d4esi491650edd.528.2024.02.27.07.10.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 07:10:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=M0FoZU6z; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-83474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83474-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 am.mirrors.kernel.org (Postfix) with ESMTPS id CC7031F21D11 for ; Tue, 27 Feb 2024 15:10:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A72014A0A0; Tue, 27 Feb 2024 15:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M0FoZU6z" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79FA21474AB for ; Tue, 27 Feb 2024 15:07:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709046466; cv=none; b=bDq1sN7QqeJiEpayiAogTIu1GP24H68gq+0PY0QzlwWIVA3txR5wKMEwl3zQ5nMpXhoDiCz9ZEmLhWbLN7sezZFSidc/fstOhuNBFz3ExhRkg2Kf5e+D9T7vZvROXH2uW6vQ7z5K7ZTZnc7JFgGvG2UQgNDLgHY6MMxwDmAaERk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709046466; c=relaxed/simple; bh=dEWy7wLEKGq1ouT0iXQhr1lr4MchUw+lzS97J7XS4zI=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=Cz7P7BkBkiGKPgm42iKTK3Wq6MLbbqnj+TwNIvsrIhxKhFjO/an2qL421eXMB9OYQNmJJBb5ePNGp+Pn4WfWI2N/I8fQJMm2cxy9Inz+6jFllF6/gPCUBBexCNqY0l0ZCU9K5k2niBcOXYOFzt5oweK89xzn9CqdmsL6bhFW55A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M0FoZU6z; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF7FAC433C7; Tue, 27 Feb 2024 15:07:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709046466; bh=dEWy7wLEKGq1ouT0iXQhr1lr4MchUw+lzS97J7XS4zI=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=M0FoZU6ziI1hCULE1HJ5T1LCchSD7qQIbU/onUvipS9xFKgfjRH2pnikIdG2R78wC dg4YAHH7a3odiKHJi5nc13YguQHtD7If+4P40yq6rJDcZfTHoTGefHOQdpOJB6tHAk EzFLSVvLZB/rpQArwL2ITIi+ylTNX69NnCH4Tz2yndbqcTq91OMlgpsUUb1HU1Rz6a NRmGK2UoDeRIkYu+AmPwW8sO0URXF/6cJzQoUb7cBnHXjWg0CLeszvemvR7wE646qS K7+Y/XFf8RAA7vv8TeHxcxY3UgoS7o1AZx2qSx73jbAvn0AZ82BmU4OKQ60VwDrYaI guP6FE+XJ3ypw== Date: Tue, 27 Feb 2024 09:07:44 -0600 From: Bjorn Helgaas To: Greg Kroah-Hartman Cc: Carlos =?utf-8?B?TMOzcGV6?= , cve@kernel.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , Jonas Gorski , Andy Shevchenko , Mika Westerberg Subject: Re: CVE-2023-52466: PCI: Avoid potential out-of-bounds read in pci_dev_for_each_resource() Message-ID: <20240227150744.GA235367@bhelgaas> 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: <2024022709-magazine-handshake-50da@gregkh> [+cc Mika, author of 09cc90063240] On Tue, Feb 27, 2024 at 02:26:26PM +0100, Greg Kroah-Hartman wrote: > On Tue, Feb 27, 2024 at 02:18:51PM +0100, Carlos López wrote: > > On 25/2/24 9:16, Greg Kroah-Hartman wrote: > > > There is no actual issue right now because we have another check > > > afterwards and the out-of-bounds read is not being performed. In > > > any case it's better code with this fixed, hence the proposed > > > change. > > > > Given that there is no actual security issue this looks more like a > > hardening, and thus not deserving of a CVE, no? > > This was a tricky one, I think it's needed as we do not know how people > are really using these macros, right? If the PCI maintainer agrees (on > the cc:), I'll be glad to revoke it, it's their call. 09cc90063240 ("PCI: Introduce pci_dev_for_each_resource()") added pci_dev_for_each_resource(), which expands to: for (...; res = (&(dev)->resource[(bar)]), bar < PCI_NUM_RESOURCES; ...) We compute "res" before the bounds-check of "bar", so the pointer may be out-of-bounds, but the body of the pci_dev_for_each_resource() loop is never executed with that out-of-bounds value. So I don't think this is a security issue, no matter how pci_dev_for_each_resource() is used, unless the mere presence of an invalid address in a register is an issue. The same address computation is used for "pci_resource_start(dev, bar)", which is used in hundreds of places where drivers supply the BAR index, and the index is not checked. We could consider adding a bounds check in pci_resource_n() to turn a potential out-of-bounds reference into a NULL pointer dereference, e.g., #define pci_resource_n(dev, bar) (bar < PCI_NUM_RESOURCES ? &(dev)->resource[(bar)] : NULL) But of course, there's nothing stopping drivers from computing "&dev->resource[junk]" themselves. Bjorn