[OpenWrt-Devel] libblkid-tiny: bugged buffer management

Rafał Miłecki zajec5 at gmail.com
Mon Aug 26 11:33:34 EDT 2019

I noticed a bug in "block" tool behavior. It was providing inconsistent
UUIDs for my disks with NTFS partitions.

Please check UUID of /dev/sda1 in following examples:

root at OpenWrt:/# block info
/dev/mtdblock4: UUID="8463a403-99b3cf92-d2b7996f-c4ede4f4" VERSION="4.0" MOUNT="/rom" TYPE="squashfs"
/dev/mtdblock5: MOUNT="/overlay" TYPE="jffs2"
/dev/sda1: UUID="6AA9873636CA5409" TYPE="ntfs"
/dev/sda2: UUID="0000001800000030" TYPE="ntfs"
/dev/sdb1: UUID="0000001800000030" TYPE="ntfs"

root at OpenWrt:/# block detect
config 'global'
        option  anon_swap       '0'
        option  anon_mount      '0'
        option  auto_swap       '1'
        option  auto_mount      '1'
        option  delay_root      '5'
        option  check_fs        '0'

config 'mount'
        option  target  '/mnt/sda1'
        option  uuid    '0000001800000030'
        option  enabled '0'

config 'mount'
        option  target  '/mnt/sda2'
        option  uuid    '0000001800000030'
        option  enabled '0'

config 'mount'
        option  target  '/mnt/sdb1'
        option  uuid    '0000001800000030'
        option  enabled '0'

That bug was exposed by cache_load(0) vs. cache_load(1). Those calls
result in different order of buffer allocation in the

This problem is caused by:
1) blkid_probe_get_buffer() resuing buffer when possible
2) __probe_ntfs() reading multiple blocks

As you can probably guess any subsequent block ready can overwrite a
content of previously returned block content buffer. In __probe_ntfs()
case it's something like:

ns = blkid_probe_get_sb(...);
buf_mft = blkid_probe_get_buffer(...);
buf_mft = blkid_probe_get_buffer(...);

If you take a look at blkid_probe_get_buffer() in the original project
(util-linux's libblkid) it's a bit more complicated:

Any idea/hint how to resolve it in some simple way?


openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list