From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 273A0606A323 for ; Sun, 29 Nov 2026 02:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.u-boot-project.org header.i=@lists.u-boot-project.org header.a=rsa-sha256 header.s=default header.b=vOeexLWq Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 68E5580C5D; Sun, 29 Nov 2026 02:04:08 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id UohK4HyjIqC3; Sun, 29 Nov 2026 02:04:07 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp1.osuosl.org 88E6180A9B Authentication-Results: smtp1.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1795917847; b=h+7VV48YAXuEEZMIPeDkmwalWy2P7unm64SyQSf5W9jnKTEjXQU88W+EQLQUckg3qaDy mAHVM7fH0QwEECWlg5IFqvnrmbo7qJtUrLiMFILRvpC0lwQbnxjDCAOSAN4A0LAXFrMfF zl1B2ptDDHKZkz/l2xw6AEwLY+9D/aG8US19m+666PFh3j3ONGF5iGTFePXDmDHgnQSsl QDGaZ2aoV7bg6kXY6s/DdB5ik334Av7nZ1TZX67VYQf9Rdt2PG7lsO0eE4RtW9N2Gwr13 hEK7sFbC0ifxM7KS09RsfLRlHG1VKE2qT3lcIxpnLu2ZLL0gL6llWRcrit0vDkdUhbA== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1795917847; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:Received-SPF:Received:Received:Date: From:To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:X-BeenThere:X-Mailman-Version: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help: List-Subscribe:Errors-To; bh=fmDzgThM61JoAw46JvJtVQC54WQye7C9Qk+CJvD2OGE=; b=g9AI6jGgqNXS3CHdvgEFayyYJwx8hJFnaJwZ82lD401a1oQ0PS43X+HFmeau1Wb2g5Cn 6KhNXAZQVYkokg466V8+gvOTqmNMT3QUy7J5uI6+uZt4lh/gh/Wr3yx1TBIA3WzcgPntE 5fIy9iPjW9mUaRHQyKGKNDOdtVi569GSsApneoVXRHEfI3/9vFfDrg3dld7u4bhBitEtF s5mYIy+VMD4C5gz5f3td75cT5o9Vpo/Z8q/FFgsvGn6+ADDYu09jMx8E3y3DBF5uAPClw fG4sQBu4a6YIMbKm1l3n2ePTMmOoT2XCJlFdeXZiZviwAoQE/v31N2jNOoLZdg/BZuw== ARC-Authentication-Results: i=1; smtp1.osuosl.org; dmarc=none header.from=makrotopia.org; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=u-boot-bounces@lists.u-boot-project.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.u-boot-project.org; s=default; t=1795917847; bh=fmDzgThM61JoAw46JvJtVQC54WQye7C9Qk+CJvD2OGE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vOeexLWqJMUgbtEHO+65NyMe7J36oLUNecnrk2+jf0Ofmw8RolNmmJiI1Wuo5HeMF 94QoZ0Xld3gm8VTm4kbZf3U/3xitkDNFzsU9XzZI4fx+FDHezgj6e6g7Jg2vyThLLB MRf5T2E6pK9MOAj2GLCjudP5j3KXrqeijrEPRgKvtt+SJufgtjRvrQnugUUjYNKVkG ekiIAeOWprmRw9clJxg6UWtbrbPu3nBC+hmKxJ+Phvbcny98lU5CNmbBYhcOzHsgf7 xYiJznikh6s8wU39L4XtZJCUil7t21tzZEOxy9BEyjozqVX7+j4oI99Q3s6V4PVrUk 2vQDO1TjygX3A== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp1.osuosl.org (Postfix) with ESMTP id 88E6180A9B; Sun, 29 Nov 2026 02:04:07 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists1.osuosl.org (Postfix) with ESMTP id 5F81743 for ; Sun, 29 Nov 2026 02:04:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 5CBBA80A9B for ; Sun, 29 Nov 2026 02:04:06 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id VPwFBRDrILPS for ; Sun, 29 Nov 2026 02:04:05 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp1.osuosl.org 02B9280944 Authentication-Results: smtp1.osuosl.org; arc=none smtp.remote-ip="2a07:2ec0:3002::65" Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a07:2ec0:3002::65; helo=pidgin.makrotopia.org; envelope-from=daniel@makrotopia.org; receiver= Authentication-Results: smtp1.osuosl.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [IPv6:2a07:2ec0:3002::65]) by smtp1.osuosl.org (Postfix) with ESMTPS id 02B9280944 for ; Sun, 29 Nov 2026 02:04:04 +0000 (UTC) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256:X25519MLKEM768) (Exim 4.100.1) (envelope-from ) id 1xXUGn-0000000066B-3acs; Sun, 29 Nov 2026 02:04:01 +0000 Date: Sun, 29 Nov 2026 02:03:55 +0000 From: Daniel Golle To: Aristo Chen Cc: u-boot@lists.u-boot-project.org, Tom Rini Subject: Re: [PATCH v2 1/2] boot: fit: bound the external data size on the imagemap storage path Message-ID: References: <20261115143134.25791-1-aristo.chen@canonical.com> <20261120131113.1044702-1-aristo.chen@canonical.com> <20261120131113.1044702-2-aristo.chen@canonical.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261120131113.1044702-2-aristo.chen@canonical.com> X-BeenThere: u-boot@lists.u-boot-project.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: U-Boot discussion List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-8.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Fri, Nov 20, 2026 at 01:11:07PM +0000, Aristo Chen wrote: > fit_image_load_storage() loads an external-data sub-image by reading it > from the storage device with a transfer sized from the FIT data-size > property. That property is listed in exc_prop[] in boot/image-fit-sig.c, > so it is excluded from the configuration signature and stays under the > control of anyone able to modify the boot medium even when FIT_SIGNATURE > is enabled. The read happens before fit_image_select() checks the image > hash, and for an uncompressed image with a load address it goes straight > to that address, so an inflated data-size overruns the destination > before the corruption can be detected. > > The other branch is not changed. There imagemap_map() reads into a > buffer that it allocates from LMB at the requested size. Its size > arithmetic can wrap for a data-size close to 4 GiB when ulong or > phys_size_t is 32 bits wide; that needs a fix in imagemap_map() itself > and is not part of this patch. > > Before the direct read, reject an image whose data-size is larger than > the memory that lmb_get_free_size() reports as free at the load address, > and print a message that gives both. Within the limits of that helper, > which are listed below, this keeps the read away from U-Boot itself, > from reserved memory and from the buffers imagemap_map() has allocated. > It does not limit how large an image may be. > > This is partial hardening, not a complete fix. Free memory behind the > real payload can still be written before the hash check rejects the > image, and the destination of a direct read is not reserved in LMB, so > a sub-image that was read directly is not protected from a later one. > > lmb_get_free_size() has three limits that are left as they are: > > - It stops at every used region and returns 0 from inside one. That > includes the LMB_NONE regions that the load commands, tftp, wget, > "sf read" and bootm leave behind, so a valid image is refused when > the load address of a sub-image is still recorded as used after an > earlier load in the same session. tftp and wget stopped using the > helper for that reason, in commit af45c84871e4 ("tftp: rework the > logic to validate the load address") and commit 51ebd514ec78 ("wget: > rework the logic to validate the load address"). > - With more than one RAM bank, the size it returns can run across the > hole to the next bank. > - With a 32-bit phys_addr_t, it does not see a reservation that ends at > 4 GiB from an address inside that reservation. > > Fixes: 46d32e38ee4e ("boot: fit: support on-demand loading in fit_image_load()") > Addresses-Coverity-ID: CID 661899: Insecure data handling (TAINTED_SCALAR) > Suggested-by: Daniel Golle > Signed-off-by: Aristo Chen > --- > v2: bound only the direct read, by the free memory that LMB reports at > the load address, as suggested by Daniel. The CONFIG_SYS_BOOTM_LEN > ceiling and the Kconfig change are gone. Commit message rewritten; it > now lists the limits of lmb_get_free_size(). Reviewed-by: Daniel Golle