Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lO4LX-0002qc-Rz for mharc-grub-devel@gnu.org; Sun, 21 Mar 2021 16:06:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lO4LS-0002oB-M7 for grub-devel@gnu.org; Sun, 21 Mar 2021 16:06:46 -0400 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]:35479) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lO4LL-0002SQ-Ik for grub-devel@gnu.org; Sun, 21 Mar 2021 16:06:42 -0400 Received: by mail-qv1-xf2f.google.com with SMTP id x27so7719365qvd.2 for ; Sun, 21 Mar 2021 13:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iDdusz77PkhD/1yj8+6rYC9L8h/ykyLREp2y3PKqSEY=; b=WHKJgt7zThdGd2SzIAjG6UwXB8+4mj6X7sn2GY0x6IfN2u+oF72elcERfFYCLX8hNM cJV9XpvKVauSQFqhN+3vFn+sG7xUwU6NKH9izPJEQbhnHetzUGtg2mb3R7tJuYbrWAMd WZ6ngKhBKoPIbZr2LAV+lehNZOrkpaH1ydk1kjamZviD9f11+WaEORCPntdGwOcfC3IJ Ap986rnyKIbjuCa1xnoEBZsd35E8kTX9gc5i1fdZSyNgl46JiWF747ERQhFqRx6STuvu BswPU9JE9+7I52B6zw5iYRB7ouWK2Xt+aMeW8E8JSEMPqp+x7HA4uxuEjId/iGgQqrgQ WWUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iDdusz77PkhD/1yj8+6rYC9L8h/ykyLREp2y3PKqSEY=; b=FrIM0c40tEwNqi1FuwJG2CBY6sse11DjKV3+rFaMC8jho9jpEPADWjS1AXyw3yiXkY aPaezrh6OjmS92N2rYL/6Ji+htTVWi1NIBJ74yuMvGlGNmA3OWmEVqMY3U0gZIcgN3k3 39JG/lGNy9ZRNn5OS28eDXmct90XQ98mA7fBlkmiIekCheb1vDDFY2Z1EU64zYUBUfs0 kgUYp3dkcoxkzUjO5z6mndvTtqvyQ+oj9bDCESbyl88PHRkXuTYfRh3mWCeMvabNgF8N hClkabXWfDUKBZop2yPwLDG9hsGQhe5/KH113bf5N+KOuVXiqdGTaWr6ius22enbTuDc K0AA== X-Gm-Message-State: AOAM531T/T1gjF4tFn6f9cBY7qkam4GumKrF3a74U4KCuNz04T1dRaEN +HAGu91foo3324UJHAJxvTSBNcmoCadHFw== X-Google-Smtp-Source: ABdhPJxjlCbv9g3wxBVY3MV8fpy4LFCyuKEFIBocZ5Ncvu0+T12vprHDTjbn7R6aWkQxaLX/c3Z9Mg== X-Received: by 2002:a0c:e9c7:: with SMTP id q7mr18334610qvo.7.1616357194520; Sun, 21 Mar 2021 13:06:34 -0700 (PDT) Received: from localhost.localdomain ([2605:a601:ab16:db00:23af:6780:efd4:8e25]) by smtp.gmail.com with ESMTPSA id q15sm7643284qtx.47.2021.03.21.13.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 13:06:34 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH v2 1/2] luks, luks2: Force header.uuid to be NULL terminated Date: Sun, 21 Mar 2021 15:06:21 -0500 Message-Id: <784c6fc96630d6c2ae6ae7212ab6db74f17eb778.1616356604.git.development@efficientek.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::f2f; envelope-from=development@efficientek.com; helo=mail-qv1-xf2f.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.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Mar 2021 20:06:46 -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 13103ea6a..9a7323920 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -90,6 +90,9 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid, 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 125e8609a..a7e614470 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -344,6 +344,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.27.0