]> git.proxmox.com Git - mirror_qemu.git/commitdiff
crypto: validate that LUKS payload doesn't overlap with header
authorDaniel P. Berrangé <berrange@redhat.com>
Mon, 5 Sep 2022 12:50:03 +0000 (13:50 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 27 Oct 2022 11:55:27 +0000 (12:55 +0100)
We already validate that LUKS keyslots don't overlap with the
header, or with each other. This closes the remaining hole in
validation of LUKS file regions.

Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
crypto/block-luks.c

index 6ef9a89ffa96ab792c1936195fdfe2de6fe9996c..f22bc63e5460c7001590a336f0408fa6fcfa9eab 100644 (file)
@@ -572,6 +572,13 @@ qcrypto_block_luks_check_header(const QCryptoBlockLUKS *luks, Error **errp)
         return -1;
     }
 
+    if (luks->header.payload_offset_sector <
+        DIV_ROUND_UP(QCRYPTO_BLOCK_LUKS_KEY_SLOT_OFFSET,
+                     QCRYPTO_BLOCK_LUKS_SECTOR_SIZE)) {
+        error_setg(errp, "LUKS payload is overlapping with the header");
+        return -1;
+    }
+
     /* Check all keyslots for corruption  */
     for (i = 0 ; i < QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS ; i++) {