image: fix race between mkits.sh and mkimage in .itb squashfs generation
authorChristian Marangi <[email protected]>
Wed, 22 Oct 2025 00:17:25 +0000 (02:17 +0200)
committerChristian Marangi <[email protected]>
Thu, 23 Oct 2025 16:14:00 +0000 (18:14 +0200)
With further investigation it was found a race in generating .itb images
that include a RootFS caused by the mkits.sh and the mkimage.

Due to the fact that mkits.sh generates a .pagesync image of the passed
rootfs, it can happen that, concurrently, mkimage can be called at the
same time mkits.sh is creating another .pagesync for the same rootfs.

This cause mkimage to use an half made rootfs.pagesync creating a
corrupted image.

To address this, also protect the mkimage with the same lock used for
mkits.sh preventing any kind of concurrent usage/generation of the
rootfs.pagesync blob

Fixes: 52cc9d82f113 ("kernel: rework Initramfs locking logic")
Link: https://github.com/openwrt/openwrt/pull/20492
Signed-off-by: Christian Marangi <[email protected]>
include/image-commands.mk

index 7b2b346aa6c9afa47a8736a202f138a5996c5238..33c2ef89ad1952a3e377b9b0c4ed49ab10bac3d1 100644 (file)
@@ -450,7 +450,8 @@ define Build/fit
                -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config-1") \
                -A $(LINUX_KARCH) -v $(LINUX_VERSION), gen-cpio$(if $(TARGET_PER_DEVICE_ROOTFS),.$(ROOTFS_ID/$(DEVICE_NAME))))
        $(call locked,PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage $(if $(findstring external,$(word 3,$(1))),\
-               -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f [email protected] [email protected])
+               -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f [email protected] [email protected], \
+         gen-cpio$(if $(TARGET_PER_DEVICE_ROOTFS),.$(ROOTFS_ID/$(DEVICE_NAME))))
        @mv [email protected] $@
 endef