Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jEeQy-0000gu-Ue for mharc-grub-devel@gnu.org; Wed, 18 Mar 2020 15:32:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33045) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEeQv-0000gn-Ax for grub-devel@gnu.org; Wed, 18 Mar 2020 15:32:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEeQt-0000um-LC for grub-devel@gnu.org; Wed, 18 Mar 2020 15:32:53 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36062 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 1jEeQt-0000tD-G2 for grub-devel@gnu.org; Wed, 18 Mar 2020 15:32:51 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02IJVam1009493; Wed, 18 Mar 2020 15:32:49 -0400 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 2yu7d9y0na-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Mar 2020 15:32:49 -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 02IJV5Vu032246; Wed, 18 Mar 2020 19:32:48 GMT Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by ppma01wdc.us.ibm.com with ESMTP id 2yrpw6juyu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Mar 2020 19:32:48 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 02IJWlxX19595726 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Mar 2020 19:32:48 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF34CBE056; Wed, 18 Mar 2020 19:32:47 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9AC19BE053; Wed, 18 Mar 2020 19:32:47 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 18 Mar 2020 19:32:47 +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> From: Stefan Berger Message-ID: <7ba9fa0c-75ad-e3c7-77ab-08b983ccae30@linux.ibm.com> Date: Wed, 18 Mar 2020 15:32:47 -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: <20200318155906.GC2186@itdev.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed 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-18_07:2020-03-18, 2020-03-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 adultscore=0 spamscore=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003180085 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id 02IJVam1009493 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: Wed, 18 Mar 2020 19:32:55 -0000 On 3/18/20 11:59 AM, Simon Hardy wrote: > The 2020/03/17 13:15, Stefan Berger wrote: >> =C2=A0I trying to add (v)TPM support for the ieee1275/powerpc64 platf= orm to grub. >> The issue I have been running into is that the verifier runs out of me= mory. >> At that point it has loaded the (~ 32MB) Linux kernel and now the veri= fier >> is invoked to load the file. Unfortunately it cannot load the file sin= ce it >> doesn't have enough memory to grub_malloc. I have played with increasi= ng >> heap size(es) but it still doesn't work. The kernel and initramfs file= s on >> ppc64 can be rather big, thus we do not a lot of memory. The rescue >> initramfs here is for example 78MB, a regular initramfs from Fedora 31= is >> ~34MB. The kernel sizes on my system are 32MB, though a colleague was = using >> an unstripped kernel of 127MB, so lots of (unfragmented) memory needs = to be >> available to run verifiers. > The verifiers framework has a flag, GRUB_VERIFY_FLAGS_SINGLE_CHUNK, tha= t is > used by the platform-independent TPM module. This could be deferred to = the > platform-specific TPM file (see point 3 below). With this flag unset fo= r your > platform, you could verify the files in small chunks. This requires thr= ee > further elements: > > 1. You will need to implement the chunk-by-chunk behaviour in > verifiers.c, it doesn't exist yet. > > 2. You will need to add functionality to calculate a hash from chunks, = or > require that the crypto module is built into the core. > > 3. The firmware interface needs to support HashLogExtend with a user su= pplied > hash instead of a memory buffer. For example the PC Conventional BIOS A= PI has > this, but the UEFI API does not. Simon, thanks a lot for your reply. TPM 2's logging behavior is different than that of a TPM 1.2 and it's=20 not clear whether hashing in grub will produce the right hash or hashes=20 (for different PCR banks) as needed by the firmware. I would rather=20 leave the hashing entirely up to the firmware because it knows which PCR=20 banks are activate and what hashes it wants to use for logging and PCR=20 extending. I was wondering whether it would not be possible to load the raw file=20 into memory, pass it to the firmware for hashing (and logging) via the=20 verifier, and if we do not trust that the firmware treated the file data=20 as a read-only array, load the file again into the same array right=20 after. This way we wouldn't need more memory. [*] However, I am not sure=20 how it fits into the architecture with the verifiers or whether the TPM=20 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=20 the heap size somehow? My machine has GBs of memory, so it really=20 shouldn't be a problem to get memory. [*] Obviously we can load the files. We can also load them while the TPM=20 verifier is active but only when preventing the loading of those large=20 files (actually allowing the grub_malloc() on the large size to occurr=20 seems to cause issues booting). The memory allocations that are=20 occurring due to the TPM verifier do not seem to cause memory=20 fragmentation=C2=A0 that would prevent the loading of those large files. = So,=20 makes me think, re-load the files into the same memory. =C2=A0=C2=A0 Stefan > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel