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. More...
 
static int efi_blacklist (EFI_HANDLE driver, struct efi_blacklist **blacklist)
 Find driver blacklisting, if any. More...
 
void efi_unload_blacklist (void)
 Unload any blacklisted drivers. More...
 

Variables

static struct efi_blacklist efi_blacklists []
 Blacklisted drivers. More...
 

Detailed Description

EFI driver blacklist.

Definition in file efi_blacklist.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_blacklist_dell_ip4config()

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.

66  {
67  static const CHAR16 ip4cfg[] = L"IP4 CONFIG Network Service Driver";
68  static const char dell[] = "Dell Inc.";
69  char manufacturer[ sizeof ( dell ) ];
70  CHAR16 *name;
71 
72  /* Check driver name */
73  if ( ! wtf )
74  return 0;
75  if ( wtf->GetDriverName ( wtf, "eng", &name ) != 0 )
76  return 0;
77  if ( memcmp ( name, ip4cfg, sizeof ( ip4cfg ) ) != 0 )
78  return 0;
79 
80  /* Check manufacturer */
81  fetch_string_setting ( NULL, &manufacturer_setting, manufacturer,
82  sizeof ( manufacturer ) );
83  if ( strcmp ( manufacturer, dell ) != 0 )
84  return 0;
85 
86  return 1;
87 }
const char * name
Definition: ath9k_hw.c:1984
EFI_COMPONENT_NAME_GET_DRIVER_NAME GetDriverName
unsigned short CHAR16
Definition: ProcessorBind.h:59
int fetch_string_setting(struct settings *settings, const struct setting *setting, char *data, size_t len)
Fetch value of string setting.
Definition: settings.c:845
uint8_t manufacturer
Manufacturer string.
Definition: smbios.h:14
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:157
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:98
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

◆ efi_blacklist()

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.

