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 25963C3DA4A for ; Fri, 2 Aug 2024 16:37:13 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2999488BE4; Fri, 2 Aug 2024 18:37:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 8505688BC8; Fri, 2 Aug 2024 18:37:02 +0200 (CEST) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) (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 AED4A88BCE for ; Fri, 2 Aug 2024 18:37:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=richard@nod.at Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 30E4464C3B35; Fri, 2 Aug 2024 18:37:00 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id D_SCjiVv6qdu; Fri, 2 Aug 2024 18:36:59 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id D02E364C3B29; Fri, 2 Aug 2024 18:36:59 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ofK6d-nM2YNT; Fri, 2 Aug 2024 18:36:59 +0200 (CEST) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 9048564C3B26; Fri, 2 Aug 2024 18:36:59 +0200 (CEST) From: Richard Weinberger To: u-boot@lists.denx.de Cc: upstream+uboot@sigma-star.at, trini@konsulko.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, jmcosta944@gmail.com, Richard Weinberger Subject: [PATCH v2 2/4] squashfs: Fix integer overflow in sqfs_inode_size() Date: Fri, 2 Aug 2024 18:36:45 +0200 Message-Id: <20240802163647.26674-2-richard@nod.at> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240802163647.26674-1-richard@nod.at> References: <20240802163647.26674-1-richard@nod.at> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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.8 at phobos.denx.de X-Virus-Status: Clean A carefully crafted squashfs filesystem can exhibit an extremly large inode size and overflow the calculation in sqfs_inode_size(). As a consequence, the squashfs driver will read from wrong locations. Fix by using __builtin_add_overflow() to detect the overflow. Signed-off-by: Richard Weinberger Reviewed-by: Miquel Raynal --- fs/squashfs/sqfs_inode.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/squashfs/sqfs_inode.c b/fs/squashfs/sqfs_inode.c index d25cfb53e7..bb3ccd37e3 100644 --- a/fs/squashfs/sqfs_inode.c +++ b/fs/squashfs/sqfs_inode.c @@ -78,11 +78,16 @@ int sqfs_inode_size(struct squashfs_base_inode *inode= , u32 blk_size) =20 case SQFS_SYMLINK_TYPE: case SQFS_LSYMLINK_TYPE: { + int size; + struct squashfs_symlink_inode *symlink =3D (struct squashfs_symlink_inode *)inode; =20 - return sizeof(*symlink) + - get_unaligned_le32(&symlink->symlink_size); + if (__builtin_add_overflow(sizeof(*symlink), + get_unaligned_le32(&symlink->symlink_size), &size)) + return -EINVAL; + + return size; } =20 case SQFS_BLKDEV_TYPE: --=20 2.35.3