neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

Blame SOURCES/0011-Default-to-encryption-sector-size-512-for-LUKS-devic.patch

a9158f
From 2aba050e74dc5df483da022dcf436b101c7a4301 Mon Sep 17 00:00:00 2001
a9158f
From: Vojtech Trefny <vtrefny@redhat.com>
a9158f
Date: Wed, 11 Jan 2023 14:59:24 +0100
a9158f
Subject: [PATCH] Default to encryption sector size 512 for LUKS devices
a9158f
a9158f
We are currently letting cryptsetup decide the optimal encryption
a9158f
sector size for LUKS. The problem is that for disks with physical
a9158f
sector size 4096 cryptsetup will default to 4096 encryption sector
a9158f
size even if the drive logical sector size is 512 which means
a9158f
these disks cannot be combined with other 512 logical sector size
a9158f
disks in LVM. This requires a more sophisticated solution in the
a9158f
future, but for now just default to 512 if not specified by the
a9158f
user otherwise.
a9158f
a9158f
Resolves: rhbz#2103800
a9158f
---
a9158f
 blivet/formats/luks.py                      | 10 +++++++---
a9158f
 tests/unit_tests/formats_tests/luks_test.py |  2 +-
a9158f
 2 files changed, 8 insertions(+), 4 deletions(-)
a9158f
a9158f
diff --git a/blivet/formats/luks.py b/blivet/formats/luks.py
a9158f
index 8de4911f..2637e0c5 100644
a9158f
--- a/blivet/formats/luks.py
a9158f
+++ b/blivet/formats/luks.py
a9158f
@@ -166,9 +166,13 @@ class LUKS(DeviceFormat):
a9158f
             if self.pbkdf_args.type == "pbkdf2" and self.pbkdf_args.max_memory_kb:
a9158f
                 log.warning("Memory limit is not used for pbkdf2 and it will be ignored.")
a9158f
 
a9158f
-        self.luks_sector_size = kwargs.get("luks_sector_size") or 0
a9158f
-        if self.luks_sector_size and self.luks_version != "luks2":
a9158f
-            raise ValueError("Sector size argument is valid only for LUKS version 2.")
a9158f
+        self.luks_sector_size = kwargs.get("luks_sector_size")
a9158f
+        if self.luks_version == "luks2":
a9158f
+            if self.luks_sector_size is None:
a9158f
+                self.luks_sector_size = 512  # XXX we don't want cryptsetup choose automatically here so fallback to 512
a9158f
+        else:
a9158f
+            if self.luks_sector_size:
a9158f
+                raise ValueError("Sector size argument is valid only for LUKS version 2.")
a9158f
 
a9158f
     def __repr__(self):
a9158f
         s = DeviceFormat.__repr__(self)
a9158f
diff --git a/tests/unit_tests/formats_tests/luks_test.py b/tests/unit_tests/formats_tests/luks_test.py
a9158f
index 5ae6acfe..ec7b7592 100644
a9158f
--- a/tests/unit_tests/formats_tests/luks_test.py
a9158f
+++ b/tests/unit_tests/formats_tests/luks_test.py
a9158f
@@ -53,7 +53,7 @@ class LUKSNodevTestCase(unittest.TestCase):
a9158f
 
a9158f
     def test_sector_size(self):
a9158f
         fmt = LUKS()
a9158f
-        self.assertEqual(fmt.luks_sector_size, 0)
a9158f
+        self.assertEqual(fmt.luks_sector_size, 512)
a9158f
 
a9158f
         with self.assertRaises(ValueError):
a9158f
             fmt = LUKS(luks_version="luks1", luks_sector_size=4096)
a9158f
-- 
a9158f
2.39.0
a9158f