From mboxrd@z Thu Jan 1 00:00:00 1970 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 52ADCC05027 for ; Sun, 29 Jan 2023 16:44:38 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 380DB8549C; Sun, 29 Jan 2023 17:44:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="eTvPlomb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 95925855A1; Sun, 29 Jan 2023 17:44:34 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4990F85351 for ; Sun, 29 Jan 2023 17:44:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CF18FB80D19; Sun, 29 Jan 2023 16:44:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D2E9C433D2; Sun, 29 Jan 2023 16:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675010670; bh=LUJWeDKLWMuf6oVeMXDo1IBncCcZ8/kkrl45/cje5H4=; h=From:To:Cc:Subject:Date:From; b=eTvPlombebdyZJ6IDHWktYbhMm5smmYrp1+V043ZjzrRMjG9U4RQgKy2bIgPJZtqq nvNPFBcXg6tQUiUf5Rue9Mkpq6It0clb1UYtbP3RtLPKLnkjcujHNMLQypL36SMgoY dDOjqP078J/0vj1hFkB/cNoeTGebdHf0APNTB4a5B1Pm0EHeeIph/hK/4PSZQrVfdf NNhT8OpAJkjVQSA9qh2aC4elO84H94iJZspkwdf/b6wUc9jrMV472yA9/U5PBAsd1x cSRu/5CJoi9TzVVLndtoRTgekNUz6IQFdi/huqRYucQcd53Togeq2bs0YQc8uxQqyT etf1tZnBB4law== Received: by pali.im (Postfix) id 597C2976; Sun, 29 Jan 2023 17:44:27 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Simon Glass Cc: u-boot@lists.denx.de Subject: [PATCH u-boot 1/2] tools: default_image: Verify header size Date: Sun, 29 Jan 2023 17:44:10 +0100 Message-Id: <20230129164411.9795-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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.6 at phobos.denx.de X-Virus-Status: Clean Before reading image header, verify that image size is at least size of the image header. Signed-off-by: Pali Rohár --- tools/default_image.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/default_image.c b/tools/default_image.c index 4a067e65862e..4aa9a33241cb 100644 --- a/tools/default_image.c +++ b/tools/default_image.c @@ -49,6 +49,12 @@ static int image_verify_header(unsigned char *ptr, int image_size, struct legacy_img_hdr header; struct legacy_img_hdr *hdr = &header; + if (image_size < sizeof(struct legacy_img_hdr)) { + debug("%s: Bad image size: \"%s\" is no valid image\n", + params->cmdname, params->imagefile); + return -FDT_ERR_BADSTRUCTURE; + } + /* * create copy of header so that we can blank out the * checksum field for checking - this can't be done -- 2.20.1