From patchwork Thu Jul 29 18:42:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1511372 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=U1WnQiq9; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GbKCQ5wJlz9sW8 for ; Fri, 30 Jul 2021 04:42:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230376AbhG2Smp (ORCPT ); Thu, 29 Jul 2021 14:42:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:47248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbhG2Smo (ORCPT ); Thu, 29 Jul 2021 14:42:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2FE2D60F5C; Thu, 29 Jul 2021 18:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627584161; bh=mNHkWhp2gqaE2pFLRywdLRuMHd0sK+JVy4ynGKzSyeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U1WnQiq9AO8fA67p7v75JsVJH3Qm1q6C9/97s5CmDlePo0GMk+lTqir162qjn+6Zv E/NvfbaJvYEgs1kOQsP69QHRJml+JViMh4EoxfBW2CIY4tRo1zg6oHa2KABBhMmxQL /XU+JAVkCeUqqQveTZdpu4b4256asWoXbjCi0M5qsrRGBjNetYJLL52iQYFiczQgNY wmQ25/QfV8nRjC19+39HO9nqmhA/K2Otq+1vw2v0xSSNFo/Nys1bzaev/VRlgSqh7A pwF6TnwKVUIDwaHEdYI9vWCE8vAGjfLzYhfcA1ozeI1vA1NuIJrMvHk0ILjt43Hwcg 8iKCeX785duMQ== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v2 1/6] PCI/VPD: Correct diagnostic for VPD read failure Date: Thu, 29 Jul 2021 13:42:29 -0500 Message-Id: <20210729184234.976924-2-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210729184234.976924-1-helgaas@kernel.org> References: <20210729184234.976924-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Previously, when a VPD read failed, we warned about an "invalid large VPD tag". Warn about the VPD read failure instead. Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 26bf7c877de5..7bfb8fc4251b 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -92,8 +92,8 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) (tag == PCI_VPD_LTIN_RW_DATA)) { if (pci_read_vpd(dev, off+1, 2, &header[1]) != 2) { - pci_warn(dev, "invalid large VPD tag %02x size at offset %zu", - tag, off + 1); + pci_warn(dev, "failed VPD read at offset %zu", + off + 1); return 0; } off += PCI_VPD_LRDT_TAG_SIZE + From patchwork Thu Jul 29 18:42:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1511373 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=EAf1ovqo; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GbKCS1YXTz9sSs for ; Fri, 30 Jul 2021 04:42:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230443AbhG2Smq (ORCPT ); Thu, 29 Jul 2021 14:42:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:47312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbhG2Smq (ORCPT ); Thu, 29 Jul 2021 14:42:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C69F360249; Thu, 29 Jul 2021 18:42:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627584163; bh=auhxKJrYSDOfxalsGZS8NQWEtQT9lrJGrSdzj+8Q7+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EAf1ovqouRw1XQ5sAMSPMnGgNamFaKjr/Zq+1xkXcLhAEYyIWU/r88SO9sCLXrrJr L2gbuHUtLCikDdE0NZ+nm6vd/o4XIwYeo+vufaWfCwKaqOcWgTsi0wA6yKo+1G6Gy3 ub4fEfw+v7/316caGvihrEuDuz1QHvHIWPMss9dXI+KRCVIMQy9L+v2b3moxzDq7Af pPurE3KE8Si94VNnwO6kObBsxINmgojaVfv2e4FdZWhjr4mS/usua4wheOUAG7nZXr hWnSH4tobHVU2U2TZc64pqCtUIIH3G/IrR9Hm/ka1Sp1NIJPskfU+gKKg/Xj/qG8XJ TAfAqHxy1MFdA== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v2 2/6] PCI/VPD: Check Resource Item Names against those valid for type Date: Thu, 29 Jul 2021 13:42:30 -0500 Message-Id: <20210729184234.976924-3-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210729184234.976924-1-helgaas@kernel.org> References: <20210729184234.976924-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Previously, we checked for PCI_VPD_STIN_END, PCI_VPD_LTIN_ID_STRING, etc., outside the Large and Small Resource cases, so we checked Large Resource Item Names against a Small Resource name and vice versa. Move these tests into the Large and Small Resource cases, so we only check PCI_VPD_STIN_END for Small Resources and PCI_VPD_LTIN_* for Large Resources. Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 7bfb8fc4251b..9b54dd95e42c 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -98,24 +98,18 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) } off += PCI_VPD_LRDT_TAG_SIZE + pci_vpd_lrdt_size(header); + } else { + pci_warn(dev, "invalid large VPD tag %02x at offset %zu", + tag, off); + return 0; } } else { /* Short Resource Data Type Tag */ off += PCI_VPD_SRDT_TAG_SIZE + pci_vpd_srdt_size(header); tag = pci_vpd_srdt_tag(header); - } - - if (tag == PCI_VPD_STIN_END) /* End tag descriptor */ - return off; - - if ((tag != PCI_VPD_LTIN_ID_STRING) && - (tag != PCI_VPD_LTIN_RO_DATA) && - (tag != PCI_VPD_LTIN_RW_DATA)) { - pci_warn(dev, "invalid %s VPD tag %02x at offset %zu", - (header[0] & PCI_VPD_LRDT) ? "large" : "short", - tag, off); - return 0; + if (tag == PCI_VPD_STIN_END) /* End tag descriptor */ + return off; } } return 0; From patchwork Thu Jul 29 18:42:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1511374 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Grbt/G5E; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GbKCT6JH2z9sW8 for ; Fri, 30 Jul 2021 04:42:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbhG2Sms (ORCPT ); Thu, 29 Jul 2021 14:42:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:47366 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbhG2Sms (ORCPT ); Thu, 29 Jul 2021 14:42:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6EC0960FD7; Thu, 29 Jul 2021 18:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627584164; bh=Fw6pnMuUh/6p/2qaZfimakF16+9evrrMwuSMuxTp7mY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Grbt/G5EJhyyi+sUpI2M72A2x+g/fsT9QGsjb5zUomG9eQQVxtDqu4m349ZzkKJXp mDwTZH+A0PKAuYKVLXx6aKxexX6Q3hxRI9gZxIdzU5UB7m9tod8ETxGjargEV45UHP XT2eOCH43ayTn+Zuaimg5bGbR1HEy3VcM4q7/kfAecxHWEiQ7xNsBsXDWyFgo5K2Tv bKbGBqefaCYa4PmdRM+iQekIYOjoJSCrWqD4ssJ/FWBwdeGchOYzmM4Mizb42+rdeF JIU2m+hcSU4kub3shrgNdDw+Iw9X/0VZJa2w7qrlNmEghFUXP6HS8L5tceu1KguNyF mimPFoDaQ7VlQ== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v2 3/6] PCI/VPD: Treat initial 0xff as missing EEPROM Date: Thu, 29 Jul 2021 13:42:31 -0500 Message-Id: <20210729184234.976924-4-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210729184234.976924-1-helgaas@kernel.org> References: <20210729184234.976924-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Heiner Kallweit Previously we assumed that the first tag being 0x00 meant an EEPROM was missing. The first tag being 0xff means the same thing; check for that also. [bhelgaas: rework error mesage] Signed-off-by: Heiner Kallweit Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 9b54dd95e42c..66703de2cf2b 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -78,10 +78,8 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) while (off < old_size && pci_read_vpd(dev, off, 1, header) == 1) { unsigned char tag; - if (!header[0] && !off) { - pci_info(dev, "Invalid VPD tag 00, assume missing optional VPD EPROM\n"); - return 0; - } + if (off == 0 && (header[0] == 0x00 || header[0] == 0xff)) + goto error; if (header[0] & PCI_VPD_LRDT) { /* Large Resource Data Type Tag */ @@ -113,6 +111,12 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) } } return 0; + +error: + pci_info(dev, "invalid VPD tag %#04x at offset %zu%s\n", + header[0], off, off == 0 ? + "; assume missing optional EEPROM" : ""); + return 0; } /* From patchwork Thu Jul 29 18:42:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1511375 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Xb/R8y/L; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GbKCW4Pkdz9sSs for ; Fri, 30 Jul 2021 04:42:47 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230002AbhG2Smu (ORCPT ); Thu, 29 Jul 2021 14:42:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:47430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230503AbhG2Smt (ORCPT ); Thu, 29 Jul 2021 14:42:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 208EC60F5E; Thu, 29 Jul 2021 18:42:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627584166; bh=3ungDbb3OMklU9ftRu0d0idMhHW/9diicRxu5L/gMP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xb/R8y/LV3KbeKUpHOXgH4OSKwUxqdO+hhtXZay8z48EIMTbV6XUlzdYvea2rQNaS mJCBdrUgEkLZuVocjfz9adoexgVXccFkuLHKO5nMhzypM92XuWyokF6NkUQElvLlhi Zrz5VHFP9TFBJSjvBUJnlYHXc6pGkKz9NLV4lmaftvqrA/Wz7VMrFd9JkzCY6QU/d1 Z7vUrXUl3fPAto7+LrnkhyCI3q62nn3Rmg1r2mG9yrQ+khhmVDIqkaZATeJAopx1be f4DbZROTS/CPfj8nA6vbq858xoLYPhh+980+mBM96tL55okHTKZXbqInVn5m1uzhO+ ngA6ODpDwhMnQ== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v2 4/6] PCI/VPD: Reject resource tags with invalid size Date: Thu, 29 Jul 2021 13:42:32 -0500 Message-Id: <20210729184234.976924-5-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210729184234.976924-1-helgaas@kernel.org> References: <20210729184234.976924-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas VPD is limited in size by the 15-bit VPD Address field in the VPD Capability. Each resource tag includes a length that determines the overall size of the resource. Reject any resources that would extend past the maximum VPD size. Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 66703de2cf2b..e52382050e3e 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -77,6 +77,7 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) while (off < old_size && pci_read_vpd(dev, off, 1, header) == 1) { unsigned char tag; + size_t size; if (off == 0 && (header[0] == 0x00 || header[0] == 0xff)) goto error; @@ -94,8 +95,11 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) off + 1); return 0; } - off += PCI_VPD_LRDT_TAG_SIZE + - pci_vpd_lrdt_size(header); + size = pci_vpd_lrdt_size(header); + if (off + size > PCI_VPD_MAX_SIZE) + goto error; + + off += PCI_VPD_LRDT_TAG_SIZE + size; } else { pci_warn(dev, "invalid large VPD tag %02x at offset %zu", tag, off); @@ -103,9 +107,12 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) } } else { /* Short Resource Data Type Tag */ - off += PCI_VPD_SRDT_TAG_SIZE + - pci_vpd_srdt_size(header); tag = pci_vpd_srdt_tag(header); + size = pci_vpd_srdt_size(header); + if (size == 0 || off + size > PCI_VPD_MAX_SIZE) + goto error; + + off += PCI_VPD_SRDT_TAG_SIZE + size; if (tag == PCI_VPD_STIN_END) /* End tag descriptor */ return off; } From patchwork Thu Jul 29 18:42:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1511376 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=cVUCzByF; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GbKCZ4Zhyz9sW8 for ; Fri, 30 Jul 2021 04:42:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231599AbhG2Smv (ORCPT ); Thu, 29 Jul 2021 14:42:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:47484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbhG2Smv (ORCPT ); Thu, 29 Jul 2021 14:42:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B091860FE7; Thu, 29 Jul 2021 18:42:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627584168; bh=wgMnDar7z06DT1D6H2XVzvIVMOM4sIg6YdnekTrArWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cVUCzByFOF/La8Y95HYMTqkFXqpdkv6fkPkcVUfrpZFl5PJtWgiTozXJGH5t5QHqr +7utPzpHsPa6AqyXOH19LUbFl+5avFwMboLtgPEC6VwaonBcO1WFtvlQgX4vY8N59m TDiThUFJJfXFWiZOcXwm81loyycdN3uniPj0kPJEKeN0t1sRJk7liVWreLSt+vJiXh Cd2T7jvZOxWw0sNy1OxaxNY7cPJmOdwWQDvZDfpDazcInLQ7UAOjXMJfu+4TNMowgR C+r/603peCWoVwR4dwGu11EkLvnMXsHvfGPrCXhdp5RHB7fzoXXCSd42UAKOb3r4ig wv9IvgYjOLqAg== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v2 5/6] PCI/VPD: Don't check Large Resource Item Names for validity Date: Thu, 29 Jul 2021 13:42:33 -0500 Message-Id: <20210729184234.976924-6-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210729184234.976924-1-helgaas@kernel.org> References: <20210729184234.976924-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas VPD consists of a series of Small and Large Resources. Computing the size of VPD requires only the length of each, which is specified in the generic tag of each resource. We only expect to see ID_STRING, RO_DATA, and RW_DATA in VPD, but it's not a problem if it contains other resource types because all we care about is the size. Drop the validity checking of Large Resource items. Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index e52382050e3e..6fa09e969d6e 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -85,26 +85,11 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) if (header[0] & PCI_VPD_LRDT) { /* Large Resource Data Type Tag */ tag = pci_vpd_lrdt_tag(header); - /* Only read length from known tag items */ - if ((tag == PCI_VPD_LTIN_ID_STRING) || - (tag == PCI_VPD_LTIN_RO_DATA) || - (tag == PCI_VPD_LTIN_RW_DATA)) { - if (pci_read_vpd(dev, off+1, 2, - &header[1]) != 2) { - pci_warn(dev, "failed VPD read at offset %zu", - off + 1); - return 0; - } - size = pci_vpd_lrdt_size(header); - if (off + size > PCI_VPD_MAX_SIZE) - goto error; + size = pci_vpd_lrdt_size(header); + if (off + size > PCI_VPD_MAX_SIZE) + goto error; - off += PCI_VPD_LRDT_TAG_SIZE + size; - } else { - pci_warn(dev, "invalid large VPD tag %02x at offset %zu", - tag, off); - return 0; - } + off += PCI_VPD_LRDT_TAG_SIZE + size; } else { /* Short Resource Data Type Tag */ tag = pci_vpd_srdt_tag(header); From patchwork Thu Jul 29 18:42:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1511377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=IkeB1UqZ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GbKCd43ttz9sW8 for ; Fri, 30 Jul 2021 04:42:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231984AbhG2Sm4 (ORCPT ); Thu, 29 Jul 2021 14:42:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:47514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231622AbhG2Smx (ORCPT ); Thu, 29 Jul 2021 14:42:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 56FCF60FED; Thu, 29 Jul 2021 18:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627584169; bh=FH7c/v8eNoRP4MKEI2nHhlzG8/WwzP4fZLwjKx4ZIfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IkeB1UqZhHsA11mwFeqpNdfJrpr34JNE+nD0xrr/L757+Rilp4wMZ69x1H3HlAwjc JQdHavwXveriYZJKF9WiHSOXlakxY+EN9uRdeCAAwDY/HEdxFXD5BtY4hpxNnAxcV6 kFgtnnu7Xi1krsusfg277bCHekS0l8g9zc7lyZW43wRZVozK5P7Dw+lbgxCYE0iYjE CPkp1Xy26e58PEHyEI3hlbaNREGR8FjC3yDIzHFKqFJ41BxyLSdcxKDckTOkOpWeAh S+d2Ahbi/kCbPlPywICf/FEvrAWB1EWnPcYzYFIBTtb0Tsz/XfqzSVvNA4XdTXfJAo ZyxwAsxyk7s4g== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v2 6/6] PCI/VPD: Allow access to valid parts of VPD if some is invalid Date: Thu, 29 Jul 2021 13:42:34 -0500 Message-Id: <20210729184234.976924-7-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210729184234.976924-1-helgaas@kernel.org> References: <20210729184234.976924-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Previously, if we found any error in the VPD, we returned size 0, which prevents access to all of VPD. But there may be valid resources in VPD before the error, and there's no reason to prevent access to those. "off" covers only VPD resources known to have valid header tags. In case of error, return "off" (which may be zero if we haven't found any valid header tags at all). Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 6fa09e969d6e..f74d2f5194e4 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -85,6 +85,11 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) if (header[0] & PCI_VPD_LRDT) { /* Large Resource Data Type Tag */ tag = pci_vpd_lrdt_tag(header); + if (pci_read_vpd(dev, off + 1, 2, &header[1]) != 2) { + pci_warn(dev, "failed VPD read at offset %zu", + off + 1); + return off; + } size = pci_vpd_lrdt_size(header); if (off + size > PCI_VPD_MAX_SIZE) goto error; @@ -102,13 +107,13 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) return off; } } - return 0; + return off; error: pci_info(dev, "invalid VPD tag %#04x at offset %zu%s\n", header[0], off, off == 0 ? "; assume missing optional EEPROM" : ""); - return 0; + return off; } /*