View Issue Details

IDProjectCategoryView StatusLast Update
0000232file[All Projects] Generalpublic2021-02-05 21:58
ReporterratschanceAssigned Tochristos 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version5.39 
Target VersionFixed in Version5.40 
Summary0000232: Devicetrees with a structure section larger than 1MB are not correctly identified
DescriptionThe current implementation for the detection of Linux devicetree files does two checks to see whether the structure and strings sections are within the device tree blob. It seems like `file` only reads 1MB of the devicetree into its in memory buf, and so when the structure section is larger than 1MB, the check for the strings section becomes an out of bounds index into that buf and results in the devicetree not being identified. I have attached a patch of a potential fix.
Steps To ReproduceThis becomes easy to reproduce when using U-Boot's Flattened Image Tree (FIT) format, which uses the device tree compiler to build a device tree blob containing boot images (kernel, rootfs, DTBs) and configurations. More info: https://gitlab.denx.de/u-boot/u-boot/-/blob/master/doc/uImage.FIT/source_file_format.txt

The following uses the `mkimage` command from the u-boot-tools package on Ubuntu:

# dd if=/dev/zero of=test-900K.bin bs=900K count=1
# mkimage -f auto -A arm -O linux -T ramdisk -C none -e 0 -d test-900K.bin 900k.itb
# file 900k.itb
900k.itb: Device Tree Blob version 17, size=923172, boot CPU=0, string block size=102, DT structure block size=922016

# dd if=/dev/zero of=test-1M.bin bs=1M count=1
# mkimage -f auto -A arm -O linux -T ramdisk -C none -e 0 -d test-1M.bin 1m.itb
# file 1m.itb
1m.itb: data


Expected output:
1m.itb: Device Tree Blob version 17, size=1050148, boot CPU=0, string block size=102, DT structure block size=1048992
Tagsmagic

Activities

ratschance

2021-01-27 23:38

reporter  

devicetree_1m_support.patch (1,054 bytes)
diff --git a/magic/Magdir/linux b/magic/Magdir/linux
index 3086191e..6a5d3d35 100644
--- a/magic/Magdir/linux
+++ b/magic/Magdir/linux
@@ -438,17 +438,16 @@
 # Documentation/devicetree/booting-without-of.txt
 # From Christoph Biedl
 0		belong		0xd00dfeed
-# structure and strings must be within blob
+# structure must be within blob, strings are omitted to handle devicetrees > 1M
 >&(8.L)		byte		x
->>&(12.L)	byte		x
->>>20		belong		>1	Device Tree Blob version %d
->>>>4		belong		x	\b, size=%d
->>>>20		belong		>1
->>>>>28		belong		x	\b, boot CPU=%d
->>>>20		belong		>2
->>>>>32		belong		x	\b, string block size=%d
->>>>20		belong		>16
->>>>>36		belong		x	\b, DT structure block size=%d
+>>20		belong		>1	Device Tree Blob version %d
+>>>4		belong		x	\b, size=%d
+>>>20		belong		>1
+>>>>28		belong		x	\b, boot CPU=%d
+>>>20		belong		>2
+>>>>32		belong		x	\b, string block size=%d
+>>>20		belong		>16
+>>>>36		belong		x	\b, DT structure block size=%d
 
 # glibc locale archive as defined in glibc locale/locarchive.h
 0		lelong		0xde020109	locale archive

christos

2021-02-05 21:58

manager   ~0003536

Applied, thanks!

Issue History

Date Modified Username Field Change
2021-01-27 23:38 ratschance New Issue
2021-01-27 23:38 ratschance File Added: devicetree_1m_support.patch
2021-01-27 23:38 ratschance Tag Attached: magic
2021-02-05 21:58 christos Assigned To => christos
2021-02-05 21:58 christos Status new => assigned
2021-02-05 21:58 christos Status assigned => resolved
2021-02-05 21:58 christos Resolution open => fixed
2021-02-05 21:58 christos Fixed in Version => 5.40
2021-02-05 21:58 christos Note Added: 0003536