Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A255AEB64D9 for ; Mon, 19 Jun 2023 22:41:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CEB93861AA; Tue, 20 Jun 2023 00:41:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1687214482; bh=8MuKr7hOa71J5XIFMZYszQAVptWNVOy5yBF05gjSd8A=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=RtK37EIJp02cJM00ofcWA1tyUo0ljal7RyPWX7VCljA9bTuCStUcmagJYY96BDpQn JSXmdpNkWyoi2hGWt7uF5m8+aG5UJaF2nY5qXJw0nqpJLbcuOjEuX8vUsLg1whH8iB hTqIYS8VQfFCL1/DmsACYA11qCYma+pfPoMYpv3YWIptrd1Jx+FCQ35+Lr/Xe2JRit 9f7qv5QbLj1F7tVitTuyecoR3uzi30I3wd2mcleRiCvpvhShX+MGmQKHifxm9fm62I CQemI3S6tm0woVNQJ1nVmWxNXrOopjfHcRd3vfF62jEu4iDOHWriKhuMqgPF6w1sB/ eXqZTkmUUqjeg== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 71DDA8613D; Tue, 20 Jun 2023 00:41:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1687214478; bh=8MuKr7hOa71J5XIFMZYszQAVptWNVOy5yBF05gjSd8A=; h=From:To:Cc:Subject:Date:From; b=VmK1Gn+0iawCt4tuN8S9r9jITYpjcfqPtN5JYr7BVfD/B64FGgw/iwHOC0wstxJ/q MTN1S9pFtPRmb6FaH8fbChBRu2BQNXCy7okiVKA8tIhuIjScwtO1KPTQk7l+ghXg5E BC6HP6jL+h7oGt6voG6xOOCc2HnzIg+t3AKYW/7xG8Hb2cMsYwkJEqJnAaa4Q6xGHl iHwxWdrqFcsQ5WyWZreoGDW0sw3QRxmkzB6yI5eQdqCP/OI8gyebGBcv2Ew83ot8zL 9r3e2qKZzJ6sVLporoZP3VrGgRHLynU2iG6yvHq2Tx71u+BzMHei58cqOjH4g8C9pq pMT/Tjdcc1e+w== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , "NXP i.MX U-Boot Team" , Fabio Estevam , Heiko Schocher , Heinrich Schuchardt , Rasmus Villemoes , Simon Glass , Stefano Babic , Tom Rini , Ye Li Subject: [PATCH] spl: spl_legacy: Add extra address checks Date: Tue, 20 Jun 2023 00:41:05 +0200 Message-Id: <20230619224105.64004-1-marex@denx.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Check whether the loaded image or entry point does not overlap SPL. Signed-off-by: Marek Vasut --- Cc: "NXP i.MX U-Boot Team" Cc: Fabio Estevam Cc: Heiko Schocher Cc: Heinrich Schuchardt Cc: Rasmus Villemoes Cc: Simon Glass Cc: Stefano Babic Cc: Tom Rini Cc: Ye Li --- common/spl/spl_legacy.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c index 16851c55eb5..b21173baf55 100644 --- a/common/spl/spl_legacy.c +++ b/common/spl/spl_legacy.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -15,6 +16,22 @@ #define LZMA_LEN (1 << 20) +static void spl_parse_legacy_validate(uintptr_t start, uintptr_t size) +{ + uintptr_t spl_start = (uintptr_t)__image_copy_start; + uintptr_t spl_end = (uintptr_t)__image_copy_end; + uintptr_t end = start + size; + + if ((start >= spl_start && start < spl_end) || + (end > spl_start && end <= spl_end) || + (start < spl_start && end >= spl_end) || + (start > end && end > spl_start)) + panic("SPL: Image overlaps SPL\n"); + + if (size > CONFIG_SYS_BOOTM_LEN) + panic("SPL: Image too large\n"); +} + int spl_parse_legacy_header(struct spl_image_info *spl_image, const struct legacy_img_hdr *header) { @@ -58,6 +75,9 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image, "payload image: %32s load addr: 0x%lx size: %d\n", spl_image->name, spl_image->load_addr, spl_image->size); + spl_parse_legacy_validate(spl_image->load_addr, spl_image->size); + spl_parse_legacy_validate(spl_image->entry_point, 0); + return 0; } -- 2.39.2