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 X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 145CAC4338F for ; Wed, 11 Aug 2021 08:15:02 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 308B960EB5 for ; Wed, 11 Aug 2021 08:15:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 308B960EB5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 26BCD82CDE; Wed, 11 Aug 2021 10:14:51 +0200 (CEST) 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="oY79I6P+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 464C182CE8; Wed, 11 Aug 2021 10:14:48 +0200 (CEST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (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 41B8982C84 for ; Wed, 11 Aug 2021 10:14:39 +0200 (CEST) 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: by mail.kernel.org (Postfix) with ESMTPSA id 8989760F38; Wed, 11 Aug 2021 08:14:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628669677; bh=9b6wOVu/+a6xlm3gB6aj8cYpEWclkHH70O65U2OAi+U=; h=From:To:Cc:Subject:Date:From; b=oY79I6P+5Eb9uqrakjP/sxR9blphpJKURUVGs/iJnWsuLk2dDGIygKTq/B/QELVBm 2QRR5nrWd+RyRMPGJ4ViYezyHssL9mx2s4WirPj/RBtre7Z6c2NGE7izm7Klv4vitr 9Lrbsjg+KPaNj/Mp06eain2cxNhDAQNcHbO04ca+daydJKOTl7vVxXaETBxQWH7aOl Jpm1v9zx7EI4vHJU/KTgKgJrHfgnXg+tAgfUayAw12dpQ12pmaYqyJ3+zH7yP7iYnA 4HntxjVRl9Cg7CWWvjuOWlJfQho/I+3RwMzP/Dfq1vfp99AmPpNhTPhyV5gox3dDtx lcyQi0wpd7xOQ== Received: by pali.im (Postfix) id 3BA687AE; Wed, 11 Aug 2021 10:14:35 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH 1/4] tools: kwbimage: Verify supported image version Date: Wed, 11 Aug 2021 10:14:14 +0200 Message-Id: <20210811081417.18010-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.34 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.2 at phobos.denx.de X-Virus-Status: Clean Only image versions 0 and 1 are supported. Verify it in kwbimage_verify_header() function. Signed-off-by: Pali Rohár --- tools/kwbimage.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 4bff02bb3fb5..80aae8a6b619 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1690,9 +1690,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, if (checksum != ext_hdr->checksum) return -FDT_ERR_BADSTRUCTURE; } - } - - if (image_version((void *)ptr) == 1) { + } else if (image_version((void *)ptr) == 1) { struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; uint32_t offset; uint32_t size; @@ -1762,6 +1760,8 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, if (image_checksum32(ptr + offset, size - 4) != *(uint32_t *)(ptr + offset + size - 4)) return -FDT_ERR_BADSTRUCTURE; + } else { + return -FDT_ERR_BADSTRUCTURE; } return 0; -- 2.20.1