linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mke2fs: fix up check for hardlinks always false if inode > 0xFFFFFFFF
@ 2020-07-22  1:25 Hongxu Jia
  2020-10-01 16:53 ` Theodore Y. Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Hongxu Jia @ 2020-07-22  1:25 UTC (permalink / raw)
  To: tytso, linux-ext4, wshilong, adilger

While file has a large inode number (> 0xFFFFFFFF), mkfs.ext4 could
not parse hardlink correctly.

Prepare three hardlink files for mkfs.ext4

$ ls -il rootfs_ota/a rootfs_ota/boot/b rootfs_ota/boot/c
11026675846 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 rootfs_ota/a
11026675846 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 rootfs_ota/boot/b
11026675846 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 rootfs_ota/boot/c

$ truncate -s 1M rootfs_ota.ext4

$ mkfs.ext4 -F -i 8192 rootfs_ota.ext4 -L otaroot -U fd5f8768-c779-4dc9-adde-165a3d863349 -d rootfs_ota

$ mkdir mnt && sudo mount rootfs_ota.ext4 mnt

$ ls -il mnt/a mnt/boot/b mnt/boot/c
12 -rw-r--r-- 1 hjia users 0 Jul 20 17:44 mnt/a
14 -rw-r--r-- 1 hjia users 0 Jul 20 17:44 mnt/boot/b
15 -rw-r--r-- 1 hjia users 0 Jul 20 17:44 mnt/boot/c

After applying this fix
$ ls -il mnt/a mnt/boot/b mnt/boot/c
12 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 mnt/a
12 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 mnt/boot/b
12 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 mnt/boot/c

Since commit [382ed4a1 e2fsck: use proper types for variables][1]
applied, it used ext2_ino_t instead of ino_t for referencing inode
numbers, but the type of is_hardlink's `ino' should not be instead,
The ext2_ino_t is 32bit, if inode > 0xFFFFFFFF, its value will be
truncated.

Add a debug printf to show the value of inode, when it check for hardlink
files, it will always return false if inode > 0xFFFFFFFF
|--- a/misc/create_inode.c
|+++ b/misc/create_inode.c
|@@ -605,6 +605,7 @@ static int is_hardlink(struct hdlinks_s *hdlinks, dev_t dev, ext2_ino_t ino)
| {
|        int i;
|
|+       printf("%s %d, %lX, %lX\n", __FUNCTION__, __LINE__, hdlinks->hdl[i].src_ino, ino);
|        for (i = 0; i < hdlinks->count; i++) {
|                if (hdlinks->hdl[i].src_dev == dev &&
|                    hdlinks->hdl[i].src_ino == ino)

Here is debug message:
is_hardlink 608, 2913DB886, 913DB886

The length of ext2_ino_t is 32bit (typedef __u32 __bitwise ext2_ino_t;),
and ino_t is 64bit on 64bit system (such as x86-64), recover `ino' to ino_t.

[1] https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/?id=382ed4a1c2b60acb9db7631e86dda207bde6076e

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 misc/create_inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/misc/create_inode.c b/misc/create_inode.c
index e8d1df6b..837f3875 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -601,7 +601,7 @@ out:
 	return err;
 }
 
-static int is_hardlink(struct hdlinks_s *hdlinks, dev_t dev, ext2_ino_t ino)
+static int is_hardlink(struct hdlinks_s *hdlinks, dev_t dev, ino_t ino)
 {
 	int i;
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mke2fs: fix up check for hardlinks always false if inode > 0xFFFFFFFF
  2020-07-22  1:25 [PATCH] mke2fs: fix up check for hardlinks always false if inode > 0xFFFFFFFF Hongxu Jia
@ 2020-10-01 16:53 ` Theodore Y. Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Y. Ts'o @ 2020-10-01 16:53 UTC (permalink / raw)
  To: Hongxu Jia; +Cc: linux-ext4, wshilong, adilger

On Tue, Jul 21, 2020 at 06:25:03PM -0700, Hongxu Jia wrote:
> While file has a large inode number (> 0xFFFFFFFF), mkfs.ext4 could
> not parse hardlink correctly.
> 
> Prepare three hardlink files for mkfs.ext4
> 
> $ ls -il rootfs_ota/a rootfs_ota/boot/b rootfs_ota/boot/c
> 11026675846 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 rootfs_ota/a
> 11026675846 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 rootfs_ota/boot/b
> 11026675846 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 rootfs_ota/boot/c
> 
> $ truncate -s 1M rootfs_ota.ext4
> 
> $ mkfs.ext4 -F -i 8192 rootfs_ota.ext4 -L otaroot -U fd5f8768-c779-4dc9-adde-165a3d863349 -d rootfs_ota
> 
> $ mkdir mnt && sudo mount rootfs_ota.ext4 mnt
> 
> $ ls -il mnt/a mnt/boot/b mnt/boot/c
> 12 -rw-r--r-- 1 hjia users 0 Jul 20 17:44 mnt/a
> 14 -rw-r--r-- 1 hjia users 0 Jul 20 17:44 mnt/boot/b
> 15 -rw-r--r-- 1 hjia users 0 Jul 20 17:44 mnt/boot/c
> 
> After applying this fix
> $ ls -il mnt/a mnt/boot/b mnt/boot/c
> 12 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 mnt/a
> 12 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 mnt/boot/b
> 12 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 mnt/boot/c
> 
> Since commit [382ed4a1 e2fsck: use proper types for variables][1]
> applied, it used ext2_ino_t instead of ino_t for referencing inode
> numbers, but the type of is_hardlink's `ino' should not be instead,
> The ext2_ino_t is 32bit, if inode > 0xFFFFFFFF, its value will be
> truncated.
> 
> Add a debug printf to show the value of inode, when it check for hardlink
> files, it will always return false if inode > 0xFFFFFFFF
> |--- a/misc/create_inode.c
> |+++ b/misc/create_inode.c
> |@@ -605,6 +605,7 @@ static int is_hardlink(struct hdlinks_s *hdlinks, dev_t dev, ext2_ino_t ino)
> | {
> |        int i;
> |
> |+       printf("%s %d, %lX, %lX\n", __FUNCTION__, __LINE__, hdlinks->hdl[i].src_ino, ino);
> |        for (i = 0; i < hdlinks->count; i++) {
> |                if (hdlinks->hdl[i].src_dev == dev &&
> |                    hdlinks->hdl[i].src_ino == ino)
> 
> Here is debug message:
> is_hardlink 608, 2913DB886, 913DB886
> 
> The length of ext2_ino_t is 32bit (typedef __u32 __bitwise ext2_ino_t;),
> and ino_t is 64bit on 64bit system (such as x86-64), recover `ino' to ino_t.
> 
> [1] https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/?id=382ed4a1c2b60acb9db7631e86dda207bde6076e
> 
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>

Applied, thanks.

						- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-01 16:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22  1:25 [PATCH] mke2fs: fix up check for hardlinks always false if inode > 0xFFFFFFFF Hongxu Jia
2020-10-01 16:53 ` Theodore Y. Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).