iPXE
Data Structures | Functions | Variables
efi_blacklist.c File Reference

EFI driver blacklist. More...

#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <ipxe/settings.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/DriverBinding.h>
#include <ipxe/efi/Protocol/LoadedImage.h>
#include <ipxe/efi/Protocol/ComponentName.h>
#include <ipxe/efi/efi_blacklist.h>

Go to the source code of this file.

Data Structures

struct  efi_blacklist
 A blacklisted driver. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int efi_blacklist_dell_ip4config (EFI_DRIVER_BINDING_PROTOCOL *binding __unused, EFI_LOADED_IMAGE_PROTOCOL *loaded __unused, EFI_COMPONENT_NAME_PROTOCOL *wtf)
 Blacklist Dell Ip4ConfigDxe driver.
static int efi_blacklist (EFI_HANDLE driver, struct efi_blacklist **blacklist)
 Find driver blacklisting, if any.
void efi_unload_blacklist (void)
 Unload any blacklisted drivers.

Variables

static struct efi_blacklist efi_blacklists []
 Blacklisted drivers.

Detailed Description

EFI driver blacklist.

Definition in file efi_blacklist.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int efi_blacklist_dell_ip4config ( EFI_DRIVER_BINDING_PROTOCOL *binding  __unused,
EFI_LOADED_IMAGE_PROTOCOL *loaded  __unused,
EFI_COMPONENT_NAME_PROTOCOL wtf 
) [static]

Blacklist Dell Ip4ConfigDxe driver.

Parameters:
bindingDriver binding protocol
loadedLoaded image protocol
wtfComponent name protocol, if present
Return values:
blacklistedDriver is the blacklisted driver

Definition at line 64 of file efi_blacklist.c.

References fetch_string_setting(), _EFI_COMPONENT_NAME_PROTOCOL::GetDriverName, manufacturer, memcmp(), name, NULL, and strcmp().

                                                                  {
        static const CHAR16 ip4cfg[] = L"IP4 CONFIG Network Service Driver";
        static const char dell[] = "Dell Inc.";
        char manufacturer[ sizeof ( dell ) ];
        CHAR16 *name;

        /* Check driver name */
        if ( ! wtf )
                return 0;
        if ( wtf->GetDriverName ( wtf, "eng", &name ) != 0 )
                return 0;
        if ( memcmp ( name, ip4cfg, sizeof ( ip4cfg ) ) != 0 )
                return 0;

        /* Check manufacturer */
        fetch_string_setting ( NULL, &manufacturer_setting, manufacturer,
                               sizeof ( manufacturer ) );
        if ( strcmp ( manufacturer, dell ) != 0 )
                return 0;

        return 1;
}
static int efi_blacklist ( EFI_HANDLE  driver,
struct efi_blacklist **  blacklist 
) [static]

Find driver blacklisting, if any.

Parameters:
driverDriver binding handle
Return values:
blacklistDriver blacklisting, or NULL
rcReturn status code

