Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jEyAu-0001CZ-Ln for mharc-grub-devel@gnu.org; Thu, 19 Mar 2020 12:37:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51604) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEyAr-00019a-RT for grub-devel@gnu.org; Thu, 19 Mar 2020 12:37:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEyAq-0006VH-ES for grub-devel@gnu.org; Thu, 19 Mar 2020 12:37:37 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:4448 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEyAq-0006QT-8I for grub-devel@gnu.org; Thu, 19 Mar 2020 12:37:36 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02JGYkdO009773; Thu, 19 Mar 2020 12:37:25 -0400 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com with ESMTP id 2yu98unysh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 19 Mar 2020 12:37:24 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 02JGVwrQ030408; Thu, 19 Mar 2020 16:37:24 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01wdc.us.ibm.com with ESMTP id 2yrpw6stav-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 19 Mar 2020 16:37:24 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 02JGbNpi53871076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Mar 2020 16:37:23 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 63959BE051; Thu, 19 Mar 2020 16:37:23 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2B5EFBE04F; Thu, 19 Mar 2020 16:37:23 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 19 Mar 2020 16:37:22 +0000 (GMT) Subject: Re: Verifier running out of memory on ieee1275/powerpc64 To: The development of GNU GRUB , Simon Hardy References: <20200318155906.GC2186@itdev.co.uk> <7ba9fa0c-75ad-e3c7-77ab-08b983ccae30@linux.ibm.com> <8066faa6-3879-91a2-80c6-c5ca6c753a7b@linux.ibm.com> <20200318221729.GA4451@itdev.co.uk> From: Stefan Berger Message-ID: Date: Thu, 19 Mar 2020 12:37:22 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200318221729.GA4451@itdev.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645 definitions=2020-03-19_06:2020-03-19, 2020-03-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 adultscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003190069 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2020 16:37:39 -0000 On 3/18/20 6:17 PM, Simon Hardy wrote: >>> I was wondering whether it would not be possible to load the raw file >>> into memory, pass it to the firmware for hashing (and logging) via the >>> verifier, and if we do not trust that the firmware treated the file data >>> as a read-only array, load the file again into the same array right >>> after. This way we wouldn't need more memory. [*] However, I am not sure >>> how it fits into the architecture with the verifiers or whether the TPM >>> verifier would have to take on a special role (possibly with a flag) >>> then. >>> >>> You didn't pick up on the idea of a bigger heap. Is there a problem with >>> the heap size somehow? My machine has GBs of memory, so it really >>> shouldn't be a problem to get memory. >> I think that's the problem to solve, at least for this platform, since none >> of the verifiers will work due to the memory exhaustion issue. > Increasing the heap size may be the easiest way for you to solve this > problem. I am not so familiar with the issues around doing this, but I > have seen recent discussion on this list. I found the lsmmap command and it shows me some impressive memory ranges to be known: base_addr = 0x4000, length = 0x17c000, available RAM base_addr = 0x1fffff, length = 0x1, available RAM base_addr = 0x21ffff, length = 0x1, available RAM base_addr = 0x2000000, length = 0x7bbf0000, available RAM base_addr = 0x7feffffff, length = 0x1, available RAM base_addr = 0x800903dc, length = 0x7ff6fc24, available RAM There's more than needed memory here. It doesn't seem to be available for grub_malloc, though. > > The reason there is extra memory usage is that the verifier framework is > built on top of the file filter framework. The process is: > 1. The file is opened using grub_file_open. > 2. The verifier framework opens the underlying file and reads all of it > into a new heap-allocated memory buffer. > 3. The verifier framework provides the buffer to the verifiers for > verification. > 4. The verifier framework returns a file handle. > 5. Read operations on this file handle are served by copying from the > verification buffer. Yes, saw this, verify_fs. > 6. The file is closed. The verification framework frees its buffer. > > There are good reasons for doing this. It is more secure to ensure that > verification is applied to the same data that is actually used. (An > attacker could give you different data on a second read from the disk.) Also true. > Some verifiers, like the TPM, prefer to receive the data in a single > chunk. Existing code depends on the open/read/seek/close file access > model. > > The problem you have run into is that where you have a use case that > involves loading a large file into memory then you need enough free > memory to hold two copies of that file. > > Ideally there would be an alternative grub_file_read_all function that > loads the contents of a named file to a user-provided memory buffer. > This doesn't look like it would be simple or easy, for example I don't > know how this would work for compressed files. Stefan > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel