From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pOZ65-0004o6-1y for mharc-grub-devel@gnu.org; Sun, 05 Feb 2023 02:05:57 -0500 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 1pOZ62-0004mN-6K for grub-devel@gnu.org; Sun, 05 Feb 2023 02:05:54 -0500 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pOZ5x-000370-Le for grub-devel@gnu.org; Sun, 05 Feb 2023 02:05:52 -0500 Received: by mail-qt1-x829.google.com with SMTP id z5so9861065qtn.8 for ; Sat, 04 Feb 2023 23:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uXOjHNOz1gxKFYNiZtH7SAqYEeUK25n0nAMZiUKkXcQ=; b=czfxSmf1pUNFpn0sHjwXfjjXWpxlqEJDJpOc+c4EWIB7XuBma3Ga9Z/LUMNcNL8meU 9fyvfCLndp6FQlBvCO/Yc7KpWT6gkvBajLNWMug3ZWzSlW9LlTBfnc8nqYMdaPa99yJP IU296KDDHy08K3i5lCThN14uIr5TNI/tq7H1R44bL6DPoK01C2wr19IECQdFyGQkSOEP Mlv86vTv2+KiItROJt9hRwM8XjogofX8sSeUzPB9CHC+T346ieSPJQaQ/cxM3CW4eNOy EBBcSbA+My6MLy1NUD6Obp356DjqqxodRQid0RCRmpQj2X7p2AWQlrS5u8ABs4/wMB+c Zgdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=uXOjHNOz1gxKFYNiZtH7SAqYEeUK25n0nAMZiUKkXcQ=; b=d191gq8PQ9gE5QF80MOcvX1IyPhQk5gKz8k8SCEHsxeLZQBZ9fM/OfYtdUr1KJyLxa tHYCJ1R9l4uARTA0N1mIRVfbzXQQlKrak80oKRWSTcMKkuVRZORV+ZM4ORTxbHVHpCuK crQ6rwq756jMOmM48O8u5r5I1U4FEwQvh4ryxruo7fDawxeal2xh0rA53BOkqRJE1FSv yTit5u12sLBwvM7uW+JkvaElgpLwFPgwRn+snFnDjOOVnSYa9AQANn/u7iO6TDyLXNBr HcugYobVn9VfvyflN2gVZ5EcOq0/l2hafnBomM05ucMueZj0//EnPf2nOomb1EMwltY0 QLjw== X-Gm-Message-State: AO0yUKUvsL7XYu0Qjelun21Q+NVBJA3e6sbVBlyXIOo5iRXHH0/Hbs7U DIYlcbp1bkFM4r+R9+29xPCsBMI2SxHg/K0i X-Google-Smtp-Source: AK7set+/sprHb/aaHZrNtDYjt4B1BhmQ9L4E0HE9RJHtFEVOXEozjeCs6o6k/pt1ya0qZJPJmTylBw== X-Received: by 2002:ac8:5ac8:0:b0:3b7:ec87:8154 with SMTP id d8-20020ac85ac8000000b003b7ec878154mr16177219qtd.44.1675580748039; Sat, 04 Feb 2023 23:05:48 -0800 (PST) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id t189-20020a372dc6000000b0072771acaf09sm5106395qkh.126.2023.02.04.23.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Feb 2023 23:05:46 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Patrick Steinhardt , Glenn Washburn Subject: [PATCH] luks2: Add support for LUKS2 in (proc)/luks_script Date: Sun, 5 Feb 2023 01:05:31 -0600 Message-Id: <20230205070531.1951868-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::829; envelope-from=development@efficientek.com; helo=mail-qt1-x829.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 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: Sun, 05 Feb 2023 07:05:54 -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 --- 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 34b67a705f..f2c8c8d3fe 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, "%" PRIuGRUB_UINT64_T " ", + i->offset_sectors); + ptr += grub_snprintf (ptr, 7, "%d ", 1 << i->log_sector_size); for (iptr = i->cipher->cipher->name; *iptr; iptr++) *ptr++ = grub_tolower (*iptr); switch (i->mode) -- 2.34.1