Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oEnK2-0001b7-6B for mharc-grub-devel@gnu.org; Fri, 22 Jul 2022 03:43:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEnJt-0001Y6-Kl for grub-devel@gnu.org; Fri, 22 Jul 2022 03:43:34 -0400 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]:47023) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oEnJr-0006WX-Tv for grub-devel@gnu.org; Fri, 22 Jul 2022 03:43:33 -0400 Received: by mail-qk1-x72f.google.com with SMTP id v28so3037768qkg.13 for ; Fri, 22 Jul 2022 00:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YL++coqO41lZGs9t1S10wq5lw6THE/+BkasG8EGt3Qg=; b=rCILxTSdzQPWux7/MOLsHdQ1XcMXWVuZIYkez+i6wKMcxRS25ztGPyqMRRwvBOI1nU mbqTAkImwH6eFst38BIi5Kb4IDnvl0VL7yKzVKEt1gYkyOPUHX5I9xckXTw8EesO782h 7Y1HiH0faTd/M1KonHIvMoRxWuMNQdIuzjlZl7T13dMVfr0tVYeXt3by4ZRMg58lvGJv 3jPIJqJUZCzpU4RmT73yaZwKC+b8pGTFL8PHGdiP9UVVqFc146n2r4+I/aPUd+uZBWWy ovyiTjhqt3f1a6wdwwX1eSA7lEErDAkRduVgEV7jUEcm8lO7ByPmCjUOBtHAO7MuYAqx O3Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YL++coqO41lZGs9t1S10wq5lw6THE/+BkasG8EGt3Qg=; b=pS0RQNVwKCHCrqrP1dkYugRkGbrXZCqBudiZmamQ/H3v0OIzRiPBNZJPeWoqBTha+G e8VrDUgBioRKOVXd8OLJ6K1HXcBvawTQnmgGVszwwZcY878TmGPoBJ3pl3BPR2z80d2n RwLO/Z3BT5iX1SURqPARuLCxzRdo3zcrIEUchgplxT4hp8r2vpN3ocZFkLa8NXC1X0fN ZureCJPxv/zFSWMkV2ZU1ipbMmVkbCD6eRBn7o+dKXK8fsJ1lqszZVpfjRNLvIgvGZ6o I5KFA9Gs4p59dALca693UIleuRvk0gpZxR7SwbUlR4sWt3LU/HlIublqJW4mAy5cXRVu qoAw== X-Gm-Message-State: AJIora96nLxsu3efaqGhYgdHKZ99EIFM1DQR504k6iN5olphVTRqIy5k ZrVcYoJf+G0vgBU9skbiiH5pYZ4aeyyoUw== X-Google-Smtp-Source: AGRyM1v3FZDq/z/Tx6WztDnjbq5/zKKxxdChrusTW9OTrLnR0DL1FdrnwXhyEU6Qxfo9mC+wI9cZRA== X-Received: by 2002:a05:620a:15e4:b0:6b5:c8d7:eab0 with SMTP id p4-20020a05620a15e400b006b5c8d7eab0mr1582971qkm.536.1658475811091; Fri, 22 Jul 2022 00:43:31 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id x2-20020a05620a448200b006a8b6848556sm2955254qkp.7.2022.07.22.00.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 00:43:30 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Patrick Steinhardt , Glenn Washburn Subject: [PATCH v4 1/2] luks, luks2: Force header.uuid to be NULL terminated Date: Fri, 22 Jul 2022 02:43:13 -0500 Message-Id: <5b736b245bc6470b77c08073410c0d1d0e0d5a62.1658475502.git.development@efficientek.com> 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::72f; envelope-from=development@efficientek.com; helo=mail-qk1-x72f.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, 22 Jul 2022 07:43:36 -0000 According to the LUKS specification the uuid header field is of data type "char[]", which is defined as "a string stored as null terminated sequence of 8-bit characters". So enforce this by adding a null byte as the last byte of the uuid. The LUKS2 specification defers to the LUKS1 specification in this regard. Signed-off-by: Glenn Washburn --- grub-core/disk/luks.c | 3 +++ grub-core/disk/luks2.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 7f837d52c..ad72e5d1f 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -87,6 +87,9 @@ luks_scan (grub_disk_t disk, grub_cryptomount_args_t cargs) return NULL; } + /* According to the spec the uuid field is NULL terminated, so enforce it. */ + header.uuid[sizeof (header.uuid) - 1] = '\0'; + /* Look for LUKS magic sequence. */ if (grub_memcmp (header.magic, LUKS_MAGIC, sizeof (header.magic)) || grub_be_to_cpu16 (header.version) != 1) diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c index bf741d70f..1346c3821 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -342,6 +342,9 @@ luks2_read_header (grub_disk_t disk, grub_luks2_header_t *outhdr) header = &secondary; grub_memcpy (outhdr, header, sizeof (*header)); + /* According to the spec the uuid field is NULL terminated, so enforce it. */ + header->uuid[sizeof (header->uuid) - 1] = '\0'; + return GRUB_ERR_NONE; } -- 2.34.1