Skip to contentSkip to conversation

grub-fs-tester: Add luks1 and luks2 support

PATCH In review Glenn Washburn 2 participants 2 messages Jun 15, 2022 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 grub-fs-tester: Add luks1 and luks2 support

From: Pierre-Louis Bonicoli <[email protected]>

The logical sector size used by LUKS1 is 512 bytes and LUKS2 uses 512 to 4069 bytes. The deafualt password used is "pass", but can be overridden by setting the PASS environment variable. The device mapper name is set to the name of the temp directory so that its easy to corrolate device mapper name with a particular test run. Also since this name is unique per test run, multiple simultaneous test runs are allowed.

Note that cryptsetup is passing the --disable-locks parameter to allow cryptsetup run successfully when /run/lock/cryptsetup is not accessible. Since the device mapper name is unique per test run, there is no need to worry about locking the device to serialize access.

---
Update from v3:
* Add --force-password so that cryptsetup does not fail with the default password on systems where cryptsetup is built with the password quality checking library. Cryptsetup is not built this way on Debian or Ubuntu systems, but on Fabian's test system, which I presume is a SUSE variant, it is.

This is a heavily modified version of Pierre-Louis's v2 patch. It has been tested with Fabian's v3 and Josselin's v4 series for x86_64-efi. Some notable differences from the previous version:
* Rebase on to master accounting for cleanup() changes
* Allow multple tests runs to run simultaneously
* Allow specifying alternate password with environment variable
* Fixed bug in previous version where LC_ALL=C was being set for echo and not run_it
* Make output on UUID fail consistent with other filesystems
* Allow tests to work with older cryptsetups
* Fixed bug where luks1 tests were actually testing luks2
* Address my review comments

Note: The luks2 test will fail without some form of working grub-probe support for luks2. This patch is independent of the above mentioned patch series, will apply without them just fine, and can be reviewed independently.

Glenn

---
 .gitignore                   |  2 ++
 Makefile.util.def            | 12 ++++++++
 tests/luks1_test.in          | 23 +++++++++++++++
 tests/luks2_test.in          | 23 +++++++++++++++
 tests/util/grub-fs-tester.in | 57 ++++++++++++++++++++++++++++++++++--
 5 files changed, 115 insertions(+), 2 deletions(-)
 create mode 100644 tests/luks1_test.in
 create mode 100644 tests/luks2_test.in
.gitignore +2 -0
index f6a1bd051..4064d3d1e 100644
@@ -230,6 +230,8 @@ widthspec.bin
 /lib/libgcrypt-grub
 /libgrub_a_init.c
 /lzocompress_test
+/luks1_test
+/luks2_test
 /m4/
 /minixfs_test
 /missing
Makefile.util.def +12 -0
index d919c562c..3f1162b76 100644
@@ -1213,6 +1213,18 @@ script = {
   common = tests/syslinux_test.in;
 };
 
+script = {
+  testcase = native;
+  name = luks1_test;
+  common = tests/luks1_test.in;
+};
+
+script = {
+  testcase = native;
+  name = luks2_test;
+  common = tests/luks2_test.in;
+};
+
 program = {
   testcase = native;
   name = example_unit_test;
tests/luks1_test.in new file +23 -0
new file mode 100644
index 000000000..cd28fd714
@@ -0,0 +1,23 @@
+#!@BUILD_SHEBANG@
+
+set -e
+
+if [ "x$EUID" = "x" ] ; then
+  EUID=`id -u`
+fi
+
+if [ "$EUID" != 0 ] ; then
+   exit 99
+fi
+
+if ! which mkfs.ext2 >/dev/null 2>&1; then
+   echo "mkfs.ext2 not installed; cannot test luks."
+   exit 99
+fi
+
+if ! which cryptsetup >/dev/null 2>&1; then
+   echo "cryptsetup not installed; cannot test luks."
+   exit 99
+fi
+
+"@builddir@/grub-fs-tester" luks1
tests/luks2_test.in new file +23 -0
new file mode 100644
index 000000000..6a26ba626
@@ -0,0 +1,23 @@
+#!@BUILD_SHEBANG@
+
+set -e
+
+if [ "x$EUID" = "x" ] ; then
+  EUID=`id -u`
+fi
+
+if [ "$EUID" != 0 ] ; then
+   exit 99
+fi
+
+if ! which mkfs.ext2 >/dev/null 2>&1; then
+   echo "mkfs.ext2 not installed; cannot test luks2."
+   exit 99
+fi
+
+if ! which cryptsetup >/dev/null 2>&1; then
+   echo "cryptsetup not installed; cannot test luks2."
+   exit 99
+fi
+
+"@builddir@/grub-fs-tester" luks2
tests/util/grub-fs-tester.in +55 -2

123 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw
Quoted 37 lines · Glenn Washburn

From: Pierre-Louis Bonicoli <[email protected]>

The logical sector size used by LUKS1 is 512 bytes and LUKS2 uses 512 to 4069 bytes. The deafualt password used is "pass", but can be overridden by setting the PASS environment variable. The device mapper name is set to the name of the temp directory so that its easy to corrolate device mapper name with a particular test run. Also since this name is unique per test run, multiple simultaneous test runs are allowed.

Note that cryptsetup is passing the --disable-locks parameter to allow cryptsetup run successfully when /run/lock/cryptsetup is not accessible. Since the device mapper name is unique per test run, there is no need to worry about locking the device to serialize access.

---
Update from v3:
* Add --force-password so that cryptsetup does not fail with the default password on systems where cryptsetup is built with the password quality checking library. Cryptsetup is not built this way on Debian or Ubuntu systems, but on Fabian's test system, which I presume is a SUSE variant, it is.

This is a heavily modified version of Pierre-Louis's v2 patch. It has been tested with Fabian's v3 and Josselin's v4 series for x86_64-efi. Some notable differences from the previous version:
* Rebase on to master accounting for cleanup() changes
* Allow multple tests runs to run simultaneously
* Allow specifying alternate password with environment variable
* Fixed bug in previous version where LC_ALL=C was being set for echo and not run_it
* Make output on UUID fail consistent with other filesystems
* Allow tests to work with older cryptsetups
* Fixed bug where luks1 tests were actually testing luks2
* Address my review comments

Quoted 6 lines

Note: The luks2 test will fail without some form of working grub-probe support for luks2. This patch is independent of the above mentioned patch series, will apply without them just fine, and can be reviewed independently.

Glenn

Thanks for these updates. I ran the luks1_test and luks2_test tests successfully on top of the following patches:
- [PATCH v3] disk/cryptodisk: When cheatmounting, use the sector info of the cheat device
- [PATCH v5 2/2] devmapper/getroot: Set up cheated LUKS2 cryptodisk mount from DM parameters

Signature · 1 line
Pierre-Louis Bonicoli