]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Revert "libblkid: luks: add checksum support"
authorKarel Zak <kzak@redhat.com>
Mon, 19 Sep 2022 09:39:09 +0000 (11:39 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 19 Sep 2022 09:39:09 +0000 (11:39 +0200)
See discussion at https://github.com/util-linux/util-linux/pull/1801

The change is unwanted by LUKS upstream developers, the checksum
functionality is designed for libcryptsetup internal use only.
Issues:

* introduces security issue (allocated buffer is not checked agaisnt
  maximal value) - inserting LUKS2 device with header faking oversized
  header size will cause allocating of huge amount of memory (perhaps
  crash of blkid)
* we support JSON area up to 4MB in size (checksum covers also this part
  that was not intended to be read by blkid) - calculating SHA256 for
  such area is really not fast operation; readin of 4MB of data is waste
  of resources either (that's why there is smaill 4k binary header)
* even if checksum check is disabled, it is calculated (complete waste
  of time here)
* it does not support anything else that SHA256 (we can switch to different
  hash or other algorithm later); blkid should not introduce such limits.
* checksum for the second heder is not calculated at all

This reverts commit eca0d8b8b1360f745131158bf6b5b5c1c04d98c9.

Signed-off-by: Karel Zak <kzak@redhat.com>
Addresses: https://github.com/util-linux/util-linux/pull/1801

libblkid/src/superblocks/luks.c
tests/ts/blkid/images-fs/luks2.img.xz

index a3aa84c5ea6df21e72f2ec7738e78d63f388dbfd..0230b349267081966641122a0dbbecc57df47e6d 100644 (file)
@@ -17,7 +17,6 @@
 #include <stdint.h>
 
 #include "superblocks.h"
-#include "sha256.h"
 
 #define LUKS_CIPHERNAME_L              32
 #define LUKS_CIPHERMODE_L              32
@@ -97,23 +96,6 @@ static int luks_attributes(blkid_probe pr, struct luks2_phdr *header, uint64_t o
        return BLKID_PROBE_OK;
 }
 
-static int luks_verify_csum(blkid_probe pr, struct luks2_phdr *header)
-{
-       if (strncmp(header->checksum_alg, "sha256", sizeof(header->checksum_alg)))
-               return 1;
-
-       uint64_t header_size = be64_to_cpu(header->hdr_size);
-       unsigned char *checksummed = blkid_probe_get_buffer(pr, 0, header_size);
-       if (!checksummed)
-               return 0;
-       memset(checksummed + offsetof(struct luks2_phdr, csum), 0, LUKS2_CHECKSUM_L);
-
-       unsigned char csum[32];
-       ul_SHA256(csum, checksummed, header_size);
-
-       return blkid_probe_verify_csum(pr, 1, !memcmp(header->csum, csum, 32));
-}
-
 static int probe_luks(blkid_probe pr, const struct blkid_idmag *mag __attribute__((__unused__)))
 {
        struct luks2_phdr *header;
@@ -124,8 +106,6 @@ static int probe_luks(blkid_probe pr, const struct blkid_idmag *mag __attribute_
                return errno ? -errno : BLKID_PROBE_NONE;
 
        if (!memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L)) {
-               if (!luks_verify_csum(pr, header))
-                       return BLKID_PROBE_NONE;
                /* LUKS primary header was found. */
                return luks_attributes(pr, header, 0);
        }
index 311a4e865608e81dcc79f1e0351558c0d1a9f796..997fb0483d6e1f4827543f9267e8cf830898144f 100644 (file)
Binary files a/tests/ts/blkid/images-fs/luks2.img.xz and b/tests/ts/blkid/images-fs/luks2.img.xz differ