From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1qIxNi-0003N3-OT for mharc-grub-devel@gnu.org; Mon, 10 Jul 2023 16:21:14 -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 1qIxNf-0003Mm-Ih for grub-devel@gnu.org; Mon, 10 Jul 2023 16:21:12 -0400 Received: from mail-vk1-xa34.google.com ([2607:f8b0:4864:20::a34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIxNd-0006xa-F8 for grub-devel@gnu.org; Mon, 10 Jul 2023 16:21:11 -0400 Received: by mail-vk1-xa34.google.com with SMTP id 71dfb90a1353d-47e3026ca12so1476755e0c.3 for ; Mon, 10 Jul 2023 13:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20221208.gappssmtp.com; s=20221208; t=1689020468; x=1691612468; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1DM4p+ax1byT/mrYKutfgBrkz4Rq//2w5SrFB5ptPYw=; b=w4+tORP2jo4gtDXG6raaRZyPyWNzFY9OtSQEHhxpkn84X2FTQXzSBXdLMxW8nei7lc BuNz2FXPo4dhd1C7KFlCn4VPASisXhnpagQmI5Uu9XHFZ/2dUH179oY5+UOErEBBzRpH tM8HYBXUO8yiAISd0JNESq/uGL8mV7rzBFSTvSltn/wrscSNi4zvH3mULDKKQ9Duj0xA IXYYe9VWacTyh3p6i79Ir5cHGikLj9hR1Ase0xLuVjmV1MEtPLw4tqhp4ZGf2Ovm8SUQ c2DxkeM3aLdfFjUsZw6FpteHadCd+BVwNNFnH0i/d9Co38q+NtIOT8AiVA1l/L7ZrmEq kiXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689020468; x=1691612468; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1DM4p+ax1byT/mrYKutfgBrkz4Rq//2w5SrFB5ptPYw=; b=NJwex7u1pNowe/jCpoo4MTZ5DjHe/l2IyAyvMuKdHo240L7Wu6DAS6/6tYr6h1pM+a by1Bz1rkJT4dihghnBTwJeN/CZEUaN0DsRurehwmbcn/uZ/p2L8NYgPTMvINCVSFrgVL Qqal7mtH77EL+cL56RqlY/1MQXogpMWkl3yb1fSfjPSOfmOIHCxCTF8XhQCD6ZNKS0wJ j3kbnvt7E8P9wJjSlXL/aobHSw2k+FH/NCDQtfkAkoQiX3YsLx9UMDMSlJvC0BQxB0FZ 7CHGWdyrovXAKAEu5zxQup/ubGEfeZ7RT6RD0fsVxWOgU4wVAveZia/T9rbvb7/9lyS5 XZjg== X-Gm-Message-State: ABy/qLZV8y+QMgx38eUwRHpxQ0P0owY6yGwGV6QSnmZy2vfN+vTTc9DN g+m3NB9x/I5wGzy8xPOyCWQFgkAkRePwN4sAZH8= X-Google-Smtp-Source: APBJJlHn0Ci+3BXZPWbFWy2MEL8tiJQPWQvggFGlCPbNEGs8CnYuZaLvhZPHTujH+Kgo6sHoagXvbg== X-Received: by 2002:a1f:e086:0:b0:47e:30a:c7bc with SMTP id x128-20020a1fe086000000b0047e030ac7bcmr5360121vkg.12.1689020467707; Mon, 10 Jul 2023 13:21:07 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.249]) by smtp.gmail.com with ESMTPSA id j6-20020ac5ccc6000000b004532e881807sm80301vkn.18.2023.07.10.13.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 13:21:06 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Patrick Steinhardt , Glenn Washburn Subject: [PATCH v2] luks2: Add support for LUKS2 in (proc)/luks_script Date: Mon, 10 Jul 2023 15:20:48 -0500 Message-Id: <20230710202048.1458370-1-development@efficientek.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::a34; envelope-from=development@efficientek.com; helo=mail-vk1-xa34.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: Mon, 10 Jul 2023 20:21:12 -0000 The sector size in bytes is added to each line and it is allowed to be 5 decimal digits long, which covers the most common cases of 512 and 4096 byte sectors with space for an additional digit as future-proofing. The size allocation is updated to reflect this additional field, allow up to 5 characters and 1 space added. Signed-off-by: Glenn Washburn --- Range-diff against v1: 1: 14160a8991f6 ! 1: dbf695eef1ab luks2: Add support for LUKS2 in (proc)/luks_script @@ grub-core/disk/cryptodisk.c: luks_script_get (grub_size_t *sz) - grub_snprintf (ptr, 21, "%" PRIuGRUB_UINT64_T " ", i->offset_sectors); - while (*ptr) - ptr++; -+ ptr += grub_snprintf (ptr, 21, "%" PRIuGRUB_UINT64_T " ", ++ ptr += grub_snprintf (ptr, 21, "%" PRIxGRUB_OFFSET " ", + i->offset_sectors); -+ ptr += grub_snprintf (ptr, 7, "%d ", 1 << i->log_sector_size); ++ ptr += grub_snprintf (ptr, 7, "%u ", 1 << i->log_sector_size); for (iptr = i->cipher->cipher->name; *iptr; iptr++) *ptr++ = grub_tolower (*iptr); switch (i->mode) grub-core/disk/cryptodisk.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 34b67a705fbc..7f3170abc887 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 16 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 + 5 + 1 + 16; if (i->essiv_hash) size += grub_strlen (i->essiv_hash->name); size += i->keysize * 2; @@ -1496,16 +1506,18 @@ 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++ = ' '; - grub_snprintf (ptr, 21, "%" PRIuGRUB_UINT64_T " ", i->offset_sectors); - while (*ptr) - ptr++; + ptr += grub_snprintf (ptr, 21, "%" PRIxGRUB_OFFSET " ", + i->offset_sectors); + ptr += grub_snprintf (ptr, 7, "%u ", 1 << i->log_sector_size); for (iptr = i->cipher->cipher->name; *iptr; iptr++) *ptr++ = grub_tolower (*iptr); switch (i->mode) -- 2.34.1