Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mFe6I-0002Ec-Nr for mharc-grub-devel@gnu.org; Mon, 16 Aug 2021 11:00:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFe66-0002BD-NL for grub-devel@gnu.org; Mon, 16 Aug 2021 11:00:19 -0400 Received: from erebus.the-tk.com ([2a01:7e00:e000:24e:109:74:205:187]:34282) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFe64-0005Ax-F5 for grub-devel@gnu.org; Mon, 16 Aug 2021 11:00:18 -0400 Received: from erebus.the-tk.com (localhost [127.0.0.1]) by erebus.the-tk.com (OpenSMTPD) with ESMTP id cfdec812; Mon, 16 Aug 2021 15:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=the-tk.com; h=from:to:cc :subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=sel0; bh=mUH26PnfIpGzYK7QNO6ZVW3HQ 3c=; b=IGGhKa/3ccUMaJN90ueT1IVQzVKyD2wtUj2ktc8Gn6a7hrMfyJ+PsFQ5g yRDKMB1yl6bi4CxM76pYY9S0KDwn/zXYs/HXsSrWCLF1YeP5K6uHYLzl02uEKOIj HA9g5sEAY6Rez6tXrlIWFYhJ6o8zTw5Te4kc5ZtMM44QkRt/MA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=the-tk.com; h=from:to:cc :subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=sel0; b=a1Jv6W17QIuBMMc93c+ YmwPTVqSDw95gIC0c5T7RP1OIY29o6/O38gWH/oBnO2cLqha+tRtV/saIVuxXZli Wnh9VtmnvUmMzkabCs2SfJNUbKLCaJGwKbsVsk77jr6lTDi+BeQ8W874fCwWBlFG Uv2LX5m+QxUsYTE2UInS9AE0= Received: from localhost (cpc96438-basf13-2-0-cust186.12-3.cable.virginm.net [80.0.24.187]) by erebus.the-tk.com (OpenSMTPD) with ESMTPSA id 966af8bf (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Mon, 16 Aug 2021 15:00:07 +0000 (UTC) From: Tomasz Kramkowski To: grub-devel@gnu.org Cc: Tomasz Kramkowski , =?UTF-8?q?Na=C3=AFm=20Favier?= Subject: [PATCH] fat: Allow out-of-range FAT modification timestamps Date: Mon, 16 Aug 2021 15:59:28 +0100 Message-Id: <20210816145928.10518-1-tk@the-tk.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a01:7e00:e000:24e:109:74:205:187; envelope-from=tk@the-tk.com; helo=erebus.the-tk.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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: Mon, 16 Aug 2021 15:00:28 -0000 20def1a3c introduced support for file modification times to allow comparison of file ages on EFI systems. This patch used grub_datetime2unixtime which uses a 32 bit unix timestamp and as a result did not allow the full range of times that FAT timestamps do. In some situations a file with a timestamp of 1970-01-01 gets transferred to a FAT partition, the timestamp ends up as 2098-01-01 because of FAT's use of the 1980-01-01 DOS epoch and lack of negative timestamps. Since 2098 is after 2038, this date cannot fit in a 32 bit timestamp. Ideally grub should use 64 bit timestamps but I have not investigated what kind of work would be required to support this. This fixes bug #60565. Reported-by: Naïm Favier Tested-by: Naïm Favier Signed-off-by: Tomasz Kramkowski --- grub-core/fs/fat.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index dd82e4ee3..34589d7db 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -1020,16 +1020,17 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook, info.mtimeset = grub_exfat_timestamp (grub_le_to_cpu32 (ctxt.entry.type_specific.file.m_time), ctxt.entry.type_specific.file.m_time_tenth, &info.mtime); + if (info.mtimeset == 0) + grub_dprintf("exfat", "invalid modification timestamp for %s\n", path); #else if (ctxt.dir.attr & GRUB_FAT_ATTR_VOLUME_ID) continue; info.mtimeset = grub_fat_timestamp (grub_le_to_cpu16 (ctxt.dir.w_time), grub_le_to_cpu16 (ctxt.dir.w_date), &info.mtime); -#endif if (info.mtimeset == 0) - grub_error (GRUB_ERR_OUT_OF_RANGE, - "invalid modification timestamp for %s", path); + grub_dprintf("fat", "invalid modification timestamp for %s\n", path); +#endif if (hook (ctxt.filename, &info, hook_data)) break; -- 2.32.0