]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: nilfs: fix byte order and block size validation
authorKarel Zak <kzak@redhat.com>
Wed, 15 Apr 2026 13:53:56 +0000 (15:53 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Apr 2026 12:07:45 +0000 (14:07 +0200)
Fix s_dev_size comparison to use le64_to_cpu() for big-endian
architectures. Tighten s_log_block_size check to match kernel limit
(NILFS_MAX_BLOCK_SIZE=65536, max shift 6).

Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/superblocks/nilfs.c

index 0226da5ab458e15a8b4986f9752494dea90bcbb7..f023721ea0e7da89afab5feea12ce9c0c4f7a889 100644 (file)
@@ -79,7 +79,7 @@ static int nilfs_valid_sb(blkid_probe pr, struct nilfs_super_block *sb, int is_b
                return 0;
 
        if (is_bak && blkid_probe_is_wholedisk(pr) &&
-           sb->s_dev_size != pr->size)
+           le64_to_cpu(sb->s_dev_size) != (uint64_t) pr->size)
                return 0;
 
        bytes = le16_to_cpu(sb->s_bytes);
@@ -157,7 +157,9 @@ static int probe_nilfs2(blkid_probe pr,
                                (unsigned char *) &sb->s_magic))
                return 1;
 
-       if (le32_to_cpu(sb->s_log_block_size) < 32){
+       /* kernel limits s_log_block_size to ilog2(NILFS_MAX_BLOCK_SIZE=65536) - 10 = 6,
+        * values above 6 would overflow 1024U << shift */
+       if (le32_to_cpu(sb->s_log_block_size) <= 6){
                blkid_probe_set_fsblocksize(pr, 1024U << le32_to_cpu(sb->s_log_block_size));
                blkid_probe_set_block_size(pr, 1024U << le32_to_cpu(sb->s_log_block_size));
        }