Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2111295pxf; Sat, 20 Mar 2021 04:59:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqgF5Z51clYBAJksCeTU07dh7scqGgPyNGSy8j/0SJbLRcrKwKCfpqH07Y0s4+lzWlhLXs X-Received: by 2002:a05:6402:4395:: with SMTP id o21mr14842761edc.22.1616241569462; Sat, 20 Mar 2021 04:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616241569; cv=none; d=google.com; s=arc-20160816; b=RQdHwlEmiaNegjzPwInO4jnLNmA2I9+gi5sk9J7Y3uw/6Iuu5aLimrr+44CjMIQeKk wXIqsxkfKxz+sgFnITgBSr0a5z0xyhsvb2AFSJ/UuiEk7OrP1xWVXMhpq4iC+U5PfVlj M2Gva+YBoL5dGUQMPyQ8Wu12JUzCRF+d12l6ydBzQVQSn2/bqlBif7mllXHvYknYISNJ DV2OwvT7bxYS1uZO//lQxeTuI3grkky36rFdRSiXiUr30i+kDvvO35rGdLpoEAxfC5hD WmcCdFnWIvc9uVSzEw+9kHNQHUx3IcvsHqnJ5G3DSyQdJ4L4jU6fXmGZxrbawrxDzdjg 3RvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UUZSld/Y2ScyH/gr9DXdRTOqZEpHJR3JyvCTPA1fYjo=; b=FI8OPqNjjDuJUecSBkS9NfV6poEAO/2YyKblsMRnDvOZRkzJBT9hCJBLpa7U7adcQE GmrFUvm2Z3FSL+f2GNhuD/2MOC6U51UQvirJPw60z43i8j4U8EB9Mm2Ypes8P0xxhcUp Z75uEvS7GEu9N3d474yWvwLSwowYy7/8Fl8qbqBivuEIjAxFIb7qnBRRiG1utCALVb3/ KroTgxhStPVA35LxmZ9nd3heDBydOxptyhlIUAzrcfHNSkabJ7Qg4a7R7rMEuWSwPz2Y 349ACB8pFzstV7LngwY99jRW5efU7XWxzUgIutyBYtJR8o3IKyGn1eLG92SrH5yjE2wA xIbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=e7K92LmP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y25si6589373eje.459.2021.03.20.04.59.07; Sat, 20 Mar 2021 04:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=e7K92LmP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbhCTL6N (ORCPT + 99 others); Sat, 20 Mar 2021 07:58:13 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46948 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbhCTL6A (ORCPT ); Sat, 20 Mar 2021 07:58:00 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 12K83rNM143519; Sat, 20 Mar 2021 04:25:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=UUZSld/Y2ScyH/gr9DXdRTOqZEpHJR3JyvCTPA1fYjo=; b=e7K92LmPpPWpQyx7VbEPIv5pysKwYkQOwXcq0Din0U1POcYIOht6JoBfjKcn6XUiC3LU /dd86y5VNoWvCGMc+jWgx+3ipd7dRAO8+EPf7XWyD3eSguuJJeIdtrswvqtyqAvY+Huq bxV+oiGMWTQI29rnJ5z6RH+bPc2us+braw3rOU+zrRBDNFqau28K+H1WP1XBeVHWCSO0 T9rjycSpeshQHnQEaFZxg0rGZ1ngwTxCxWsMPTipLsbfSUGEFeseI1wfXLhHRrZaC71J z81Qak4bVFKmEN/Jc78AA+//0gpF3GyfPoa0Yj8mxW4t35qTsHJ5yxG3rbTt0im5UWek Sw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37dd6v8af8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 20 Mar 2021 04:25:29 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 12K85ALr150631; Sat, 20 Mar 2021 04:25:29 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 37dd6v8af0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 20 Mar 2021 04:25:28 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 12K8MbUB017835; Sat, 20 Mar 2021 08:25:26 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04ams.nl.ibm.com with ESMTP id 37d99r89q2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 20 Mar 2021 08:25:26 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 12K8PO6657737682 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 20 Mar 2021 08:25:24 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3A7605204F; Sat, 20 Mar 2021 08:25:24 +0000 (GMT) Received: from linux.ibm.com (unknown [9.145.165.64]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 01CEE52052; Sat, 20 Mar 2021 08:25:21 +0000 (GMT) Date: Sat, 20 Mar 2021 10:25:19 +0200 From: Mike Rapoport To: "Rafael J. Wysocki" Cc: "Rafael J. Wysocki" , Erik Kaneda , David Hildenbrand , George Kennedy , Robert Moore , Rafael Wysocki , Len Brown , ACPI Devel Maling List , "open list:ACPI COMPONENT ARCHITECTURE (ACPICA)" , Linux Kernel Mailing List , Konrad Rzeszutek Wilk , Dan Carpenter , Dhaval Giani , Andrew Morton , Vlastimil Babka , Oscar Salvador , Wei Yang , Pankaj Gupta , Michal Hocko Subject: Re: [PATCH 1/1] ACPI: fix acpi table use after free Message-ID: References: <3236337.DtqTXxM43S@kreacher> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-03-19_12:2021-03-19,2021-03-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 clxscore=1015 suspectscore=0 malwarescore=0 impostorscore=0 phishscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103200058 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 18, 2021 at 04:22:37PM +0100, Rafael J. Wysocki wrote: > On Thu, Mar 18, 2021 at 11:50 AM Rafael J. Wysocki wrote: > > > > On Thu, Mar 18, 2021 at 8:25 AM Mike Rapoport wrote: > > > > > > On Wed, Mar 17, 2021 at 09:14:37PM +0100, Rafael J. Wysocki wrote: > > > > On Monday, March 15, 2021 5:19:29 PM CET Rafael J. Wysocki wrote: > > > > > On Sun, Mar 14, 2021 at 8:00 PM Mike Rapoport wrote: > > > > > > > > > > > > On Thu, Mar 11, 2021 at 04:36:31PM +0100, Rafael J. Wysocki wrote: > > > > > > > On Wed, Mar 10, 2021 at 8:47 PM David Hildenbrand wrote: > > > > > > > > > > > > > > > > > > There is some care that should be taken to make sure we get the order > > > > > > > > > right, but I don't see a fundamental issue here. > > > > > > > > > > > > > > Me neither. > > > > > > > > > > > > > > > > If I understand correctly, Rafael's concern is about changing the parts of > > > > > > > > > ACPICA that should be OS agnostic, so I think we just need another place to > > > > > > > > > call memblock_reserve() rather than acpi_tb_install_table_with_override(). > > > > > > > > > > > > > > Something like this. > > > > > > > > > > > > > > There is also the problem that memblock_reserve() needs to be called > > > > > > > for all of the tables early enough, which will require some reordering > > > > > > > of the early init code. > > > > > > > > > > > > > > > > Since the reservation should be done early in x86::setup_arch() (and > > > > > > > > > probably in arm64::setup_arch()) we might just have a function that parses > > > > > > > > > table headers and reserves them, similarly to how we parse the tables > > > > > > > > > during KASLR setup. > > > > > > > > > > > > > > Right. > > > > > > > > > > > > I've looked at it a bit more and we do something like the patch below that > > > > > > nearly duplicates acpi_tb_parse_root_table() which is not very nice. > > > > > > > > > > It looks to me that the code need not be duplicated (see below). > > > > > > > > > > > Besides, reserving ACPI tables early and then calling acpi_table_init() > > > > > > (and acpi_tb_parse_root_table() again would mean doing the dance with > > > > > > early_memremap() twice for no good reason. > > > > > > > > > > That'd be simply inefficient which is kind of acceptable to me to start with. > > > > > > > > > > And I changing the ACPICA code can be avoided at least initially, it > > > > > by itself would be a good enough reason. > > > > > > > > > > > I believe the most effective way to deal with this would be to have a > > > > > > function that does parsing, reservation and installs the tables supplied by > > > > > > the firmware which can be called really early and then another function > > > > > > that overrides tables if needed a some later point. > > > > > > > > > > I agree that this should be the direction to go into. > > > > > > > > So maybe something like the patch below? > > > > > > > > I'm not sure if acpi_boot_table_prepare() gets called early enough, though. > > > > > > To be 100% safe it should be called before e820__memblock_setup(). > > > > OK > > Well, that said, reserve_bios_regions() doesn't seem to have concerns > like this and I'm not sure why ACPI tables should be reserved before > this runs. That applies to efi_reserve_boot_services() too. > > I can put the new call before e820__memblock_alloc_reserved_mpc_new(), > but I'm not sure why to put it before efi_reserve_boot_services(), > say? The general idea is to reserve all the memory used by the firmware before memblock allocations are possible, i.e. before e820__memblock_setup(). Currently this is not the case, but it does not make it more correct. Theoretically, it is possible that reserve_bios_regions() will cause a memory allocation and the allocated memory will be exactly at the area where ACPI tables reside. In practice I believe this is very unlikely, but who knows. Another advantage of having ACPI tables handy by the time we do the memory detection is that we will be able to SRAT earlier and simplify NUMA initialization. -- Sincerely yours, Mike.