From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web12.9374.1585136335981475015 for ; Wed, 25 Mar 2020 04:38:56 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=zHcmCP0D; spf=pass (domain: linaro.org, ip: 209.85.221.66, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wr1-f66.google.com with SMTP id a25so2666891wrd.0 for ; Wed, 25 Mar 2020 04:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=yTzrVVXj3pvgwa4anqXRl/eQ2pbGp7PCweeqPhGCFmM=; b=zHcmCP0DpNIezz/9X7L7hEdCVqTDY6EQbecZugfZ6qAocvXDw7h+nNY3qiP3BNrlIe kySIHdWiArtm9ieOznq67o/dU9tpOrcug/RLaIOUYE0LDQrSx7v78KumWfFbR8Fr7UMB Bop5Bj49lDxyn4HezBUUHP2Y5atk9mM9nRvYHjabFF0UzZQyDE9BdeLgus3xPKIcM/no rSNmedoeYaJCd5MmYi03L0bPIqTZGOx651cW7na7KUyHFPFJMwW2OfOLfkk5EkefDoXy UMLzAibwLIzxTSztoCscYI/1T1cdUpjaR5FffCXTAnyDC4bXzIsNwIY9e/etRL3ooaCC OBqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yTzrVVXj3pvgwa4anqXRl/eQ2pbGp7PCweeqPhGCFmM=; b=IGbkL48TKjbJlv7Gty4DzovQXQwQFMFHKRjVR7RGwgl84MpUk0dFB3IWosaJM1Y/Pu +xz3ciS9NhU9efWtK0t1/TBdsVQ61laBFtUrp4kZVTBjrS5FBMl+joGNidGmVgXA0VAa S5R8WQPYMZBVW1Iz/BeSAPUgvM3gIP9BX2+OEKbZubd3AJveLlri6ORKfS3W0GZW2ELb qRp7CISfYMFof3h2S9JGLuRz0B9YKtpNx5Rvc8HCj/Ua02OMiEATSpwDvXnXz97c5exA bBvj60E1e6Kd1yvVHlyuvZ8P8ZREBivJ1cSWHXO+3vB4lbSBobcfgz9D5y7nDxUZKc9u bzFQ== X-Gm-Message-State: ANhLgQ2tGDEDAQQENeN8/ro1tV6sSFqFMz8ukT9RakFFdlXbIzKDW014 0aYo5GoQVXFZj60CH/mki1uXGHLQmy4O4ZMc X-Google-Smtp-Source: ADFU+vsXeal3ZvYAYXxE654TL9/UEOQlHIE0ByoOCDiPv/fPDdVuU/mgu0B9mcQ9LpbDOExYbrYvlA== X-Received: by 2002:a5d:6581:: with SMTP id q1mr2896767wru.17.1585136334357; Wed, 25 Mar 2020 04:38:54 -0700 (PDT) Return-Path: Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr. [109.210.65.247]) by smtp.gmail.com with ESMTPSA id v26sm33259682wra.7.2020.03.25.04.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2020 04:38:53 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Leif Lindholm , Ashish Singhal Subject: [PATCH v2 0/2] ArmPkg/ArmMmuLib AARCH64: correctness fix Date: Wed, 25 Mar 2020 12:38:44 +0100 Message-Id: <20200325113846.21700-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 The new ArmMmuLib code is easier to reason about, so that is what I did: currently, when we create mappings that cover existing table entries, we may end up overwriting those with block entries without taking the mapping attributes of the original table entries into account. So let's fix this. I honestly don't know whether the original code was better at dealing with this: I do remember some changes from Heyi that may have been related, but the old code is not easy to follow. In any case, I didn't manage to hit this case in practice, given that we typically start out with large mappings, and break them down later (to set permissions), rather than the other way around. Patch #1 adds some helpers to hide the insane way the type bits change meaning when you change to level 3. Patch #2 ensures that we only replace (and free) table entries with block entries if it is guaranteed that doing so will not lose any attribute information. Changes since v1: - zero newly allocated pages before splitting a block entry into a table entry, to avoid garbage in that page being misidentified as entry type attributes - this should fix the crash observed by Laszlo Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Ashish Singhal Ard Biesheuvel (2): ArmPkg/ArmMmuLib AARCH64: use helpers to determine table entry types ArmPkg/ArmMmuLib AARCH64: preserve attributes when replacing a table entry .../Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 65 ++++++++++++++++--- 1 file changed, 56 insertions(+), 9 deletions(-) -- 2.17.1