diff mbox series

[meta-security] dmverity: Check the root device before sleeping

Message ID 20261128210746.461103-1-esa.jaaskela@suomi24.fi
State New
Headers show
Series [meta-security] dmverity: Check the root device before sleeping | expand

Commit Message

Esa Jaaskela Nov. 28, 2026, 9:07 p.m. UTC
The loop that waits for the root device resolves root= and then sleeps
for rootdelay seconds before it checks the result. Before the loop,
only a PARTUUID= root is resolved, so with any other form of root= the
boot always waits rootdelay seconds (1 by default), even when the
device already exists.

Move resolving root= into dmverity_root_device(), and call it before
the loop and after each sleep, so that the boot waits only while the
root device does not exist.

Signed-off-by: Esa Jaaskela <esa.jaaskela@suomi24.fi>
---
 .../initramfs-framework-dm/dmverity           | 51 ++++++++++---------
 1 file changed, 27 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/recipes-core/initrdscripts/initramfs-framework-dm/dmverity b/recipes-core/initrdscripts/initramfs-framework-dm/dmverity
index 1923490..4b29af4 100644
--- a/recipes-core/initrdscripts/initramfs-framework-dm/dmverity
+++ b/recipes-core/initrdscripts/initramfs-framework-dm/dmverity
@@ -4,6 +4,31 @@  dmverity_enabled() {
     return 0
 }
 
+dmverity_root_device() {
+    case "${bootparam_root}" in
+        ID=*)
+            realpath /dev/disk/by-id/${bootparam_root#ID=} 2>/dev/null
+            ;;
+        LABEL=*)
+            realpath /dev/disk/by-label/${bootparam_root#LABEL=} 2>/dev/null
+            ;;
+        PARTLABEL=*)
+            realpath /dev/disk/by-partlabel/${bootparam_root#PARTLABEL=} 2>/dev/null
+            ;;
+        PARTUUID=*)
+            realpath /dev/disk/by-partuuid/${bootparam_root#PARTUUID=} 2>/dev/null
+            ;;
+        PATH=*)
+            realpath /dev/disk/by-path/${bootparam_root#PATH=} 2>/dev/null
+            ;;
+        UUID=*)
+            realpath /dev/disk/by-uuid/${bootparam_root#UUID=} 2>/dev/null
+            ;;
+        *)
+            echo "${bootparam_root}"
+    esac
+}
+
 dmverity_run() {
     DATA_SIZE="__not_set__"
     DATA_BLOCK_SIZE="__not_set__"
@@ -43,39 +68,17 @@  dmverity_run() {
 	    return
     fi
 
-    RDEV="$(realpath /dev/disk/by-partuuid/${bootparam_root#PARTUUID=} 2>/dev/null)"
+    RDEV="$(dmverity_root_device)"
     while [ ! -b "${RDEV}" ]; do
         if [ $(( $C * $delay )) -gt $timeout ]; then
             fatal "Root device resolution failed"
             exit 1
         fi
 
-        case "${bootparam_root}" in
-            ID=*)
-                RDEV="$(realpath /dev/disk/by-id/${bootparam_root#ID=} 2>/dev/null)"
-                ;;
-            LABEL=*)
-                RDEV="$(realpath /dev/disk/by-label/${bootparam_root#LABEL=} 2>/dev/null)"
-                ;;
-            PARTLABEL=*)
-                RDEV="$(realpath /dev/disk/by-partlabel/${bootparam_root#PARTLABEL=} 2>/dev/null)"
-                ;;
-            PARTUUID=*)
-                RDEV="$(realpath /dev/disk/by-partuuid/${bootparam_root#PARTUUID=} 2>/dev/null)"
-                ;;
-            PATH=*)
-                RDEV="$(realpath /dev/disk/by-path/${bootparam_root#PATH=} 2>/dev/null)"
-                ;;
-            UUID=*)
-                RDEV="$(realpath /dev/disk/by-uuid/${bootparam_root#UUID=} 2>/dev/null)"
-                ;;
-            *)
-                RDEV="${bootparam_root}"
-        esac
         debug "Sleeping for $delay second(s) to wait root to settle..."
         sleep $delay
         C=$(( $C + 1 ))
-
+        RDEV="$(dmverity_root_device)"
     done
 
     veritysetup \