From patchwork Fri Apr 30 04:45:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Campbell Suter X-Patchwork-Id: 1472115 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=snapit.group header.i=@snapit.group header.a=rsa-sha256 header.s=shd header.b=gEOTUUZl; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FWq5l6Wx9z9sCD for ; Fri, 30 Apr 2021 20:55:23 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AE50282A9B; Fri, 30 Apr 2021 12:55:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=snapit.group 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=snapit.group header.i=@snapit.group header.b="gEOTUUZl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E62BC82A98; Fri, 30 Apr 2021 06:45:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) (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 BBF0182A8B for ; Fri, 30 Apr 2021 06:45:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=snapit.group Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=campbell@snapit.group Received: by mail-pg1-x52a.google.com with SMTP id p12so48628631pgj.10 for ; Thu, 29 Apr 2021 21:45:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=snapit.group; s=shd; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=YbvHDxJXzZpenqifEn827t8tMs+0skgkHJ8+yJx/S4I=; b=gEOTUUZlfSjSxz1+JNeQElnYG4B19+gxtZZw0W53tQaFaQOY8Vvb/ucOfIGN5IOGWl PvCLBPzIV7x1j6D6140v4VCPQYdOaUbGvLIm5jniUVbZaBPhTS9PZbU0mjLRaRJoVN/g 6oIDI2XOsrN691oOw8Pg+wj49vlj0/ZPNPXmg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=YbvHDxJXzZpenqifEn827t8tMs+0skgkHJ8+yJx/S4I=; b=C/dVM4lSAG8G5zr8RJaCBY6EKvSbx7VNUdJVMtlOK2MWMv4B3MqmsKldlgXzMMuOcb l3rYRbIAshFRHt98fCPgvy6Agdi4AP3UcZKKnMkIY3EfFAOmbtC8Ja7JnPk/J09DDSP7 x08crGAXJ4/3si8mW/wGEcEl8WEdtVjJNt7+eQ5TTgCm9aUZDWwsc08t61XTo5Nb5bTi eicRAWRrtaXyo+DTW3bb98LTUdSvUhZa8/iY+tCzGyxl8z5VXW6JM/OUgMk7aZ/5mYgv O8lJOsQBeRUnEsIeYJ/boJIykGANTXGDSxRwSsbGovlsPmxWm4sh5GmxrCNYxqvMVBPk Us1Q== X-Gm-Message-State: AOAM5337XJ0lsg8Fs5SBfMlyq4SmDq+u1Ln5QXXxCDxnyiSfOb+9Dqia ifZ9fIk4siYrWePqg2jyDLJqHhpootX/9g== X-Google-Smtp-Source: ABdhPJxZTFm+0u50pp2h94+4BFrrkL5jNf1JoZ2lCAXM8LAkZgzBwtmA3yyJO2yYnx6JTi9bsVMj2g== X-Received: by 2002:a63:1960:: with SMTP id 32mr1744153pgz.253.1619757951924; Thu, 29 Apr 2021 21:45:51 -0700 (PDT) Received: from ?IPv6:2406:e002:b231:9401:734f:e920:3693:42a8? ([2406:e002:b231:9401:734f:e920:3693:42a8]) by smtp.gmail.com with ESMTPSA id i126sm667960pfc.20.2021.04.29.21.45.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Apr 2021 21:45:51 -0700 (PDT) To: u-boot@lists.denx.de Cc: Joao Marcos Costa , Thomas Petazzoni , Miquel Raynal From: Campbell Suter Subject: [PATCH] fs/squashfs: Fix some hardlinks reading the wrong inode Message-ID: Date: Fri, 30 Apr 2021 16:45:46 +1200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 Content-Language: en-GB X-Mailman-Approved-At: Fri, 30 Apr 2021 12:55:16 +0200 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.102.4 at phobos.denx.de X-Virus-Status: Clean In SquashFS, the contents of a directory is stored by squashfs_directory_entry structures which contain the file's name, inode and position within the filesystem. The inode number is not stored directly; instead each directory has one or more headers which set a base inode number, and files store the offset from that to the file's inode number. In mksquashfs, each inode is allocated a number in the same order as they are written to the directory table; thus the offset from the header's base inode number to the file's inode number is usually positive. Hardlinks are simply stored with two directory entries referencing the same file. This means the second entry will thus have an inode number much lower than the surrounding files. Since the header's base inode number comes from the first entry that uses the header, this delta will usually be negative. Previously, U-Boot's squashfs_directory_entry.inode_offset field was declared as an unsigned value. Thus when a negative value was found, it would either resolve to an invalid inode number or to that of an unrelated file. A squashfs image to test this can be created like so: echo hi > sqfs_test_files/001-root-file mkdir sqfs_test_files/002-subdir touch sqfs_test_files/002-subdir/003-file ln sqfs_test_files/{001-root-file,002-subdir/004-link} mksquashfs sqfs_test_files/ test.sqfs -noappend Note that squashfs sorts the files ASCIIbetacally, so we can use the names to control the order they appear in. The ordering is important - the first reference to the file must have a lower inode number than the directory in which the second reference resides, and the second reference cannot be the first file in the directory. Listing this sample image in U-Boot results in: => sqfsls virtio 2 002-subdir 0 003-file Inode not found. 0 004-link Signed-off-by: Campbell Suter Reviewed-by: Miquel Raynal --- fs/squashfs/sqfs_filesystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/squashfs/sqfs_filesystem.h b/fs/squashfs/sqfs_filesystem.h index 856cd15e349..5440b6c0e05 100644 --- a/fs/squashfs/sqfs_filesystem.h +++ b/fs/squashfs/sqfs_filesystem.h @@ -231,7 +231,7 @@ union squashfs_inode { struct squashfs_directory_entry { u16 offset; - u16 inode_offset; + s16 inode_offset; u16 type; u16 name_size; char name[0];