[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH initramfs-tools 1/3] Add more sanity checks on root device name in dep_add_modules



Check that readlink succeeds and that the block device exists,
after eliminating the ubifs case.

Related-to: #760127
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 hook-functions | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/hook-functions b/hook-functions
index 1afb767..dbe8cd2 100644
--- a/hook-functions
+++ b/hook-functions
@@ -254,17 +254,6 @@ dep_add_modules()
 			&& break; done < /proc/mounts)"
 	fi
 
-	# recheck root device
-	if [ -z "$root" ]; then
-		echo "mkinitramfs: failed to determine root device" >&2
-		echo "mkinitramfs: workaround is MODULES=most, check:" >&2
-		echo "grep -r MODULES /etc/initramfs-tools/" >&2
-		echo "" >&2
-		echo "Error please report bug on initramfs-tools" >&2
-		echo "Include the output of 'mount' and 'cat /proc/mounts'" >&2
-		exit 1
-	fi
-
 	# handle ubifs and return since ubifs root is a char device but
 	# most of the commands below only work with block devices.
 	if [ "${FSTYPE}" = "ubifs" ]; then
@@ -275,7 +264,17 @@ dep_add_modules()
 	if [ "${root}" = "/dev/root" ] ; then
 		root="/dev/disk/by-uuid/"$(blkid -o value -s UUID ${root}) 2>/dev/null
 	fi
-	root="$(readlink -f ${root})"
+
+	# recheck root device
+	if [ -z "$root" ] || ! root="$(readlink -f ${root})" || ! [ -b "$root" ]; then
+		echo "mkinitramfs: failed to determine root device" >&2
+		echo "mkinitramfs: workaround is MODULES=most, check:" >&2
+		echo "grep -r MODULES /etc/initramfs-tools/" >&2
+		echo "" >&2
+		echo "Error please report bug on initramfs-tools" >&2
+		echo "Include the output of 'mount' and 'cat /proc/mounts'" >&2
+		exit 1
+	fi
 
 	# do not trust mount, check superblock
 	eval "$(/usr/lib/klibc/bin/fstype ${root})"


-- 
Ben Hutchings
This sentence contradicts itself - no actually it doesn't.

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: