Re: [PATCH v2] powerpc: increase MIN RMA size for CAS negotiation
Hi Daniel, Thank you for your response! -- Condition before the patch: if (err == GRUB_ERR_NONE && rmo_top < (512 * 1024 * 1024)) grub_ieee1275_ibm_cas (); Condition after the patch: if (!ibm_ca_support_reboot && err == GRUB_ERR_NONE && rmo_top < (512 * 1024 * 1024)) grub_ieee1275_ibm_cas (); -- We have added just one extra check in the code "!ibm_ca_support_reboot" to check whether the reboot is a CAS reboot or not! And these are below comments in the patch which are in question: + /* + * If we have an error or the reboot is detected as CAS reboot, + * don't call CAS, just hope for the best. + * Along with the above, if the rmo_top is 512 MB or above. We + * will skip the CAS call. Though if we call CAS, the rmo_top will + * be set to 768 MB via CAS Vector2. This condition is required to avoid the + * issue where the older Linux kernels are still using rmo_top as 512 MB. + * If we call CAS where rmo_top is less then 768 MB, this will result in an issue + * due to IBM CAS reboot feature and we won't be able to boot the newer kernel. + * The machine will boot with the last booted kernel which has rmo_top as 512 MB. + */ I'm tried to explain in the comment on when the CAS will be called. And why we need to use this old condition "rmo_top < 512 MB" and not "rmo_top < 768 MB". + if (!ibm_ca_support_reboot && err == GRUB_ERR_NONE && rmo_top < (512 * 1024 * 1024)) +grub_ieee1275_ibm_cas (); } Condition 1: (!ibm_ca_support_reboot) This condition checks whether the last reboot is caused by CAS. If the reboot is detected as a CAS reboot, the GRUB will skip the CAS call. As the CAS has already been called earlier and it's not required to call even if the other conditions are met! Condition 2: (rmo_top < (512 * 1024 * 1024)) If the machine detects rmo_top as less than 512 MB, the CAS will be called. Why we need this condition: Logically as we are changing MIN_RMA as 768 MB in GRUB Options_vector2. We should check "rmo_top < (768 * 1024 * 1024)" and not "rmo_top < (512 * 1024 * 1024)". In the patch, whenever we are calling CAS. We set MIN_RMA as 768 MB. But we decide when to call CAS is based on old condition rmo_top < 512 MB. Logically it should be 768 MB. But we can't do this right now due to the below scenarios. We will change this condition to "rmo_top < (768 * 1024 * 1024)" in the future. * Scenario 1: In kernel prom_init.c file. The Options_vector2 is using 512 MB as MIN_RMA. And GRUB is using "rmo_top < (768 * 1024 * 1024)" to call CAS. 1. Machine boots, GRUB detects rmo_top as less than 512 MB. GRUB calls CAS and sets MIN_RMA as 768MB. The machine reboots after the CAS call. (Every CAS call will result in a reboot) 2. Machine boots, GRUB detects rmo_top is not as less than 512 MB. GRUB skips CAS call. 3. After this kernel boots and detects MIN_RMA as other than its 512 MB required value. It calls CAS and makes the MIN_RMA again to 512 MB. As the CAS is called, the machine will go for a reboot again. 4. Now GRUB will again detects rmo_top as less than 512 MB (changed by kernel). And then we will again go back to step 1. And machine will keep doing the CAS calls and change MIN_RMA from 512 to 768 to 512 to 768 and so on. With this, the machine will stuck in this stage forever! * In the above scenario 1, with (!ibm_ca_support_reboot) condition in place. We will avoid this CAS reboot loop. But if we use "rmo_top < (768 * 1024 * 1024)". The machine will never get stuck in reboot loop, but as the CAS is called from GRUB (currently all the powerpc machines has rmo_top is 512 MB). The IBM CAS reboot feature will not allow us to boot with the newer kernel! IBM CAS reboot feature: Whenever a reboot is detected as the CAS reboot by GRUB. It will boot the machine with the last booted kernel by reading the variable "boot-last-label" that has the info related to the last boot. This is specific to IBM powerpc and no other architecture has this. * Scenario 2: In kernel prom_init.c file. The Options_vector2 is using 768 MB as MIN_RMA. And GRUB is using "rmo_top < (768 * 1024 * 1024)" to call CAS. 1. Machine boots, GRUB detects rmo_top as less than 512 MB. GRUB calls CAS and sets MIN_RMA as 768MB. The machine reboots after the CAS call. (Every CAS call will result in a reboot) 2. Machine boots, GRUB detects rmo_top is not as less than 512 MB. GRUB skips CAS call. 3. But as the last boot was a CAS reboot, the machine will boot with the last booted kernel having MIN_RMA as 512 MB. We will not see an option to choose which kernel a user like to boot to. * _ Please let me know if you feel I need to change or add any content in my "comment" in the patch. I have tried my best to explain and cover these above scenarios in simple and short message. And let me know if you have an
Re: [PATCH v2] powerpc: increase MIN RMA size for CAS negotiation
On Tue, Mar 11, 2025 at 02:59:35PM +0530, Avnish Chouhan wrote: > Hi Daniel, > Thank you for your response! > > -- > Condition before the patch: > > if (err == GRUB_ERR_NONE && rmo_top < (512 * 1024 * 1024)) > grub_ieee1275_ibm_cas (); > > Condition after the patch: > > if (!ibm_ca_support_reboot && err == GRUB_ERR_NONE && rmo_top < (512 * 1024 * > 1024)) > grub_ieee1275_ibm_cas (); Avnish, I understand the code. The problem is the commit message and comment are partially unreadable/incomprehensible. So, that is why I am asking you to rephrase them. Now they are better but still... > -- > > We have added just one extra check in the code "!ibm_ca_support_reboot" to > check whether the reboot is a CAS reboot or not! > > And these are below comments in the patch which are in question: > > + /* > + * If we have an error or the reboot is detected as CAS reboot, > + * don't call CAS, just hope for the best. > + * Along with the above, if the rmo_top is 512 MB or above. We > + * will skip the CAS call. Though if we call CAS, the rmo_top will > + * be set to 768 MB via CAS Vector2. This condition is required to > avoid the > + * issue where the older Linux kernels are still using rmo_top as 512 > MB. > + * If we call CAS where rmo_top is less then 768 MB, this will result > in an issue > + * due to IBM CAS reboot feature and we won't be able to boot the > newer kernel. > + * The machine will boot with the last booted kernel which has rmo_top > as 512 MB. > + */ > > I'm tried to explain in the comment on when the CAS will be called. And why > we need to use this old condition "rmo_top < 512 MB" and not "rmo_top < 768 > MB". > > + if (!ibm_ca_support_reboot && err == GRUB_ERR_NONE && rmo_top < (512 > * 1024 * 1024)) > +grub_ieee1275_ibm_cas (); > } > > > Condition 1: (!ibm_ca_support_reboot) > > This condition checks whether the last reboot is caused by CAS. If the > reboot is detected as a CAS reboot, the GRUB will skip the CAS call. As the > CAS has already been called earlier and it's not required to call even if > the other conditions are met! > > Condition 2: (rmo_top < (512 * 1024 * 1024)) > > If the machine detects rmo_top as less than 512 MB, the CAS will be called. > > Why we need this condition: > > Logically as we are changing MIN_RMA as 768 MB in GRUB Options_vector2. We > should check "rmo_top < (768 * 1024 * 1024)" and not "rmo_top < (512 * 1024 > * 1024)". > > In the patch, whenever we are calling CAS. We set MIN_RMA as 768 MB. But we > decide when to call CAS is based on old condition rmo_top < 512 MB. > Logically it should be 768 MB. But we can't do this right now due to the > below scenarios. We will change this condition to "rmo_top < (768 * 1024 * > 1024)" in the future. > > * > Scenario 1: > In kernel prom_init.c file. The Options_vector2 is using 512 MB as MIN_RMA. > And GRUB is using "rmo_top < (768 * 1024 * 1024)" to call CAS. > > 1. Machine boots, GRUB detects rmo_top as less than 512 MB. >GRUB calls CAS and sets MIN_RMA as 768MB. >The machine reboots after the CAS call. (Every CAS call will result in a > reboot) > 2. Machine boots, GRUB detects rmo_top is not as less than 512 MB. >GRUB skips CAS call. > 3. After this kernel boots and detects MIN_RMA as other than its 512 MB > required value. >It calls CAS and makes the MIN_RMA again to 512 MB. >As the CAS is called, the machine will go for a reboot again. > > 4. Now GRUB will again detects rmo_top as less than 512 MB (changed by > kernel). >And then we will again go back to step 1. > > And machine will keep doing the CAS calls and change MIN_RMA from 512 to 768 > to 512 to 768 and so on. With this, the machine will stuck in this stage > forever! > * > > In the above scenario 1, with (!ibm_ca_support_reboot) condition in place. > We will avoid this CAS reboot loop. But if we use "rmo_top < (768 * 1024 * > 1024)". The machine will never get stuck in reboot loop, but as the CAS is > called from GRUB (currently all the powerpc machines has rmo_top is 512 MB). > The IBM CAS reboot feature will not allow us to boot with the newer kernel! > > IBM CAS reboot feature: > > Whenever a reboot is detected as the CAS reboot by GRUB. It will boot the > machine with the last booted kernel by reading the variable > "boot-last-label" that has the info related to the last boot. This is > specific to IBM powerpc and no other architecture has this. > > * > Scenario 2: > In kernel prom_init.c file. The Options_vector2 is using 768 MB as MIN_RMA. > And GRUB is using "rmo_top < (768 * 1024 * 1024)" to call CAS. > > 1. Machine boots, GRUB detects rmo_top as less than 512 MB. >GRUB calls CAS and sets MIN_RMA as 768MB. >The machine reboots after the CAS call. (Every CAS call will result in a > reboot) > 2. Machine boots, GRUB detects rmo_top is not as less than 512 MB. >GRUB skips CAS call. > 3. Bu
[PATCH] fs/zfs: Fix a number of memory leaks in ZFS code
Without this fix, grub failed to boot linux with "out of memory" after trying to run a "search --fs-uuid..." on a system that has 7 ZFS pools across about 80 drives. Signed-off-by: Stuart Hayes --- grub-core/fs/zfs/zfs.c | 43 +- grub-core/fs/zfs/zfsinfo.c | 5 - 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 376042631..bff9d0208 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -1057,8 +1057,10 @@ check_pool_label (struct grub_zfs_data *data, ZIO_SET_CHECKSUM(&emptycksum, diskdesc->vdev_phys_sector << 9, 0, 0, 0); err = zio_checksum_verify (emptycksum, ZIO_CHECKSUM_LABEL, endian, nvlist, VDEV_PHYS_SIZE); - if (err) + if (err) { +grub_free (nvlist); return err; + } grub_dprintf ("zfs", "check 2 passed\n"); @@ -1144,8 +1146,10 @@ check_pool_label (struct grub_zfs_data *data, if (original) data->guid = poolguid; - if (data->guid != poolguid) + if (data->guid != poolguid) { +grub_free (nvlist); return grub_error (GRUB_ERR_BAD_FS, "another zpool"); + } { char *nv; @@ -1186,9 +1190,12 @@ check_pool_label (struct grub_zfs_data *data, { grub_dprintf("zfs","feature missing in check_pool_label:%s\n",name); err= grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET," check_pool_label missing feature '%s' for read",name); + grub_free(features); + grub_free(nvlist); return err; } } + grub_free(features); } grub_dprintf ("zfs", "check 12 passed (feature flags)\n"); grub_free (nvlist); @@ -2601,6 +2608,7 @@ zap_lookup (dnode_end_t * zap_dnode, const char *name, grub_uint64_t *val, return err; } + grub_free (zapbuf); return grub_error (GRUB_ERR_BAD_FS, "unknown ZAP type"); } @@ -2671,6 +2679,7 @@ zap_iterate_u64 (dnode_end_t * zap_dnode, grub_free (zapbuf); return ret; } + grub_free (zapbuf); grub_error (GRUB_ERR_BAD_FS, "unknown ZAP type"); return 0; } @@ -2701,6 +2710,7 @@ zap_iterate (dnode_end_t * zap_dnode, if (block_type == ZBT_MICRO) { grub_error (GRUB_ERR_BAD_FS, "micro ZAP where FAT ZAP expected"); + grub_free (zapbuf); return 0; } if (block_type == ZBT_HEADER) @@ -2712,6 +2722,7 @@ zap_iterate (dnode_end_t * zap_dnode, grub_free (zapbuf); return ret; } + grub_free (zapbuf); grub_error (GRUB_ERR_BAD_FS, "unknown ZAP type"); return 0; } @@ -2785,6 +2796,9 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type, } grub_memmove (&(buf->dn), (dnode_phys_t *) dnbuf + idx, DNODE_SIZE); + if (data->dnode_buf == 0) + /* dnbuf not used anymore if data->dnode_mdn malloc failed */ + grub_free (dnbuf); buf->endian = endian; if (type && buf->dn.dn_type != type) return grub_error(GRUB_ERR_BAD_FS, "incorrect dnode type"); @@ -3436,6 +3450,8 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, if (err) { grub_dprintf ("zfs", "failed here\n"); + grub_free (fsname); + grub_free (snapname); return err; } @@ -3472,8 +3488,11 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, if (!err) err = dnode_get (&(data->mos), headobj, 0, &subvol->mdn, data); - if (!err && subvol->mdn.dn.dn_type != DMU_OT_DSL_DATASET && subvol->mdn.dn.dn_bonustype != DMU_OT_DSL_DATASET) + if (!err && subvol->mdn.dn.dn_type != DMU_OT_DSL_DATASET && subvol->mdn.dn.dn_bonustype != DMU_OT_DSL_DATASET) { + grub_free (fsname); + grub_free (snapname); return grub_error(GRUB_ERR_BAD_FS, "incorrect dataset dnode type"); + } if (err) { @@ -3952,6 +3971,7 @@ grub_zfs_open (struct grub_file *file, const char *fsfilename) { void *sahdrp; int hdrsize; + bool free_sahdrp = false; if (data->dnode.dn.dn_bonuslen != 0) { @@ -3964,6 +3984,7 @@ grub_zfs_open (struct grub_file *file, const char *fsfilename) err = zio_read (bp, data->dnode.endian, &sahdrp, NULL, data); if (err) return err; + free_sahdrp = true; } else { @@ -3972,6 +3993,8 @@ grub_zfs_open (struct grub_file *file, const char *fsfilename) hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp)); file->size = grub_zfs_to_cpu64 (grub_get_unaligned64 ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET), data->dnode.endian); + if (free_sahdrp) + grub_free(sahdrp); } else if (data->dnode.dn.dn_bonustype == DMU_OT_ZNODE) { @@ -4157,6 +4180,7 @@ fill_fs_info (struct grub_dirhook_info *info, { void *sahdrp; int hdrsize; + bool free_sahdrp = false; if (dn.dn.dn_bonuslen != 0)
[PATCH v2 0/2] Support for shim loader protocol
This is supported by the latest shim release candidate. The bit where the verifier saves the image handle and then the loaders grab it via the sideband API is a bit hacky. Julian Andres Klode (1): efi: Provide wrappers for load_image, start_image, unload_image Mate Kukri (1): efi: Use shim's loader protocol for EFI image verification and loading grub-core/kern/efi/efi.c | 57 ++ grub-core/kern/efi/sb.c| 45 --- grub-core/loader/efi/chainloader.c | 30 grub-core/loader/efi/linux.c | 36 ++- include/grub/efi/api.h | 5 +++ include/grub/efi/efi.h | 42 ++ include/grub/efi/sb.h | 5 +-- 7 files changed, 158 insertions(+), 62 deletions(-) -- 2.39.5 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH] tests/util/grub-shell-luks-tester: Find cryptodisk by UUID
On Thu, Mar 06, 2025 at 12:18:43AM -0600, Glenn Washburn wrote: > GRUB has the capability to search all the disks for a cryptodisk of a > given UUID. Use this instead of hardcoding which disk is the cryptodisk, > which can change when devices are added or removed, or potentially when > QEMU is upgraded. This can not be done for the detached header tests > because the header contains the UUID. > > Also, capitalize comment lines for consistency. > > Signed-off-by: Glenn Washburn Reviewed-by: Daniel Kiper Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH v2 2/2] efi: Use shim's loader protocol for EFI image verification and loading
- Use shim loader protocol to verify images in the shim_lock verifier. - Add API to allow downstream consumers to re-use image handles produced by the verifier. This is necessary to avoid having images measured twice to the TPM. - Register shim loader protocol as an image loader. Signed-off-by: Mate Kukri --- grub-core/kern/efi/sb.c| 45 -- grub-core/loader/efi/chainloader.c | 21 -- grub-core/loader/efi/linux.c | 30 ++-- include/grub/efi/api.h | 5 include/grub/efi/efi.h | 19 - include/grub/efi/sb.h | 5 ++-- 6 files changed, 66 insertions(+), 59 deletions(-) diff --git a/grub-core/kern/efi/sb.c b/grub-core/kern/efi/sb.c index 8d3e41360..fcc71e4e8 100644 --- a/grub-core/kern/efi/sb.c +++ b/grub-core/kern/efi/sb.c @@ -31,8 +31,11 @@ #include static grub_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID; +static grub_guid_t shim_loader_guid = GRUB_EFI_SHIM_IMAGE_LOADER_GUID; -static bool shim_lock_enabled = false; +static grub_efi_loader_t *shim_loader = NULL; + +static grub_efi_handle_t last_verified_image_handle; /* * Determine whether we're in secure boot mode. @@ -95,14 +98,6 @@ grub_efi_get_secureboot (void) if (!(attr & GRUB_EFI_VARIABLE_RUNTIME_ACCESS) && *moksbstate == 1) { secureboot = GRUB_EFI_SECUREBOOT_MODE_DISABLED; - /* - * TODO: Replace this all with shim's LoadImage protocol, delegating policy to it. - * - * We need to set shim_lock_enabled here because we disabled secure boot - * validation *inside* shim but not in the firmware, so we set this variable - * here to trigger that code path, whereas the actual verifier is not enabled. - */ - shim_lock_enabled = true; goto out; } @@ -183,14 +178,18 @@ shim_lock_verifier_init (grub_file_t io __attribute__ ((unused)), static grub_err_t shim_lock_verifier_write (void *context __attribute__ ((unused)), void *buf, grub_size_t size) { - grub_efi_shim_lock_protocol_t *sl = grub_efi_locate_protocol (&shim_lock_guid, 0); + grub_efi_handle_t image_handle; - if (!sl) -return grub_error (GRUB_ERR_ACCESS_DENIED, N_("shim_lock protocol not found")); + if (last_verified_image_handle) +{ + shim_loader->unload_image (last_verified_image_handle); + last_verified_image_handle = NULL; +} - if (sl->verify (buf, size) != GRUB_EFI_SUCCESS) + if (shim_loader->load_image (false, grub_efi_image_handle, NULL, buf, size, &image_handle) != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad shim signature")); + last_verified_image_handle = image_handle; return GRUB_ERR_NONE; } @@ -205,11 +204,11 @@ void grub_shim_lock_verifier_setup (void) { struct grub_module_header *header; - grub_efi_shim_lock_protocol_t *sl = -grub_efi_locate_protocol (&shim_lock_guid, 0); - /* shim_lock is missing, check if GRUB image is built with --disable-shim-lock. */ - if (!sl) + shim_loader = grub_efi_locate_protocol (&shim_loader_guid, 0); + + /* shim is missing, check if GRUB image is built with --disable-shim-lock. */ + if (!shim_loader) { FOR_MODULES (header) { @@ -225,14 +224,18 @@ grub_shim_lock_verifier_setup (void) /* Enforce shim_lock_verifier. */ grub_verifier_register (&shim_lock_verifier); - shim_lock_enabled = true; + /* Register shim loader if supported. */ + grub_efi_register_loader (shim_loader); grub_env_set ("shim_lock", "y"); grub_env_export ("shim_lock"); } -bool -grub_is_shim_lock_enabled (void) + +grub_efi_handle_t +grub_efi_get_last_verified_image_handle (void) { - return shim_lock_enabled; + grub_efi_handle_t tmp = last_verified_image_handle; + last_verified_image_handle = NULL; + return tmp; } diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index 11b64ac1b..e77bd863c 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -337,16 +338,20 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } #endif - status = grub_efi_load_image (0, grub_efi_image_handle, file_path, - boot_image, size, &image_handle); - if (status != GRUB_EFI_SUCCESS) + image_handle = grub_efi_get_last_verified_image_handle (); + if (image_handle == NULL) { - if (status == GRUB_EFI_OUT_OF_RESOURCES) - grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources"); - else - grub_error (GRUB_ERR_BAD_OS, "cannot load image"); + status = grub_efi_load_image (0, grub_efi_image_handle, file_path, + boot_image, size, &image_handle); + if (status != GRUB_EFI_SUCCESS) + { + if (status == GRUB_EFI_OUT_OF_RESOURCES) + grub_error (GRUB_ERR_OUT_OF_MEMOR
Re: [PATCH] fs/zfs: Fix a number of memory leaks in ZFS code
LGTM. Reviewed-By: Vladimir Serbinenko Le lun. 10 mars 2025, 19:25, Stuart Hayes a écrit : > Without this fix, grub failed to boot linux with "out of memory" after > trying to run a "search --fs-uuid..." on a system that has 7 ZFS pools > across about 80 drives. > > Signed-off-by: Stuart Hayes > --- > grub-core/fs/zfs/zfs.c | 43 +- > grub-core/fs/zfs/zfsinfo.c | 5 - > 2 files changed, 42 insertions(+), 6 deletions(-) > > diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c > index 376042631..bff9d0208 100644 > --- a/grub-core/fs/zfs/zfs.c > +++ b/grub-core/fs/zfs/zfs.c > @@ -1057,8 +1057,10 @@ check_pool_label (struct grub_zfs_data *data, >ZIO_SET_CHECKSUM(&emptycksum, diskdesc->vdev_phys_sector << 9, 0, 0, 0); >err = zio_checksum_verify (emptycksum, ZIO_CHECKSUM_LABEL, endian, > nvlist, VDEV_PHYS_SIZE); > - if (err) > + if (err) { > +grub_free (nvlist); > return err; > + } > >grub_dprintf ("zfs", "check 2 passed\n"); > > @@ -1144,8 +1146,10 @@ check_pool_label (struct grub_zfs_data *data, >if (original) > data->guid = poolguid; > > - if (data->guid != poolguid) > + if (data->guid != poolguid) { > +grub_free (nvlist); > return grub_error (GRUB_ERR_BAD_FS, "another zpool"); > + } > >{ > char *nv; > @@ -1186,9 +1190,12 @@ check_pool_label (struct grub_zfs_data *data, > { > grub_dprintf("zfs","feature missing in > check_pool_label:%s\n",name); > err= grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET," > check_pool_label missing feature '%s' for read",name); > + grub_free(features); > + grub_free(nvlist); > return err; > } > } > + grub_free(features); > } >grub_dprintf ("zfs", "check 12 passed (feature flags)\n"); >grub_free (nvlist); > @@ -2601,6 +2608,7 @@ zap_lookup (dnode_end_t * zap_dnode, const char > *name, grub_uint64_t *val, >return err; > } > > + grub_free (zapbuf); >return grub_error (GRUB_ERR_BAD_FS, "unknown ZAP type"); > } > > @@ -2671,6 +2679,7 @@ zap_iterate_u64 (dnode_end_t * zap_dnode, >grub_free (zapbuf); >return ret; > } > + grub_free (zapbuf); >grub_error (GRUB_ERR_BAD_FS, "unknown ZAP type"); >return 0; > } > @@ -2701,6 +2710,7 @@ zap_iterate (dnode_end_t * zap_dnode, >if (block_type == ZBT_MICRO) > { >grub_error (GRUB_ERR_BAD_FS, "micro ZAP where FAT ZAP expected"); > + grub_free (zapbuf); >return 0; > } >if (block_type == ZBT_HEADER) > @@ -2712,6 +2722,7 @@ zap_iterate (dnode_end_t * zap_dnode, >grub_free (zapbuf); >return ret; > } > + grub_free (zapbuf); >grub_error (GRUB_ERR_BAD_FS, "unknown ZAP type"); >return 0; > } > @@ -2785,6 +2796,9 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, > grub_uint8_t type, > } > >grub_memmove (&(buf->dn), (dnode_phys_t *) dnbuf + idx, DNODE_SIZE); > + if (data->dnode_buf == 0) > + /* dnbuf not used anymore if data->dnode_mdn malloc failed */ > + grub_free (dnbuf); >buf->endian = endian; >if (type && buf->dn.dn_type != type) > return grub_error(GRUB_ERR_BAD_FS, "incorrect dnode type"); > @@ -3436,6 +3450,8 @@ dnode_get_fullpath (const char *fullpath, struct > subvolume *subvol, >if (err) > { > grub_dprintf ("zfs", "failed here\n"); > + grub_free (fsname); > + grub_free (snapname); > return err; > } > > @@ -3472,8 +3488,11 @@ dnode_get_fullpath (const char *fullpath, struct > subvolume *subvol, >if (!err) > err = dnode_get (&(data->mos), headobj, 0, > &subvol->mdn, data); > - if (!err && subvol->mdn.dn.dn_type != DMU_OT_DSL_DATASET && > subvol->mdn.dn.dn_bonustype != DMU_OT_DSL_DATASET) > + if (!err && subvol->mdn.dn.dn_type != DMU_OT_DSL_DATASET && > subvol->mdn.dn.dn_bonustype != DMU_OT_DSL_DATASET) { > + grub_free (fsname); > + grub_free (snapname); > return grub_error(GRUB_ERR_BAD_FS, "incorrect dataset dnode type"); > + } > >if (err) > { > @@ -3952,6 +3971,7 @@ grub_zfs_open (struct grub_file *file, const char > *fsfilename) > { >void *sahdrp; >int hdrsize; > + bool free_sahdrp = false; > >if (data->dnode.dn.dn_bonuslen != 0) > { > @@ -3964,6 +3984,7 @@ grub_zfs_open (struct grub_file *file, const char > *fsfilename) > err = zio_read (bp, data->dnode.endian, &sahdrp, NULL, data); > if (err) > return err; > + free_sahdrp = true; > } >else > { > @@ -3972,6 +3993,8 @@ grub_zfs_open (struct grub_file *file, const char > *fsfilename) > >hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp)); >file->size = grub_zfs_to_cpu64 (grub_get_unaligned64 ((char *) > sahdrp + hdrsize + SA_SI
Re: [PATCH v2 0/6] Various test fixes proposed by Thomas Schmitt
On Mon, Mar 03, 2025 at 02:12:00AM -0600, Glenn Washburn wrote: > Thomas Schmitt proposed variations on these fixes[1]. I've broken his > patch into several patches with improvements. > > Glenn > > [1] https://lore.kernel.org/all/9956308756800479...@scdbackup.webframe.org/ > > v2: > * Add patch #2 to allow grub-shell-luks-tester to cleanup properly on > expected >failure. > * Add patch #5 to remove empty directories left by the cryptomount tests. > > Glenn Washburn (5): > tests/util/grub-shell-luks-tester: Add missing line to create RET > variable in cleanup > tests: Cleanup generated files on expected failure in > grub_cmd_cryptomount > tests/grub_cmd_cryptomount: Cleanup the cryptsetup script unless debug > is enabled > tests/grub_cmd_cryptomount: Default TMPDIR to /tmp > tests/util/grub-shell: Remove the work directory on successful run and > debug is not on > > Thomas Schmitt (1): > tests/grub_cmd_cryptomount: Remove temporary directories if successful > and debug is not on Reviewed-by: Daniel Kiper for all patches... Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH v2 1/2] efi: Provide wrappers for load_image, start_image, unload_image
From: Julian Andres Klode These can be used to register a different implementation later, for example, when shim provides a protocol with those functions. Signed-off-by: Mate Kukri --- grub-core/kern/efi/efi.c | 57 ++ grub-core/loader/efi/chainloader.c | 13 +++ grub-core/loader/efi/linux.c | 12 +++ include/grub/efi/efi.h | 37 +++ 4 files changed, 104 insertions(+), 15 deletions(-) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index b93ae3aba..77456835e 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -1049,3 +1049,60 @@ grub_efi_find_configuration_table (const grub_guid_t *target_guid) return 0; } + +static const grub_efi_loader_t *override_loader = NULL; + +grub_err_t +grub_efi_register_loader (const grub_efi_loader_t *loader) +{ + if (override_loader != NULL) +return grub_error (GRUB_ERR_BUG, "trying to register different loader"); + override_loader = loader; + return GRUB_ERR_NONE; +} + +grub_err_t +grub_efi_unregister_loader (const grub_efi_loader_t *loader) +{ + if (loader != override_loader) +return grub_error (GRUB_ERR_BUG, "trying to unregister different loader"); + + override_loader = NULL; + return GRUB_ERR_NONE; +} + +grub_efi_status_t +grub_efi_load_image (grub_efi_boolean_t boot_policy, +grub_efi_handle_t parent_image_handle, +grub_efi_device_path_t *file_path, void *source_buffer, +grub_efi_uintn_t source_size, +grub_efi_handle_t *image_handle) +{ + if (override_loader != NULL) +return override_loader->load_image (boot_policy, parent_image_handle, + file_path, source_buffer, source_size, + image_handle); + return grub_efi_system_table->boot_services->load_image ( + boot_policy, parent_image_handle, file_path, source_buffer, source_size, + image_handle); +} + +grub_efi_status_t +grub_efi_start_image (grub_efi_handle_t image_handle, + grub_efi_uintn_t *exit_data_size, + grub_efi_char16_t **exit_data) +{ + if (override_loader != NULL) +return override_loader->start_image (image_handle, exit_data_size, +exit_data); + return grub_efi_system_table->boot_services->start_image ( + image_handle, exit_data_size, exit_data); +} + +grub_efi_status_t +grub_efi_unload_image (grub_efi_handle_t image_handle) +{ + if (override_loader != NULL) +return override_loader->unload_image (image_handle); + return grub_efi_system_table->boot_services->unload_image (image_handle); +} diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index 869307bf3..11b64ac1b 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -50,14 +50,12 @@ grub_chainloader_unload (void *context) { grub_efi_handle_t image_handle = (grub_efi_handle_t) context; grub_efi_loaded_image_t *loaded_image; - grub_efi_boot_services_t *b; loaded_image = grub_efi_get_loaded_image (image_handle); if (loaded_image != NULL) grub_free (loaded_image->load_options); - b = grub_efi_system_table->boot_services; - b->unload_image (image_handle); + grub_efi_unload_image (image_handle); grub_dl_unref (my_mod); return GRUB_ERR_NONE; @@ -73,7 +71,7 @@ grub_chainloader_boot (void *context) grub_efi_char16_t *exit_data = NULL; b = grub_efi_system_table->boot_services; - status = b->start_image (image_handle, &exit_data_size, &exit_data); + status = grub_efi_start_image (image_handle, &exit_data_size, &exit_data); if (status != GRUB_EFI_SUCCESS) { if (exit_data) @@ -339,9 +337,8 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } #endif - status = b->load_image (0, grub_efi_image_handle, file_path, - boot_image, size, - &image_handle); + status = grub_efi_load_image (0, grub_efi_image_handle, file_path, + boot_image, size, &image_handle); if (status != GRUB_EFI_SUCCESS) { if (status == GRUB_EFI_OUT_OF_RESOURCES) @@ -418,7 +415,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), b->free_pages (address, pages); if (image_handle != NULL) -b->unload_image (image_handle); +grub_efi_unload_image (image_handle); grub_dl_unref (my_mod); diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c index 78ea07ca8..7342f3ee7 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c @@ -187,7 +187,6 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) { grub_efi_memory_mapped_device_path_t *mempath; grub_efi_handle_t image_handle; - grub_efi_boot_services_t *b; grub_efi_status_t status; grub_efi_loade