latchset / luksmeta

GNU Lesser General Public License v2.1
26 stars 8 forks source link

Assertion "test_layout" failing with recent versions of cryptsetup #6

Closed diabonas closed 5 years ago

diabonas commented 5 years ago

When trying to build LUKSMeta with cryptsetup 2.0.5 or 2.0.6 on Arch Linux, the compilation works fine, but the test suite fails with errors of the form

Assertion `test_layout((range_t[]) { ... })' failed.
Click to see the full test-suite.log ``` ================================== luksmeta 9: ./test-suite.log ================================== # TOTAL: 7 # PASS: 2 # SKIP: 0 # XFAIL: 0 # FAIL: 5 # XPASS: 0 # ERROR: 0 .. contents:: :depth: 2 FAIL: test-lm-assumptions ========================= 00000000:00001024 (!= 0) 00001024:04194304 (== 0) unexpected nonzero: 3072 lt-test-lm-assumptions: test-lm-assumptions.c:32: main: Assertion `test_layout((range_t[]) { { 0, 1024 }, END(1024), })' failed. FAIL test-lm-assumptions (exit status: 134) FAIL: test-lm-init ================== 00000000:00001024 (!= 0) 00001024:01052672 (== 0) unexpected nonzero: 3072 lt-test-lm-init: test-lm-init.c:63: main: Assertion `test_layout((range_t[]) { { 0, 1024 }, { 1024, offset - 1024, true }, { offset, 4096 }, END(offset + 4096), })' failed. FAIL test-lm-init (exit status: 134) FAIL: test-lm-one ================= 00000000:00001024 (!= 0) 00001024:01052672 (== 0) unexpected nonzero: 3072 lt-test-lm-one: test-lm-one.c:56: main: Assertion `test_layout((range_t[]) { { 0, 1024 }, { 1024, offset - 1024, true }, { offset, 4096 }, { offset + 4096, 4096 }, END(offset + 8192), })' failed. FAIL test-lm-one (exit status: 134) FAIL: test-lm-two ================= 00000000:00001024 (!= 0) 00001024:01052672 (== 0) unexpected nonzero: 3072 lt-test-lm-two: test-lm-two.c:60: main: Assertion `test_layout((range_t[]) { { 0, 1024 }, { 1024, offset - 1024, true }, { offset, 4096 }, { offset + 4096, 4096 }, END(offset + 8192), })' failed. FAIL test-lm-two (exit status: 134) FAIL: test-lm-big ================= 00000000:00001024 (!= 0) 00001024:01052672 (== 0) unexpected nonzero: 3072 lt-test-lm-big: test-lm-big.c:119: main: Assertion `test_layout((range_t[]) { { 0, 1024 }, { 1024, offset - 1024, true }, { offset, 4096 }, { offset + 4096, 4096 }, { offset + 8192, 4096 }, END(offset + 12288), })' failed. FAIL test-lm-big (exit status: 134) ```

  Downgrading to crypsetup 2.0.4 solves the problem, so the change seems to have been introduced somewhere between version 2.0.4 and 2.0.5. I did not dig deeper, but the upstream commit c2bce3e9 (Wipe full header areas (including unused) during LUKS format.) looks promising.

dkopecek commented 5 years ago

@diabonas Oh thanks a lot! I've encountered this failure yesterday and haven't figured it out yet. You just saved me a lot of time :+1: I'll see what I can do about it w.r.t. the test assertions.

cbiedl commented 5 years ago

@diabonas, thanks for checking, the commit is very certainly the reason for the change. The data that causes the tests to fail is random which matches "subsequently, all keyslots areas are wiped with random data" in the commit description.

The fix should be on luksmeta's side, Debian will ship the patch below for the time being:

Description: Relax content tests in test suite Author: Christoph Biedl debian.axhn@manchmal.in-ulm.de Date: 2018-12-09 Forwarded: yes Bug: https://github.com/latchset/luksmeta/issues/6 Bug-Debian: https://bugs.debian.org/915256

     Starting with version 2.0.5, cryptset wipes the full LUKS header
     and fills unused sections with random data, this was introduced
     in commit

     commit c2bce3e93ecee41f661b589ee28f112eb538259e
     Author: Milan Broz <gmazyland@gmail.com>
     Date:   Sun Oct 14 13:11:50 2018 +0200

         Wipe full header areas (including unused) during LUKS format.

     While this is the right thing to do, it breaks luksmeta tests. So
     relax them.

 --- a/test-lm-init.c
 +++ b/test-lm-init.c
 @@ -57,7 +57,7 @@
      /* Test the layout state. */
      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          { offset, 4096 },              /* luksmeta header */
          END(offset + 4096),            /* Rest of the file */
      }));
 @@ -106,7 +106,7 @@
      assert(luksmeta_test(cd) == -ENOENT);
      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          END(offset),                   /* Rest of the file */
      }));

 --- a/test-lm-big.c
 +++ b/test-lm-big.c
 @@ -111,7 +111,7 @@

      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          { offset, 4096 },              /* luksmeta header */
          { offset + 4096, 4096 },       /* luksmeta slot 0 */
          { offset + 8192, 4096 },       /* luksmeta slot 0 (cont) */
 @@ -127,7 +127,7 @@

      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          { offset, 4096 },              /* luksmeta header */
          END(offset + 4096),            /* Rest of the file */
      }));
 --- a/test-lm-one.c
 +++ b/test-lm-one.c
 @@ -49,7 +49,7 @@
      /* Test the layout state. */
      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          { offset, 4096 },              /* luksmeta header */
          { offset + 4096, 4096 },       /* luksmeta slot 0 */
          END(offset + 8192),            /* Rest of the file */
 @@ -68,7 +68,7 @@
      /* Test the layout state. */
      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          { offset, 4096 },              /* luksmeta header */
          END(offset + 4096),            /* Rest of the file */
      }));
 --- a/test-lm-two.c
 +++ b/test-lm-two.c
 @@ -53,7 +53,7 @@

      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          { offset, 4096 },              /* luksmeta header */
          { offset + 4096, 4096 },       /* luksmeta slot 0 */
          END(offset + 8192),            /* Rest of the file */
 @@ -70,7 +70,7 @@

      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          { offset, 4096 },              /* luksmeta header */
          { offset + 4096, 4096 },       /* luksmeta slot 0 */
          { offset + 8192, 4096 },       /* luksmeta slot 1 */
 @@ -88,7 +88,7 @@
      assert(luksmeta_wipe(cd, 0, UUID0) == 0);
      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          { offset, 4096 },              /* luksmeta header */
          { offset + 4096, 4096, true }, /* luksmeta slot 0 */
          { offset + 8192, 4096 },       /* luksmeta slot 1 */
 @@ -99,7 +99,7 @@
      assert(luksmeta_wipe(cd, 1, UUID1) == 0);
      assert(test_layout((range_t[]) {
          { 0, 1024 },                   /* LUKS header */
 -        { 1024, offset - 1024, true }, /* Keyslot Area */
 +        { 1024, 3072, true },          /* Keyslot Area */
          { offset, 4096 },              /* luksmeta header */
          END(offset + 4096),            /* Rest of the file */
      }));
 --- a/test-lm-assumptions.c
 +++ b/test-lm-assumptions.c
 @@ -28,7 +28,8 @@
      /* Test the layout state. */
      assert(test_layout((range_t[]) {
          { 0, 1024 },                    /* LUKS header */
 -        END(1024),                    /* Rest of the file */
 +        { 1024, 3072, true },           /* Keyslot Area */
 +        { 0, 0 },
      }));

      unlink(filename);