Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1qKPjP-0003M5-CI for mharc-grub-devel@gnu.org; Fri, 14 Jul 2023 16:49:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qKPjN-0003Lm-O4 for grub-devel@gnu.org; Fri, 14 Jul 2023 16:49:37 -0400 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qKPjM-0004ez-5Q for grub-devel@gnu.org; Fri, 14 Jul 2023 16:49:37 -0400 Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-401e23045beso18771711cf.0 for ; Fri, 14 Jul 2023 13:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20221208.gappssmtp.com; s=20221208; t=1689367775; x=1691959775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U1G7GFhMj7WJDOSmGtXdWPcS/4/Mh34O7LOkqHDiaIc=; b=1unbEg6abe6bduzdP967/tRIA2GNdeIC82TT8ImuCt+Tyoa2izQmaKSTigsqanAXZn EdDNB7EBQ+N/RJO5MAnS0nSatkUcp9c8RDfime16412CR16J+FxufY9yvSo4MNkQ/lUO COhANKn8l5fgOqpPxLq5xqu3vO2ThExczFAL4we1HJUMQE24vmFpr5hzleqpGBuJ+EXC hFAqfxwD9D5kCA8t2O9OcghkjkyBQXmvYzbcgKucfRSzTN+oOFZosolftNqooFiQVvwo qyvXhVbtmzV444gTdO5pYdih9znY9P23DB5uMs1mhja8+IO8coxtNDJ1XdOzl0mKu8XD 7mjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689367775; x=1691959775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U1G7GFhMj7WJDOSmGtXdWPcS/4/Mh34O7LOkqHDiaIc=; b=IpOZ1RHfV6jdvH7hfkuf+McZjcYq1yONV9vrMb3hTOC8pvUITnH8iuBmNxl24hCsu8 xWCTLpOdK4UfzpHF0YFIY9M5aGngVc5Dd3ZkZaF+GR4kMyNPjSloboGboTx0RMb074OU RrWVGSAySywe+uLqZkQy08Sv1TZH2MUEAdWrrVL6wlzMxLlv4YfXTlo0PcliP5Jtp6AS L4zWZtiNVKC+8XxgiC15Ov/4UyQEHwfGKbAJWQnAGnDkrFm+CkhC8O0R17nu1m82URV4 m9RgVAmFG5uqaD6U7lN4r8BbO/Lv97t627I/YqnjOR07meEXjeXiZcgVB8yIVFh33teL k44g== X-Gm-Message-State: ABy/qLbV+gsLrdDgL17E0H4soeyT/rP6su2S4eh5LmmkObb3Q5wIaOnn CBQSQCiW/UANtVoJ0xDac3HOYC74ZL7r2hz7M+zHHg== X-Google-Smtp-Source: APBJJlHrppqctllG/1iaJ8CdKwDMTTO4xtcWDj8hkVQVMkcatqP8fkElh4i6nrMo1N8EcnIITIrj+w== X-Received: by 2002:a05:622a:291:b0:400:aa47:a4a1 with SMTP id z17-20020a05622a029100b00400aa47a4a1mr7722785qtw.25.1689367774900; Fri, 14 Jul 2023 13:49:34 -0700 (PDT) Received: from localhost.localdomain ([199.58.83.12]) by smtp.gmail.com with ESMTPSA id g2-20020ac87d02000000b0040328b5fbe2sm1426120qtb.58.2023.07.14.13.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 13:49:34 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Patrick Steinhardt , Glenn Washburn Subject: [PATCH v3 2/2] cryptodisk: Add support for LUKS2 in (proc)/luks_script Date: Fri, 14 Jul 2023 15:49:18 -0500 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::833; envelope-from=development@efficientek.com; helo=mail-qt1-x833.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Jul 2023 20:49:38 -0000 The sector size in bytes is added to each line and it is allowed to be 6 decimal digits long, which covers the most common cases of 512 and 4096 byte sectors with space for two additional digits as future-proofing. The size allocation is updated to reflect this additional field. Also make clearer the size allocation calculation. Signed-off-by: Glenn Washburn --- grub-core/disk/cryptodisk.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index c62656a0faea..066cec566aec 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -1478,12 +1478,22 @@ luks_script_get (grub_size_t *sz) *sz = 0; for (i = cryptodisk_list; i != NULL; i = i->next) - if (grub_strcmp (i->modname, "luks") == 0) + if (grub_strcmp (i->modname, "luks") == 0 || + grub_strcmp (i->modname, "luks2") == 0) { - size += sizeof ("luks_mount "); + size += grub_strlen (i->modname); + size += sizeof ("_mount"); size += grub_strlen (i->uuid); size += grub_strlen (i->cipher->cipher->name); - size += 54; + /* + * Add space in the line for (in order) spaces, cipher mode, cipher IV + * mode, sector offset, sector size and the trailing newline. This is + * an upper bound on the size of this data. There are 15 extra bytes + * in an earlier version of this code that are unaccounted for. It is + * left in the calculations in case it is needed. At worst, its short- + * lived wasted space. + */ + size += 5 + 5 + 8 + 20 + 6 + 1 + 15; if (i->essiv_hash) size += grub_strlen (i->essiv_hash->name); size += i->keysize * 2; @@ -1496,15 +1506,19 @@ luks_script_get (grub_size_t *sz) ptr = ret; for (i = cryptodisk_list; i != NULL; i = i->next) - if (grub_strcmp (i->modname, "luks") == 0) + if (grub_strcmp (i->modname, "luks") == 0 || + grub_strcmp (i->modname, "luks2") == 0) { unsigned j; const char *iptr; - ptr = grub_stpcpy (ptr, "luks_mount "); + ptr = grub_stpcpy (ptr, i->modname); + ptr = grub_stpcpy (ptr, "_mount "); ptr = grub_stpcpy (ptr, i->uuid); *ptr++ = ' '; ptr += grub_snprintf (ptr, 21, "%" PRIxGRUB_OFFSET, i->offset_sectors); *ptr++ = ' '; + ptr += grub_snprintf (ptr, 7, "%u", 1 << i->log_sector_size); + *ptr++ = ' '; for (iptr = i->cipher->cipher->name; *iptr; iptr++) *ptr++ = grub_tolower (*iptr); switch (i->mode) -- 2.34.1