From patchwork Thu Mar 7 16:09:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Mouette X-Patchwork-Id: 1909362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=exaion.com header.i=@exaion.com header.a=rsa-sha256 header.s=dkim header.b=XAo0XeB7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-pci+bounces-4602-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TrDlX3wRXz23hR for ; Fri, 8 Mar 2024 03:09:44 +1100 (AEDT) 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 83EDE1F24E5A for ; Thu, 7 Mar 2024 16:09:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2D0012F398; Thu, 7 Mar 2024 16:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=exaion.com header.i=@exaion.com header.b="XAo0XeB7" X-Original-To: linux-pci@vger.kernel.org Received: from mail.exaion.in (mail.exaion.in [91.239.56.9]) (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 942E512EBE0 for ; Thu, 7 Mar 2024 16:09:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.239.56.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709827776; cv=none; b=bgo5EkQGGyfHlzMI11aWs2oaZS9zlRIZGqpTTP5a4NZiJx+HFdhtU56I6lIU5nM+VI+TgPT45XNiQ+ESRF8wSaoDz9gNw5xKi6ihGAD2yFoH3RafXnT/dpncue7TFJhIAQDnchgn3hOglwTtSlQUD11zGGrCk+7Vv9rgYU0hqB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709827776; c=relaxed/simple; bh=IW4P7UufERURwOpQebAlBISYHnckkjDTY2Krd0NhZoE=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=nQeIqxSlHAZVump2Onis7MIS0QkqRDgChu9EBjMO9Saw7APYRo8kBdgRUOpX4bhh3XCc2RJGmQw8XH3ZzcKOIibwOALJELrvj8tM+UtDB0nSwvES1G3+lh3h4rtENmC7y/xyKi7VnpwCwgEYKJErfsNsP35LaCNjKtVG+yk47qE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=exaion.com; spf=pass smtp.mailfrom=exaion.com; dkim=pass (2048-bit key) header.d=exaion.com header.i=@exaion.com header.b=XAo0XeB7; arc=none smtp.client-ip=91.239.56.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=exaion.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=exaion.com Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 53F6244109; Thu, 7 Mar 2024 17:09:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=exaion.com; s=dkim; t=1709827769; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=f6o04XfVZSwQLJurPnYWjB6YzlW8GQVmm6e1ooSnit4=; b=XAo0XeB7ENcMeEFmMhbEqMC9sOMtpQrqo2rHH0JBevZO2+9OMw9SWPR6jpTZy3bUTbQVg3 KcWiZ7i8mzr0kWZ9FcF57xa4p19dKU7wXbfUlQnbMCZgC76IlnKhI7/zds3Bb+6daaCT+e IPQY7Llv0uiCWficEfozirN4OJmKRo04F8J6P5CG5sSNqNQF35AO/XyNiW4/SJOIFN/vpz V78mP6afEyoWnhQA1OxQHQzjp4akPb9f0MGy1e8jzfltRDheK1x48MJq3h0jmkCuFrZaAp NW2bxuO6LciRgMV05sKv/aE5ysqcOZcQlt0A6yZUYEyP4G0fWj+iVZbOQN68OQ== Message-ID: <0132edfec66a6bd413823d43ccdf1c4d6aae2b60.camel@exaion.com> Subject: [PATCH 1/2] Revert "PCI/VPD: Allow access to valid parts of VPD if some is invalid" From: Josselin Mouette To: linux-pci@vger.kernel.org Cc: Bjorn Helgaas Date: Thu, 07 Mar 2024 17:09:27 +0100 In-Reply-To: References: User-Agent: Evolution 3.46.4-2 Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 When a device returns invalid VPD data, it can be misused by other code paths in kernel space or user space, and there are instances in which this seems to cause memory corruption. There is no sensible reason why the kernel would provide userspace or drivers with invalid and potentially dangerous data. This reverts commit 5fe204eab174fd474227f23fd47faee4e7a6c000. --- drivers/pci/vpd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) size = pci_vpd_lrdt_size(header); if (off + size > PCI_VPD_MAX_SIZE) @@ -87,13 +87,13 @@ static size_t pci_vpd_size(struct pci_dev *dev) return off; } } - return off; + return PCI_VPD_SZ_INVALID; error: pci_info(dev, "invalid VPD tag %#04x (size %zu) at offset %zu%s\n", header[0], size, off, off == 0 ? "; assume missing optional EEPROM" : ""); - return off ?: PCI_VPD_SZ_INVALID; + return PCI_VPD_SZ_INVALID; } static bool pci_vpd_available(struct pci_dev *dev, bool check_size) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 485a642b9304..daaa208c9d9c 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -68,7 +68,7 @@ static size_t pci_vpd_size(struct pci_dev *dev) if (pci_read_vpd_any(dev, off + 1, 2, &header[1]) != 2) { pci_warn(dev, "failed VPD read at offset %zu\n", off + 1); - return off ?: PCI_VPD_SZ_INVALID; + return PCI_VPD_SZ_INVALID; } From patchwork Thu Mar 7 16:10:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Mouette X-Patchwork-Id: 1909364 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=exaion.com header.i=@exaion.com header.a=rsa-sha256 header.s=dkim header.b=mzGBe4SD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-pci+bounces-4603-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TrDn66LcCz1yX4 for ; Fri, 8 Mar 2024 03:11:06 +1100 (AEDT) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A496A1C252DA for ; Thu, 7 Mar 2024 16:11:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A68912DDB9; Thu, 7 Mar 2024 16:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=exaion.com header.i=@exaion.com header.b="mzGBe4SD" X-Original-To: linux-pci@vger.kernel.org Received: from mail.exaion.in (mail.exaion.in [91.239.56.9]) (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 67B7112FB23 for ; Thu, 7 Mar 2024 16:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.239.56.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709827851; cv=none; b=gqKvkLRWKkXd/9kQVxeBbpWBu/w8POIqdap8EAWnCtPJQTRN5DkIfVaoVlFri730nQqRVT0BAYXU41jB0PTvsm+hM1HnlzDRz9P0eqX/LamBtFk3eZaxZF5DO0MxhaQ4FdLeKxiSlpFFL15aUhWXyHDQdP2FoPA6vg9uBCvOakA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709827851; c=relaxed/simple; bh=upIFTatwDagvNzJYZFB4IaVrlROkF0ASELX/671dWHY=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=FXnFx4nKOtn+dWLZIATiiabFwdVT/g/l0vMBJziOQL2xL1ellp4LfMPNfBN3wlMrHGjdW1rqaq+b3Rp8pRcYs9Jvx24ADPYwvV8f4p62CFiDqcvPb9M0IQFafO40R9ErcgzE8h+fCZmqH9AMiTv+Lbds35m+E+VghgAsG7xVxMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=exaion.com; spf=pass smtp.mailfrom=exaion.com; dkim=pass (2048-bit key) header.d=exaion.com header.i=@exaion.com header.b=mzGBe4SD; arc=none smtp.client-ip=91.239.56.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=exaion.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=exaion.com Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9E1B64412B; Thu, 7 Mar 2024 17:10:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=exaion.com; s=dkim; t=1709827846; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=m8U7poDu3qqEW+mNNxq49GL3/UNmH5Nci5YiMPbS/xE=; b=mzGBe4SD64u2GSqsqy1qSUFXA92n1/UrNUaRzQkKx5DG+2LcZHbByWtjW/u+Oxm9nzpyS4 0T+jxMA/Q9NMPzpM0GeTez8fxWn+3hG/dufeQRNq/xsIPzQVIKp4QKUnxcNS7VePcTwITX yt5SVk8v16q/EcDMzjizM8/2HL0Z1/jGCd9G+sG8SJO7ABinOdntrC2tbyeq32n0KS+8fr lUBbi6tWwAe5kSv36bfGyk2xYagDerTPBO4YnsNorCffg7FTC9nByuFu33NQbFUetMSX16 3Mz3vZFpsaTbTBnQEg+PRwbiLYsJpcJc6PUswVvyw7FVKcgnY9PAOou6rhfmyA== Message-ID: <6fcc9a22e89a11dec1f769d74482592c681e526c.camel@exaion.com> Subject: [PATCH 2/2] Add better warnings about invalid VPD data From: Josselin Mouette To: linux-pci@vger.kernel.org Cc: Bjorn Helgaas Date: Thu, 07 Mar 2024 17:10:46 +0100 In-Reply-To: <0132edfec66a6bd413823d43ccdf1c4d6aae2b60.camel@exaion.com> References: <0132edfec66a6bd413823d43ccdf1c4d6aae2b60.camel@exaion.com> User-Agent: Evolution 3.46.4-2 Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 Some Mellanox Connect-X 3 cards have firmware bugs which return unfinished VPD data. This change helps to diagnose such issues with clear warning messages. --- drivers/pci/vpd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) "; assume missing optional EEPROM" : ""); return PCI_VPD_SZ_INVALID; diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index daaa208c9d9c..fc38a611dd3e 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -87,10 +87,11 @@ static size_t pci_vpd_size(struct pci_dev *dev) return off; } } + pci_warn(dev, "missing VPD_STIN_END at offset %zu\n", off + 1); return PCI_VPD_SZ_INVALID; error: - pci_info(dev, "invalid VPD tag %#04x (size %zu) at offset %zu%s\n", + pci_warn(dev, "invalid VPD tag %#04x (size %zu) at offset %zu%s\n", header[0], size, off, off == 0 ?