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 CF0A2C43334 for ; Tue, 28 Jun 2022 22:54:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 920EF84478; Wed, 29 Jun 2022 00:54:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="srKlMrq0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A896B8444B; Wed, 29 Jun 2022 00:54:42 +0200 (CEST) Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0197184417 for ; Wed, 29 Jun 2022 00:54:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-qv1-xf2e.google.com with SMTP id q4so22266535qvq.8 for ; Tue, 28 Jun 2022 15:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+lV7ST6dTP8n1HM5Dd/laK+VhuLYJVYE7nm6sS2jK6M=; b=srKlMrq0UDr+PGGyKjrpGY6/kl4aqUIqD2i5QwAltsAv4XNXpOEwJ0vjKcITcmM1qf Q0knHlzpRkPAfufpWaPb5M70pb/EzudTjKlS+8UFHxBYE4XHRzx/QRmqx7cMU8y/bOY1 vozY7Q2P8CqYvivAlFzbYS5yUcMvsh3T3FPB4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+lV7ST6dTP8n1HM5Dd/laK+VhuLYJVYE7nm6sS2jK6M=; b=isRCveZKpw69SdbloiTiP76OmMfZT5YBqlJI4fYv9uDy0ltuHGxLrSwTVO1uURPQSd LaqKtHaCvZG23P4pn3vDlFV9qX8wvvijbaHZ3mKA4Fhggm3VQ0Q52eY4qfEgU4ZaTzjZ k//0UAW7cmWawsX+raWWciraPITOyvGcekQtNsymBZ8d92S1mJRx34Kx8Vu8BuKDePHH Ucb7fFB33r0MJ11WadFfnY0DT8Mwg4Oxptwe82WzuQ3/XrQegbDEW6wmj6DCAdb2m5JR 4BQCtefuvMcWLxm1k+5WPUkWvugutXBwywQXsj1mQaE+xWaz5Yx+d2wnX+26gfJtlE7D g2ww== X-Gm-Message-State: AJIora9f00mYjkb1zSCdK6/+HoCEmpnFEAytSDumRlXqjni2kYHMpLc4 DQ2XNE97ckBK+Ii54oqlYCdlC+Eg9g9vsw== X-Google-Smtp-Source: AGRyM1szSobi28qkJW37x7J4TqUfO6kuXEYCyp465WQfdGE9V37Y6JRnVYcvbm6TXZ69W3T/zAJhHw== X-Received: by 2002:a05:6214:242e:b0:472:7475:e1f3 with SMTP id gy14-20020a056214242e00b004727475e1f3mr4441813qvb.73.1656456877668; Tue, 28 Jun 2022 15:54:37 -0700 (PDT) Received: from bill-the-cat (cpe-65-184-195-139.ec.res.rr.com. [65.184.195.139]) by smtp.gmail.com with ESMTPSA id j12-20020ac874cc000000b00304e29c9a6asm9363877qtr.91.2022.06.28.15.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 15:54:36 -0700 (PDT) Date: Tue, 28 Jun 2022 18:54:34 -0400 From: Tom Rini To: Miquel Raynal Cc: u-boot@lists.denx.de, Thomas Petazzoni , Tatsuhiko Yasumatsu Subject: Re: [PATCH v2] fs/squashfs: Use kcalloc when relevant Message-ID: <20220628225434.GZ1146598@bill-the-cat> References: <20220627102003.21269-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sF6X0tUrUrSWNIfp" Content-Disposition: inline In-Reply-To: <20220627102003.21269-1-miquel.raynal@bootlin.com> X-Clacks-Overhead: GNU Terry Pratchett 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 --sF6X0tUrUrSWNIfp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 27, 2022 at 12:20:03PM +0200, Miquel Raynal wrote: > A crafted squashfs image could embed a huge number of empty metadata > blocks in order to make the amount of malloc()'d memory overflow and be > much smaller than expected. Because of this flaw, any random code > positioned at the right location in the squashfs image could be memcpy'd > from the squashfs structures into U-Boot code location while trying to > access the rearmost blocks, before being executed. >=20 > In order to prevent this vulnerability from being exploited in eg. a > secure boot environment, let's add a check over the amount of data > that is going to be allocated. Such a check could look like: >=20 > if (!elem_size || n > SIZE_MAX / elem_size) > return NULL; >=20 > The right way to do it would be to enhance the calloc() implementation > but this is quite an impacting change for such a small fix. Another > solution would be to add the check before the malloc call in the > squashfs implementation, but this does not look right. So for now, let's > use the kcalloc() compatibility function from Linux, which has this > check. >=20 > Fixes: c5100613037 ("fs/squashfs: new filesystem") > Reported-by: Tatsuhiko Yasumatsu > Signed-off-by: Miquel Raynal > Tested-by: Tatsuhiko Yasumatsu Applied to u-boot/master, thanks! --=20 Tom --sF6X0tUrUrSWNIfp Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmK7hqoACgkQFHw5/5Y0 tyz5cAv7BL3udp6WeoaX36tOZynieCpYkp4dcxhj4w3vyd9JpqbiURRKnLNL+aNT Ga0oVQ65Ju1nkzhL0snB1je5Z6y6XXsFhxDrOzxn2dJipuwjPLNiQR47pYaFuCXP stuUaO0po1ZpOazl79Tb7/+kQYntG1I7AbOvKnVhSFjrdDemRkuTKEVXqk1zOOOD Gwo9OjvWmYV2vyT7jFtRZ5y77sw+hsTFwiKeMFeDP8CfVan4K+yIElESdJFrUYNB 2UQ9mFQ/74iIMYL5lzS8X34WNYTFu3KQspJ7s23MhdTFNh5rOARdF+Yr98clXpmp FwyBqzZbbStlq+kky97tCfyIaBihIavcgd+4nikv0KPrXEdtkQjHbSS6I+gGZYhN 1H5w9TO8K+ess3lnbSQISUC81cuq8MLtyrOzpoY+gHpBirbWVL8RMT/3rWBubn6V Vo2ekeuLqg/5MipCPAMvDX2hnlVJcXqLBhb+DLgFf1QIXy/Kwne+pL/jU9ewMsX6 9oMKoS+r =h1Pj -----END PGP SIGNATURE----- --sF6X0tUrUrSWNIfp--