105  {
107  union {
109  void *interface;
110  } binding;
111  union {
113  void *interface;
114  } loaded;
115  union {
117  void *interface;
118  } wtf;
119  unsigned int i;
121  EFI_STATUS efirc;
122  int rc;
123 
124  DBGC2 ( &efi_blacklists, "EFIBL checking %s\n",
125  efi_handle_name ( driver ) );
126 
127  /* Mark as not blacklisted */
128  *blacklist = NULL;
129 
130  /* Open driver binding protocol */
131  if ( ( efirc = bs->OpenProtocol (
133  &binding.interface, efi_image_handle, driver,
134  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
135  rc = -EEFI ( efirc );
136  DBGC ( driver, "EFIBL %s could not open driver binding "
137  "protocol: %s\n", efi_handle_name ( driver ),
138  strerror ( rc ) );
139  goto err_binding;
140  }
141  image = binding.binding->ImageHandle;
142 
143  /* Open loaded image protocol */
144  if ( ( efirc = bs->OpenProtocol (
146  &loaded.interface, efi_image_handle, image,
147  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
148  rc = -EEFI ( efirc );
149  DBGC ( driver, "EFIBL %s could not open",
150  efi_handle_name ( driver ) );
151  DBGC ( driver, " %s loaded image protocol: %s\n",
152  efi_handle_name ( image ), strerror ( rc ) );
153  goto err_loaded;
154  }
155 
156  /* Open component name protocol, if present*/
157  if ( ( efirc = bs->OpenProtocol (
159  &wtf.interface, efi_image_handle, driver,
160  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
161  /* Ignore failure; is not required to be present */
162  wtf.interface = NULL;
163  }
164 
165  /* Check blacklistings */
166  for ( i = 0 ; i < ( sizeof ( efi_blacklists ) /
167  sizeof ( efi_blacklists[0] ) ) ; i++ ) {
168  if ( efi_blacklists[i].blacklist ( binding.binding,
169  loaded.loaded, wtf.wtf ) ) {
170  *blacklist = &efi_blacklists[i];
171  break;
172  }
173  }
174 
175  /* Success */
176  rc = 0;
177 
178  /* Close protocols */
179  if ( wtf.wtf ) {
181  efi_image_handle, driver );
182  }
185  err_loaded:
187  efi_image_handle, driver );
188  err_binding:
189  return rc;
190 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
This protocol is used to retrieve user readable names of drivers and controllers managed by UEFI Driv...
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:157
#define DBGC(...)
Definition: compiler.h:505
EFI_GUID efi_loaded_image_protocol_guid
Loaded image protocol GUID.
Definition: efi_guid.c:184
An executable image.
Definition: image.h:24
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
Can be used on any image handle to obtain information about the loaded image.
Definition: LoadedImage.h:51
An object interface.
Definition: interface.h:109
static struct efi_blacklist efi_blacklists[]
Blacklisted drivers.
Definition: efi_blacklist.c:90
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
This protocol provides the services required to determine if a driver supports a given controller.
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
EFI_GUID efi_component_name_protocol_guid
Component name protocol GUID.
Definition: efi_guid.c:120
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:148
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:55

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_unload_blacklist()

void efi_unload_blacklist ( void  )

Unload any blacklisted drivers.

Definition at line 196 of file efi_blacklist.c.

196  {
198  struct efi_blacklist *blacklist;
199  EFI_HANDLE *drivers;
200  EFI_HANDLE driver;
201  UINTN num_drivers;
202  unsigned int i;
203  EFI_STATUS efirc;
204  int rc;
205 
206  /* Locate all driver binding protocol handles */
207  if ( ( efirc = bs->LocateHandleBuffer (
209  NULL, &num_drivers, &drivers ) ) != 0 ) {
210  rc = -EEFI ( efirc );
211  DBGC ( &efi_blacklists, "EFIBL could not list all drivers: "
212  "%s\n", strerror ( rc ) );
213  return;
214  }
215 
216  /* Unload any blacklisted drivers */
217  for ( i = 0 ; i < num_drivers ; i++ ) {
218  driver = drivers[i];
219  if ( ( rc = efi_blacklist ( driver, &blacklist ) ) != 0 ) {
220  DBGC ( driver, "EFIBL could not determine "
221  "blacklisting for %s: %s\n",
222  efi_handle_name ( driver ), strerror ( rc ) );
223  continue;
224  }
225  if ( ! blacklist )
226  continue;
227  DBGC ( driver, "EFIBL unloading %s (%s)\n",
228  efi_handle_name ( driver ), blacklist->name );
229  if ( ( efirc = bs->UnloadImage ( driver ) ) != 0 ) {
230  DBGC ( driver, "EFIBL could not unload %s: %s\n",
231  efi_handle_name ( driver ), strerror ( rc ) );
232  }
233  }
234 
235  /* Free handle list */
236  bs->FreePool ( drivers );
237 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:157
#define DBGC(...)
Definition: compiler.h:505
EFI_IMAGE_UNLOAD UnloadImage
Definition: UefiSpec.h:1886
A blacklisted driver.
Definition: efi_blacklist.c:39
static struct efi_blacklist efi_blacklists[]
Blacklisted drivers.
Definition: efi_blacklist.c:90
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int(* blacklist)(EFI_DRIVER_BINDING_PROTOCOL *binding, EFI_LOADED_IMAGE_PROTOCOL *loaded, EFI_COMPONENT_NAME_PROTOCOL *wtf)
Check if driver is blacklisted.
Definition: efi_blacklist.c:50
EFI Boot Services Table.
Definition: UefiSpec.h:1836
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1448
EFI_SYSTEM_TABLE * efi_systab
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:148
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:55
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:1913

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

Referenced by efi_probe().

Variable Documentation

◆ efi_blacklists

struct efi_blacklist efi_blacklists[]
static
Initial value:
= {
{
.name = "Dell Ip4Config",
},
}
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.
Definition: efi_blacklist.c:64

Blacklisted drivers.

Definition at line 90 of file efi_blacklist.c.

Referenced by efi_blacklist(), and efi_unload_blacklist().