Blame SOURCES/0022-cryptsetup-add-support-for-sector-size-option-9936.patch

a3e2b5
From a046230cfb7e02938e3ad2ac85515636b319651e Mon Sep 17 00:00:00 2001
a3e2b5
From: Dimitri John Ledkov <xnox@ubuntu.com>
a3e2b5
Date: Wed, 29 Aug 2018 15:38:09 +0100
a3e2b5
Subject: [PATCH] cryptsetup: add support for sector-size= option (#9936)
a3e2b5
a3e2b5
Bug-Ubuntu: https://launchpad.net/bugs/1776626
a3e2b5
a3e2b5
Closes #8881.
a3e2b5
a3e2b5
(cherry picked from commit a9fc640671ef60ac949f1ace6fa687ff242fc233)
a3e2b5
a3e2b5
Resolves: #1572563
a3e2b5
---
a3e2b5
 man/crypttab.xml            |  9 +++++++++
a3e2b5
 meson.build                 |  6 ++++++
a3e2b5
 src/cryptsetup/cryptsetup.c | 30 ++++++++++++++++++++++++++++++
a3e2b5
 3 files changed, 45 insertions(+)
a3e2b5
a3e2b5
diff --git a/man/crypttab.xml b/man/crypttab.xml
a3e2b5
index dcaf03d2ca..3574ce00da 100644
a3e2b5
--- a/man/crypttab.xml
a3e2b5
+++ b/man/crypttab.xml
a3e2b5
@@ -250,6 +250,15 @@
a3e2b5
         option.</para></listitem>
a3e2b5
       </varlistentry>
a3e2b5
 
a3e2b5
+      <varlistentry>
a3e2b5
+        <term><option>sector-size=</option></term>
a3e2b5
+
a3e2b5
+        <listitem><para>Specifies the sector size in bytes. See
a3e2b5
+        <citerefentry project='die-net'><refentrytitle>cryptsetup</refentrytitle><manvolnum>8</manvolnum></citerefentry>
a3e2b5
+        for possible values and the default value of this
a3e2b5
+        option.</para></listitem>
a3e2b5
+      </varlistentry>
a3e2b5
+
a3e2b5
       <varlistentry>
a3e2b5
         <term><option>swap</option></term>
a3e2b5
 
a3e2b5
diff --git a/meson.build b/meson.build
a3e2b5
index a0e7240708..f308db2631 100644
a3e2b5
--- a/meson.build
a3e2b5
+++ b/meson.build
a3e2b5
@@ -927,11 +927,17 @@ if want_libcryptsetup != 'false' and not fuzzer_build
a3e2b5
                                    version : '>= 1.6.0',
a3e2b5
                                    required : want_libcryptsetup == 'true')
a3e2b5
         have = libcryptsetup.found()
a3e2b5
+        have_sector = cc.has_member(
a3e2b5
+                    'struct crypt_params_plain',
a3e2b5
+                    'sector_size',
a3e2b5
+                    prefix : '#include <libcryptsetup.h>')
a3e2b5
 else
a3e2b5
         have = false
a3e2b5
+        have_sector = false
a3e2b5
         libcryptsetup = []
a3e2b5
 endif
a3e2b5
 conf.set10('HAVE_LIBCRYPTSETUP', have)
a3e2b5
+conf.set10('HAVE_LIBCRYPTSETUP_SECTOR_SIZE', have_sector)
a3e2b5
 
a3e2b5
 want_libcurl = get_option('libcurl')
a3e2b5
 if want_libcurl != 'false' and not fuzzer_build
a3e2b5
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
a3e2b5
index 832168184a..87008cb969 100644
a3e2b5
--- a/src/cryptsetup/cryptsetup.c
a3e2b5
+++ b/src/cryptsetup/cryptsetup.c
a3e2b5
@@ -23,10 +23,14 @@
a3e2b5
 
a3e2b5
 /* internal helper */
a3e2b5
 #define ANY_LUKS "LUKS"
a3e2b5
+/* as in src/cryptsetup.h */
a3e2b5
+#define CRYPT_SECTOR_SIZE 512
a3e2b5
+#define CRYPT_MAX_SECTOR_SIZE 4096
a3e2b5
 
a3e2b5
 static const char *arg_type = NULL; /* ANY_LUKS, CRYPT_LUKS1, CRYPT_LUKS2, CRYPT_TCRYPT or CRYPT_PLAIN */
a3e2b5
 static char *arg_cipher = NULL;
a3e2b5
 static unsigned arg_key_size = 0;
a3e2b5
+static unsigned arg_sector_size = CRYPT_SECTOR_SIZE;
a3e2b5
 static int arg_key_slot = CRYPT_ANY_SLOT;
a3e2b5
 static unsigned arg_keyfile_size = 0;
a3e2b5
 static uint64_t arg_keyfile_offset = 0;
a3e2b5
@@ -86,6 +90,29 @@ static int parse_one_option(const char *option) {
a3e2b5
 
a3e2b5
                 arg_key_size /= 8;
a3e2b5
 
a3e2b5
+        } else if ((val = startswith(option, "sector-size="))) {
a3e2b5
+
a3e2b5
+#if HAVE_LIBCRYPTSETUP_SECTOR_SIZE
a3e2b5
+                r = safe_atou(val, &arg_sector_size);
a3e2b5
+                if (r < 0) {
a3e2b5
+                        log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
a3e2b5
+                        return 0;
a3e2b5
+                }
a3e2b5
+
a3e2b5
+                if (arg_sector_size % 2) {
a3e2b5
+                        log_error("sector-size= not a multiple of 2, ignoring.");
a3e2b5
+                        return 0;
a3e2b5
+                }
a3e2b5
+
a3e2b5
+                if (arg_sector_size < CRYPT_SECTOR_SIZE || arg_sector_size > CRYPT_MAX_SECTOR_SIZE) {
a3e2b5
+                        log_error("sector-size= is outside of %u and %u, ignoring.", CRYPT_SECTOR_SIZE, CRYPT_MAX_SECTOR_SIZE);
a3e2b5
+                        return 0;
a3e2b5
+                }
a3e2b5
+#else
a3e2b5
+                log_error("sector-size= is not supported, compiled with old libcryptsetup.");
a3e2b5
+                return 0;
a3e2b5
+#endif
a3e2b5
+
a3e2b5
         } else if ((val = startswith(option, "key-slot="))) {
a3e2b5
 
a3e2b5
                 arg_type = ANY_LUKS;
a3e2b5
@@ -471,6 +498,9 @@ static int attach_luks_or_plain(struct crypt_device *cd,
a3e2b5
                 struct crypt_params_plain params = {
a3e2b5
                         .offset = arg_offset,
a3e2b5
                         .skip = arg_skip,
a3e2b5
+#if HAVE_LIBCRYPTSETUP_SECTOR_SIZE
a3e2b5
+                        .sector_size = arg_sector_size,
a3e2b5
+#endif
a3e2b5
                 };
a3e2b5
                 const char *cipher, *cipher_mode;
a3e2b5
                 _cleanup_free_ char *truncated_cipher = NULL;