Definition at line 104 of file efi_blacklist.c.

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGC2, EEFI, efi_blacklists, efi_component_name_protocol_guid, efi_driver_binding_protocol_guid, efi_handle_name(), efi_image_handle, efi_loaded_image_protocol_guid, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, NULL, EFI_BOOT_SERVICES::OpenProtocol, rc, and strerror().

                                                              {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        union {
                EFI_DRIVER_BINDING_PROTOCOL *binding;
                void *interface;
        } binding;
        union {
                EFI_LOADED_IMAGE_PROTOCOL *loaded;
                void *interface;
        } loaded;
        union {
                EFI_COMPONENT_NAME_PROTOCOL *wtf;
                void *interface;
        } wtf;
        unsigned int i;
        EFI_HANDLE image;
        EFI_STATUS efirc;
        int rc;

        DBGC2 ( &efi_blacklists, "EFIBL checking %s\n",
                efi_handle_name ( driver ) );

        /* Mark as not blacklisted */
        *blacklist = NULL;

        /* Open driver binding protocol */
        if ( ( efirc = bs->OpenProtocol (
                        driver, &efi_driver_binding_protocol_guid,
                        &binding.interface, efi_image_handle, driver,
                        EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
                rc = -EEFI ( efirc );
                DBGC ( driver, "EFIBL %s could not open driver binding "
                       "protocol: %s\n", efi_handle_name ( driver ),
                       strerror ( rc ) );
                goto err_binding;
        }
        image = binding.binding->ImageHandle;

        /* Open loaded image protocol */
        if ( ( efirc = bs->OpenProtocol (
                        image, &efi_loaded_image_protocol_guid,
                        &loaded.interface, efi_image_handle, image,
                        EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
                rc = -EEFI ( efirc );
                DBGC ( driver, "EFIBL %s could not open",
                       efi_handle_name ( driver ) );
                DBGC ( driver, " %s loaded image protocol: %s\n",
                       efi_handle_name ( image ), strerror ( rc ) );
                goto err_loaded;
        }

        /* Open component name protocol, if present*/
        if ( ( efirc = bs->OpenProtocol (
                        driver, &efi_component_name_protocol_guid,
                        &wtf.interface, efi_image_handle, driver,
                        EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
                /* Ignore failure; is not required to be present */
                wtf.interface = NULL;
        }

        /* Check blacklistings */
        for ( i = 0 ; i < ( sizeof ( efi_blacklists ) /
                            sizeof ( efi_blacklists[0] ) ) ; i++ ) {
                if ( efi_blacklists[i].blacklist ( binding.binding,
                                                   loaded.loaded, wtf.wtf ) ) {
                        *blacklist = &efi_blacklists[i];
                        break;
                }
        }

        /* Success */
        rc = 0;

        /* Close protocols */
        if ( wtf.wtf ) {
                bs->CloseProtocol ( driver, &efi_component_name_protocol_guid,
                                    efi_image_handle, driver );
        }
        bs->CloseProtocol ( image, &efi_loaded_image_protocol_guid,
                            efi_image_handle, image );
 err_loaded:
        bs->CloseProtocol ( driver, &efi_driver_binding_protocol_guid,
                            efi_image_handle, driver );
 err_binding:
        return rc;
}
void efi_unload_blacklist ( void  )

Unload any blacklisted drivers.

Definition at line 196 of file efi_blacklist.c.

References efi_blacklist::blacklist, EFI_SYSTEM_TABLE::BootServices, ByProtocol, DBGC, EEFI, efi_driver_binding_protocol_guid, efi_handle_name(), efi_systab, EFI_BOOT_SERVICES::FreePool, EFI_BOOT_SERVICES::LocateHandleBuffer, efi_blacklist::name, NULL, rc, strerror(), and EFI_BOOT_SERVICES::UnloadImage.

Referenced by efi_probe().

                                   {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        struct efi_blacklist *blacklist;
        EFI_HANDLE *drivers;
        EFI_HANDLE driver;
        UINTN num_drivers;
        unsigned int i;
        EFI_STATUS efirc;
        int rc;

        /* Locate all driver binding protocol handles */
        if ( ( efirc = bs->LocateHandleBuffer (
                        ByProtocol, &efi_driver_binding_protocol_guid,
                        NULL, &num_drivers, &drivers ) ) != 0 ) {
                rc = -EEFI ( efirc );
                DBGC ( &efi_blacklists, "EFIBL could not list all drivers: "
                       "%s\n", strerror ( rc ) );
                return;
        }

        /* Unload any blacklisted drivers */
        for ( i = 0 ; i < num_drivers ; i++ ) {
                driver = drivers[i];
                if ( ( rc = efi_blacklist ( driver, &blacklist ) ) != 0 ) {
                        DBGC ( driver, "EFIBL could not determine "
                               "blacklisting for %s: %s\n",
                               efi_handle_name ( driver ), strerror ( rc ) );
                        continue;
                }
                if ( ! blacklist )
                        continue;
                DBGC ( driver, "EFIBL unloading %s (%s)\n",
                       efi_handle_name ( driver ), blacklist->name );
                if ( ( efirc = bs->UnloadImage ( driver ) ) != 0 ) {
                        DBGC ( driver, "EFIBL could not unload %s: %s\n",
                               efi_handle_name ( driver ), strerror ( rc ) );
                }
        }

        /* Free handle list */
        bs->FreePool ( drivers );
}

Variable Documentation

struct efi_blacklist efi_blacklists[] [static]
Initial value:
 {
        {
                .name = "Dell Ip4Config",
                .blacklist = efi_blacklist_dell_ip4config,
        },
}

Blacklisted drivers.

Definition at line 90 of file efi_blacklist.c.

Referenced by efi_blacklist().