Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4863166rdb; Fri, 15 Sep 2023 15:00:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkoj2jdzIULXBdoxs6cU8Keacc/oQz3HNo0CtBaiHSx3NcXDH+gmevMJDBgdWXPAYF+/zD X-Received: by 2002:a05:6a20:54a8:b0:13f:65ca:52a2 with SMTP id i40-20020a056a2054a800b0013f65ca52a2mr3483817pzk.5.1694815244084; Fri, 15 Sep 2023 15:00:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694815244; cv=none; d=google.com; s=arc-20160816; b=qV4ewJdFv9IN8/MrcwP4wvsUI/jwUNpQ7WxoXMZ1TKHuswMVidOvnVfu08WPWv+yzK O2Jwl2u7S9Q/iOKOrDJI+GfwBhgGYrbNkx4zR5JXMJo2mezaVencQZ8Pm4ktDea5XhzI mJvU0bpmXt959vXDFilIttPZ18CX4a9R9hROT5yCuJ0bzdoGg6Qq3MEnxDYPkYAMn9mF YU8+yotqLotOOReWwD0xtd5PNzSEHHjDeL95c/F9et9/HuNdsq39DC7SOQBfrtV61qJp B/DTwaYj8fhIAcOaIa+GAOgwsJomY4Hz60C/uwZkxfmUNccIqL5SW19M/o0RH51mAgvf rpEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=byZ/MF0PnOLhCzL5oMCVKITAw3McJ+D3CeWCYWT3WU8=; fh=+2uhTD+U5suitMK/ECMS7aYIjYC0OEFTOViwMabGiiM=; b=RXj7a3ZSBjsKER4uRsrCmWBuD95gxGbsMMkqu0Yi6blcrGUYrFtoMbr87vNHYFwC7Q 9CsSPeQV+ZKw/gBPqg866wLNd2NmU94ETTC4Zd557UQAdT4+COmlXKs3UArSbH/vYA+r nM0I85RT8qs6PYWXMAibhLvGNfmkdDgqXh+1QSMhGrPZLkEdsznj1XEra19vL/tfaS+p UaA+9KuN+EP/qoXoatQIt1gzY7mKyBEx1WkBCsESZHb38jvLc6708zWw3k6B70auKnlm LX2KxGliRIBSRgSTxZM/JDV8gR+J9Sn7bAkE0cBQwR2UeKeJtfXi28ihLXW7a39mKxhJ BpnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n67-20020a632746000000b00573fbbf187dsi3844915pgn.216.2023.09.15.15.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 15:00:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 371E680B1D2C; Fri, 15 Sep 2023 10:46:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235842AbjIORpo (ORCPT + 99 others); Fri, 15 Sep 2023 13:45:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236367AbjIORpb (ORCPT ); Fri, 15 Sep 2023 13:45:31 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51907210A; Fri, 15 Sep 2023 10:45:22 -0700 (PDT) Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnM0j2d3Sz67bgN; Sat, 16 Sep 2023 01:40:37 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:45:19 +0100 From: To: , , , , , , , , , CC: , , , , Subject: [RFC PATCH 1/1] ACPI / APEI: Fix for overwriting aer info when error status data have multiple sections Date: Sat, 16 Sep 2023 01:44:35 +0800 Message-ID: <20230915174435.779-1-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100006.china.huawei.com (7.191.160.224) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 15 Sep 2023 10:46:20 -0700 (PDT) From: Shiju Jose ghes_handle_aer() lacks synchronization with aer_recover_work_func(), so when error status data have multiple sections, aer_recover_work_func() may use estatus data for aer_capability_regs after it has been overwritten. The problem statement is here, https://lore.kernel.org/all/20230901225755.GA90053@bhelgaas/ In ghes_handle_aer() allocates memory for aer_capability_regs from the ghes_estatus_pool and copy data for aer_capability_regs from the estatus buffer. Free the memory in aer_recover_work_func() after processing the data using the ghes_estatus_pool_region_free() added. Reported-by: Bjorn Helgaas Signed-off-by: Shiju Jose --- drivers/acpi/apei/ghes.c | 23 ++++++++++++++++++++++- drivers/pci/pcie/aer.c | 10 ++++++++++ include/acpi/ghes.h | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index ef59d6ea16da..63ad0541db38 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -209,6 +209,20 @@ int ghes_estatus_pool_init(unsigned int num_ghes) return -ENOMEM; } +/** + * ghes_estatus_pool_region_free - free previously allocated memory + * from the ghes_estatus_pool. + * @addr: address of memory to free. + * @size: size of memory to free. + * + * Returns none. + */ +void ghes_estatus_pool_region_free(unsigned long addr, u32 size) +{ + gen_pool_free(ghes_estatus_pool, addr, size); +} +EXPORT_SYMBOL_GPL(ghes_estatus_pool_region_free); + static int map_gen_v2(struct ghes *ghes) { return apei_map_generic_address(&ghes->generic_v2->read_ack_register); @@ -564,6 +578,7 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO) { unsigned int devfn; int aer_severity; + u8 *aer_info; devfn = PCI_DEVFN(pcie_err->device_id.device, pcie_err->device_id.function); @@ -577,11 +592,17 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) if (gdata->flags & CPER_SEC_RESET) aer_severity = AER_FATAL; + aer_info = (void *)gen_pool_alloc(ghes_estatus_pool, + sizeof(struct aer_capability_regs)); + if (!aer_info) + return; + memcpy(aer_info, pcie_err->aer_info, sizeof(struct aer_capability_regs)); + aer_recover_queue(pcie_err->device_id.segment, pcie_err->device_id.bus, devfn, aer_severity, (struct aer_capability_regs *) - pcie_err->aer_info); + aer_info); } #endif } diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index e85ff946e8c8..388b614c11fd 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "../pci.h" @@ -996,6 +997,15 @@ static void aer_recover_work_func(struct work_struct *work) continue; } cper_print_aer(pdev, entry.severity, entry.regs); + /* + * Memory for aer_capability_regs(entry.regs) is being allocated from the + * ghes_estatus_pool to protect it from overwriting when multiple sections + * are present in the error status. Thus free the same after processing + * the data. + */ + ghes_estatus_pool_region_free((unsigned long)entry.regs, + sizeof(struct aer_capability_regs)); + if (entry.severity == AER_NONFATAL) pcie_do_recovery(pdev, pci_channel_io_normal, aer_root_reset); diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index 3c8bba9f1114..40d89e161076 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -78,6 +78,7 @@ static inline struct list_head *ghes_get_devices(void) { return NULL; } #endif int ghes_estatus_pool_init(unsigned int num_ghes); +void ghes_estatus_pool_region_free(unsigned long addr, u32 size); static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata) { -- 2.34.1