From patchwork Fri Apr 12 10:33:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 13627529 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98FA73FE3D for ; Fri, 12 Apr 2024 10:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712918065; cv=none; b=JrRglSstGL3WfSD/MwshGUG6oXRpQIlJmaFWwfGet3IVPJIM52CUF89/J5o+Sj9sVL2RCj5RxjwqjsFaVzJ6mLrGCBdOixf+Tnr2g6tdGILLgdT/dcmpW4SATQpZIV61yKdq4xvWwsrBHnTVhlRa4dvEcuOVWXLtGyKkIEfcZAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712918065; c=relaxed/simple; bh=wVApZFw3Jgpr1h5HbRcGGyXr+HJpl/gFzNMPoPRtR6Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=emPgtcdqa4ZQxFLX+fks+IwjfCpBUVTWhBxEgMZ0HfxionAsAEPcplNUbld2sVFL25zICDH5gHTnJkRSKwm70UhM6XrX3cIW7aAfgTGy8rovjmxX4monMq6TMgKCr2/uPEiVuYV0736XuUsLTnpBumT+Y6z+Gtbmq8H9p8BiF84= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4864C1596; Fri, 12 Apr 2024 03:34:52 -0700 (PDT) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EFB943F64C; Fri, 12 Apr 2024 03:34:20 -0700 (PDT) From: Suzuki K Poulose To: kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-arm-kernel@lists.infradead.org, maz@kernel.org, alexandru.elisei@arm.com, joey.gouly@arm.com, steven.price@arm.com, james.morse@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, andrew.jones@linux.dev, eric.auger@redhat.com, Suzuki K Poulose Subject: [kvm-unit-tests PATCH 02/33] arm: Detect FDT overlap with uninitialised data Date: Fri, 12 Apr 2024 11:33:37 +0100 Message-Id: <20240412103408.2706058-3-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412103408.2706058-1-suzuki.poulose@arm.com> References: <20240412103408.2706058-1-suzuki.poulose@arm.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If the FDT was placed in a region overlapping the bss/stack area, it would have been overwritten at early boot. Assert this never happened to detect the case. Signed-off-by: Suzuki K Poulose --- lib/arm/setup.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/arm/setup.c b/lib/arm/setup.c index 2f649aff..462a1d51 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -35,6 +35,7 @@ #define NR_MEM_REGIONS (MAX_DT_MEM_REGIONS + NR_EXTRA_MEM_REGIONS) extern unsigned long _text, _etext, _data, _edata; +extern unsigned long stacktop; char *initrd; u32 initrd_size; @@ -196,6 +197,12 @@ static void freemem_push_fdt(void **freemem, const void *fdt) u32 fdt_size; int ret; + /* + * Ensure that the FDT was not overlapping with the uninitialised + * data that was overwritten. + */ + assert((unsigned long)fdt > (unsigned long)&stacktop); + fdt_size = fdt_totalsize(fdt); ret = fdt_move(fdt, *freemem, fdt_size); assert(ret == 0);