Skip to contentSkip to conversation

FAT: fix mtime 0 breaking updates

PATCH In review Robbie Harwood 2 participants 5 messages Jul 15, 2022 – Jul 19, 2022

lore
Share & tools
lore
#0 lore raw

cover FAT: fix mtime 0 breaking updates

The first two commits are to make debugging grub-probe failures easier, while the third is the actual fix.

A Fedora user reported a problem with grub2-mkconfig failing on their system. This was caused by a grub2-probe failure probing the ESP. It transpired that some files on the ESP had mtime of 0, which was a fatal error for fs/fat. While this is not the first time we have encountered 0 mtimes on the ESP, it's not clear what causes it at this time.

Be well,
--Robbie

Robbie Harwood (3):
grub-probe: document the behavior of multiple -v grub_fs_probe(): dprint errors from filesystems fs/fat: don't error when mtime is 0

 grub-core/fs/fat.c  | 3 ---
 grub-core/kern/fs.c | 1 +
 util/grub-probe.c   | 3 ++-
 3 files changed, 3 insertions(+), 4 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/3 grub-probe: document the behavior of multiple -v

---
 util/grub-probe.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
util/grub-probe.c +2 -1
index 01d26bb87d..446bd25532 100644
@@ -732,7 +732,8 @@ static struct argp_option options[] = {
   {"device-map",  'm', N_("FILE"), 0,
    N_("use FILE as the device map [default=%s]"), 0},
   {"target",  't', N_("TARGET"), 0, 0, 0},
-  {"verbose",     'v', 0,      0, N_("print verbose messages."), 0},
+  {"verbose",     'v', 0,      0,
+   N_("print verbose messages (pass twice to enable debug printing)."), 0},
   {0, '0', 0, 0, N_("separate items in output using ASCII NUL characters"), 0},
   { 0, 0, 0, 0, 0, 0 }
 };
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/3 grub_fs_probe(): dprint errors from filesystems

In reply to Robbie Harwood

When filesystem detection fails, all that's currently debug-logged is a series of messages like:

grub-core/kern/fs.c:56:fs: Detecting ntfs... grub-core/kern/fs.c:76:fs: ntfs detection failed.

repeated for each filesystem. Any messages provided to grub_error() by the filesystem are lost, and one has to break out gdb to figure out what went wrong.

With this change, one instead sees:

grub-core/kern/fs.c:56:fs: Detecting fat... grub-core/osdep/hostdisk.c:357:hostdisk: reusing open device `/path/to/device'
grub-core/kern/fs.c:77:fs: error: invalid modification timestamp for /. grub-core/kern/fs.c:79:fs: fat detection failed.

in the debug prints.

---
 grub-core/kern/fs.c | 1 +
 1 file changed, 1 insertion(+)
grub-core/kern/fs.c +1 -0
index e0d7e16a29..bb1d8cc9dd 100644
@@ -74,6 +74,7 @@ grub_fs_probe (grub_device_t device)
 	  if (grub_errno == GRUB_ERR_NONE)
 	    return p;
 
+	  grub_dprintf ("fs", _("error: %s.\n"), grub_errmsg);
 	  grub_error_push ();
 	  grub_dprintf ("fs", "%s detection failed.\n", p->name);
 	  grub_error_pop ();
Signature · 1 line
2.35.1
#3 lore raw

PATCH 3/3 fs/fat: don't error when mtime is 0

In reply to Robbie Harwood

In the wild, we occasionally see valid ESPs where some file modification times are 0. For instance:

    ├── [Dec 31  1979]  EFI
    │   ├── [Dec 31  1979]  BOOT
    │   │   ├── [Dec 31  1979]  BOOTX64.EFI
    │   │   └── [Dec 31  1979]  fbx64.efi
    │   └── [Jun 27 02:41]  fedora
    │       ├── [Dec 31  1979]  BOOTX64.CSV
    │       ├── [Dec 31  1979]  fonts
    │       ├── [Mar 14 03:35]  fw
    │       │   ├── [Mar 14 03:35]  fwupd-359c1169-abd6-4a0d-8bce-e4d4713335c1.cap
    │       │   ├── [Mar 14 03:34]  fwupd-9d255c4b-2d88-4861-860d-7ee52ade9463.cap
    │       │   └── [Mar 14 03:34]  fwupd-b36438d8-9128-49d2-b280-487be02d948b.cap
    │       ├── [Dec 31  1979]  fwupdx64.efi
    │       ├── [May 10 10:47]  grub.cfg
    │       ├── [Jun  3 12:38]  grub.cfg.new.new
    │       ├── [May 10 10:41]  grub.cfg.old
    │       ├── [Jun 27 02:41]  grubenv
    │       ├── [Dec 31  1979]  grubx64.efi
    │       ├── [Dec 31  1979]  mmx64.efi
    │       ├── [Dec 31  1979]  shim.efi
    │       ├── [Dec 31  1979]  shimx64.efi
    │       └── [Dec 31  1979]  shimx64-fedora.efi
    └── [Dec 31  1979]  FSCK0000.REC

5 directories, 17 files

This causes grub-probe failure, which in turn causes grub-mkconfig failure. They are valid filesystems that appear intact, and the Linux FAT stack is able to mount and manipulate them without complaint.

The check for mtime of 0 has been present since 20def1a3c3952982395cd7c3ea7e78638527962b ("fat: support file modification times").

---
 grub-core/fs/fat.c | 3 ---
 1 file changed, 3 deletions(-)
grub-core/fs/fat.c +0 -3
index 0951b2e63f..c5efed7241 100644
@@ -1027,9 +1027,6 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook,
 					  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);
 
       if (hook (ctxt.filename, &info, hook_data))
 	break;
Signature · 1 line
2.35.1
#4 lore raw
In reply to Robbie Harwood
Quoted 8 lines · Robbie Harwood

The first two commits are to make debugging grub-probe failures easier, while the third is the actual fix.

A Fedora user reported a problem with grub2-mkconfig failing on their system. This was caused by a grub2-probe failure probing the ESP. It transpired that some files on the ESP had mtime of 0, which was a fatal error for fs/fat. While this is not the first time we have encountered 0 mtimes on the ESP, it's not clear what causes it at this time.

For all patches Reviewed-by: Daniel Kiper <[email protected]>...

Daniel