)]}'
{
  "commit": "04e60a278abcda47301f6be2c23755e5e1004661",
  "tree": "1dbbe4fd7dc600b792c1b9eb011d1c8d6ec86726",
  "parents": [
    "471599dc7721d454b6658062c901b52038a78be2"
  ],
  "author": {
    "name": "Michael Brown",
    "email": "mcb30@ipxe.org",
    "time": "Tue Feb 28 12:04:58 2023 +0000"
  },
  "committer": {
    "name": "Michael Brown",
    "email": "mcb30@ipxe.org",
    "time": "Tue Feb 28 12:30:54 2023 +0000"
  },
  "message": "[efi] Omit EFI_LOAD_FILE2_PROTOCOL for a zero-length initrd\n\nWhen the Linux kernel is being used with no initrd, iPXE will still\nprovide a zero-length initrd.magic file within the virtual filesystem.\nAs of commit 6a004be (\"[efi] Support the initrd autodetection\nmechanism in newer Linux kernels\"), this zero-length file will also be\nexposed via an EFI_LOAD_FILE2_PROTOCOL instance on a handle with a\nfixed device path.\n\nThe correct handling of zero-length files via EFI_LOAD_FILE2_PROTOCOL\nis unfortunately not well defined.\n\nLinux expects the first call to LoadFile() to always fail with\nEFI_BUFFER_TOO_SMALL.  When the initrd is genuinely zero-length, iPXE\nwill return success since the buffer is not too small to hold the\n(zero-length) file.  This causes Linux to immediately report a\nspurious EFI_LOAD_ERROR boot failure.\n\nWe could change the logic in iPXE\u0027s efi_file_load() to always return\nEFI_BUFFER_TOO_SMALL if Buffer is NULL on entry.  Since the correct\nbehaviour of LoadFile() in the corner case of a zero-length file is\nleft undefined by the UEFI specification, this would be permissible.\n\nUnfortunately this approach would not fix the problem.  If we return\nEFI_BUFFER_TOO_SMALL and set the file length to zero, then Linux will\ncall the boot services AllocatePages() method with a zero length.  In\nat least the EDK2 implementation, this combination of parameters will\ncause AllocatePages() to return EFI_OUT_OF_RESOURCES, and Linux will\nagain report a boot failure.\n\nAnother approach would be to install the initrd device path handle\nonly if we have a non-empty initrd to offer.  Unfortunately this would\nlead to a failure in yet another corner case: if a previous bootloader\nhas installed an initrd device path handle (e.g. to pass a boot script\nto iPXE) then we must not leave that initrd in place, since then our\nloaded kernel would end up seeing the wrong initrd content.\n\nThe cleanest fix seems to be to ensure that the initrd device path\nhandle is installed with the EFI_DEVICE_PATH_PROTOCOL instance present\nbut with the EFI_LOAD_FILE2_PROTOCOL instance absent (and forcibly\nuninstalled if necessary), matching the state in which we leave the\nhandle after uninstalling our virtual filesystem.  Linux will then not\nfind any handle that supports EFI_LOAD_FILE2_PROTOCOL within the fixed\ndevice path, and so will fall through to trying other mechanisms to\nlocate the initrd.\n\nReported-by: Chris Bradshaw \u003ccwbshaw@gmail.com\u003e\nSigned-off-by: Michael Brown \u003cmcb30@ipxe.org\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "e8debbbe1a538c8419504eb7cd9126f7b909fd3e",
      "old_mode": 33188,
      "old_path": "src/interface/efi/efi_file.c",
      "new_id": "7bcf8d5971d3c7ffe59778a69758bf7403d620d8",
      "new_mode": 33188,
      "new_path": "src/interface/efi/efi_file.c"
    }
  ]
}
