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 9005AC4338F for ; Wed, 11 Aug 2021 08:14:48 +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 B7E126024A for ; Wed, 11 Aug 2021 08:14:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B7E126024A 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 76A7E82CDC; Wed, 11 Aug 2021 10:14:44 +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="AVy3UDbS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 431D782C84; Wed, 11 Aug 2021 10:14:42 +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 8B83C8296F 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 07ED360F41; Wed, 11 Aug 2021 08:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628669678; bh=Sjffoy5sR/AjcaG9Xdk6rbMGj2U0NuWq81vJ+IbN3w4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AVy3UDbSTxj3JQnXGZkbVa3vCZvEiMueWi8KTj4oqiOV4yiFUjRrrJd93MxORutwy Yq2C64KxBwn5g2KIO6XU1ykT/9nV7WQsKewmD3JPLodoTcGw5/1a3nIevm/zrLR4NP vzP8gDlWJUlCfeOpC9b50RW6NlBzUaiW2PGFKKO7ykbEBLMO6Tu4hXumr0vLhP8Qd0 iUQlqAG4YIIc+pK3aoC0DTrrGjRdQX4ag7kPw1hkEqnie65dCgckQ7NQIdUx8cbLr6 lHZeJ1jWaufuaIOPDI0tiu8twwYRiDQAb6k1rif4DTa1FCElLCf7cPZcERknXFw4Bj dApOFOfBlBQoA== Received: by pali.im (Postfix) id 30FFEAFA; Wed, 11 Aug 2021 10:14:36 +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 3/4] tools: kwbimage: Verify size of image data Date: Wed, 11 Aug 2021 10:14:16 +0200 Message-Id: <20210811081417.18010-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210811081417.18010-1-pali@kernel.org> References: <20210811081417.18010-1-pali@kernel.org> 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 Part of image data is 4 byte checksum, so every image must contain at least 4 bytes. Verify it to prevent memory corruptions. Signed-off-by: Pali Rohár --- tools/kwbimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 84c41210e39e..5ac34ac5e9c8 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1757,7 +1757,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, return -FDT_ERR_BADSTRUCTURE; size = le32_to_cpu(mhdr->blocksize); - if (offset + size > image_size || size % 4 != 0) + if (size < 4 || offset + size > image_size || size % 4 != 0) return -FDT_ERR_BADSTRUCTURE; if (image_checksum32(ptr + offset, size - 4) != -- 2.20.1