6 Commits
Author SHA1 Message Date
Michael Brown e86398d364 WIP - cleaner MTU change 2023-03-14 13:37:24 +00:00
Michael Brown 8f1c120119 [dhcp] Unregister ProxyDHCP and PXEBS settings on a successful DHCPACK
When a DHCP transaction does not result in the registration of a new
"proxydhcp" or "pxebs" settings block, any existing settings blocks
are currently left unaltered.

This can cause surprising behaviour.  For example: when chainloading
iPXE, the "proxydhcp" and "pxebs" settings blocks may be prepopulated
using cached values from the previous PXE bootloader.  If iPXE
performs a subsequent DHCP request, then the DHCP or ProxyDHCP servers
may choose to respond differently to iPXE.  The response may choose to
omit the ProxyDHCP or PXEBS stages, in which case no new "proxydhcp"
or "pxebs" settings blocks may be registered.  This will result in
iPXE using a combination of both old and new DHCP responses.

Fix by assuming that a successful DHCPACK effectively acquires
ownership of the "proxydhcp" and "pxebs" settings blocks, and that any
existing settings blocks should therefore be unregistered.

Reported-by: Henry Tung <htung@palantir.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2023-03-14 11:35:30 +00:00
Michael Brown 54fcb7c29c [efi] Use image name instead of pointer value in debug messages
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2023-03-07 14:18:00 +00:00
Michael Brown 9e1f7a3659 [image] Always unregister currently executing image
We unregister script images during their execution, to prevent a
"boot" command from re-executing the containing script.  This also has
the side effect of preventing executing scripts from showing up within
the Linux magic initrd image (or the Multiboot module list).

Additional logic in bzimage.c and efi_file.c prevents a currently
executing kernel from showing up within the magic initrd image.
Similar logic in multiboot.c prevents the Multiboot kernel from
showing up as a Multiboot module.

This still leaves some corner cases that are not covered correctly.
For example: when using a gzip-compressed kernel image, nothing will
currently hide the original compressed image from the magic initrd.

Fix by moving the logic that temporarily unregisters the current image
from script_exec() to image_exec(), so that it applies to all image
types, and simplify the magic initrd and Multiboot module list
construction logic on the basis that no further filtering of the
registered image list is necessary.

This change has the side effect of hiding currently executing EFI
images from the virtual filesystem exposed by iPXE.  For example, when
using iPXE to boot wimboot, the wimboot binary itself will no longer
be visible within the virtual filesystem.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2023-03-07 12:22:19 +00:00
Michael Brown e51e7bbad7 [image] Consistently use for_each_image() to iterate over images
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2023-03-06 16:56:37 +00:00
Forest Crossman 523788ccda [intelx] Add PCI IDs for Intel 82599 10GBASE-T NIC
Signed-off-by: Forest Crossman <cyrozap@gmail.com>
2023-03-05 18:22:18 -06:00
12 changed files with 106 additions and 70 deletions
-8
View File
@@ -355,10 +355,6 @@ static size_t bzimage_load_initrd ( struct image *image,
size_t offset; size_t offset;
size_t pad_len; size_t pad_len;
/* Do not include kernel image itself as an initrd */
if ( initrd == image )
return 0;
/* Create cpio header for non-prebuilt images */ /* Create cpio header for non-prebuilt images */
offset = cpio_header ( initrd, &cpio ); offset = cpio_header ( initrd, &cpio );
@@ -406,10 +402,6 @@ static int bzimage_check_initrds ( struct image *image,
/* Calculate total loaded length of initrds */ /* Calculate total loaded length of initrds */
for_each_image ( initrd ) { for_each_image ( initrd ) {
/* Skip kernel */
if ( initrd == image )
continue;
/* Calculate length */ /* Calculate length */
len += bzimage_load_initrd ( image, initrd, UNULL ); len += bzimage_load_initrd ( image, initrd, UNULL );
len = bzimage_align ( len ); len = bzimage_align ( len );
-4
View File
@@ -204,10 +204,6 @@ static int multiboot_add_modules ( struct image *image, physaddr_t start,
break; break;
} }
/* Do not include kernel image itself as a module */
if ( module_image == image )
continue;
/* Page-align the module */ /* Page-align the module */
start = ( ( start + 0xfff ) & ~0xfff ); start = ( ( start + 0xfff ) & ~0xfff );
+10 -4
View File
@@ -312,7 +312,7 @@ void unregister_image ( struct image *image ) {
struct image * find_image ( const char *name ) { struct image * find_image ( const char *name ) {
struct image *image; struct image *image;
list_for_each_entry ( image, &images, list ) { for_each_image ( image ) {
if ( strcmp ( image->name, name ) == 0 ) if ( strcmp ( image->name, name ) == 0 )
return image; return image;
} }
@@ -349,9 +349,8 @@ int image_exec ( struct image *image ) {
/* Preserve record of any currently-running image */ /* Preserve record of any currently-running image */
saved_current_image = current_image; saved_current_image = current_image;
/* Take out a temporary reference to the image. This allows /* Take out a temporary reference to the image, so that it
* the image to unregister itself if necessary, without * does not get freed when temporarily unregistered.
* automatically freeing itself.
*/ */
current_image = image_get ( image ); current_image = image_get ( image );
@@ -371,6 +370,9 @@ int image_exec ( struct image *image ) {
/* Record boot attempt */ /* Record boot attempt */
syslog ( LOG_NOTICE, "Executing \"%s\"\n", image->name ); syslog ( LOG_NOTICE, "Executing \"%s\"\n", image->name );
/* Temporarily unregister the image during its execution */
unregister_image ( image );
/* Try executing the image */ /* Try executing the image */
if ( ( rc = image->type->exec ( image ) ) != 0 ) { if ( ( rc = image->type->exec ( image ) ) != 0 ) {
DBGC ( image, "IMAGE %s could not execute: %s\n", DBGC ( image, "IMAGE %s could not execute: %s\n",
@@ -387,6 +389,10 @@ int image_exec ( struct image *image ) {
image->name, strerror ( rc ) ); image->name, strerror ( rc ) );
} }
/* Re-register image (unless due to be replaced) */
if ( ! image->replacement )
register_image ( image );
/* Pick up replacement image before we drop the original /* Pick up replacement image before we drop the original
* image's temporary reference. The replacement image must * image's temporary reference. The replacement image must
* already be registered, so we don't need to hold a temporary * already be registered, so we don't need to hold a temporary
+1
View File
@@ -473,6 +473,7 @@ static struct pci_device_id intelx_nics[] = {
PCI_ROM ( 0x8086, 0x10f9, "82599-cx4", "82599 (CX4)", 0 ), PCI_ROM ( 0x8086, 0x10f9, "82599-cx4", "82599 (CX4)", 0 ),
PCI_ROM ( 0x8086, 0x10fb, "82599-sfp", "82599 (SFI/SFP+)", 0 ), PCI_ROM ( 0x8086, 0x10fb, "82599-sfp", "82599 (SFI/SFP+)", 0 ),
PCI_ROM ( 0x8086, 0x10fc, "82599-xaui", "82599 (XAUI/BX4)", 0 ), PCI_ROM ( 0x8086, 0x10fc, "82599-xaui", "82599 (XAUI/BX4)", 0 ),
PCI_ROM ( 0x8086, 0x151c, "82599-tn", "82599 (TN)", 0 ),
PCI_ROM ( 0x8086, 0x1528, "x540t", "X540-AT2/X540-BT2", 0 ), PCI_ROM ( 0x8086, 0x1528, "x540t", "X540-AT2/X540-BT2", 0 ),
PCI_ROM ( 0x8086, 0x154d, "82599-sfp-sf2", "82599 (SFI/SFP+)", 0 ), PCI_ROM ( 0x8086, 0x154d, "82599-sfp-sf2", "82599 (SFI/SFP+)", 0 ),
PCI_ROM ( 0x8086, 0x1557, "82599en-sfp", "82599 (Single Port SFI Only)", 0 ), PCI_ROM ( 0x8086, 0x1557, "82599en-sfp", "82599 (Single Port SFI Only)", 0 ),
+3 -10
View File
@@ -852,16 +852,9 @@ static int netvsc_reset ( struct vmbus_device *vmdev ) {
struct net_device *netdev = rndis->netdev; struct net_device *netdev = rndis->netdev;
int rc; int rc;
/* A closed device holds no NetVSC (or RNDIS) state, so there /* Reset network device */
* is nothing to reset. if ( ( rc = netdev_reset ( netdev ) ) != 0 ) {
*/ DBGC ( netvsc, "NETVSC %s could not reset: %s\n",
if ( ! netdev_is_open ( netdev ) )
return 0;
/* Close and reopen device to reset any stale state */
netdev_close ( netdev );
if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
DBGC ( netvsc, "NETVSC %s could not reopen: %s\n",
netvsc->name, strerror ( rc ) ); netvsc->name, strerror ( rc ) );
return rc; return rc;
} }
+21 -21
View File
@@ -147,38 +147,38 @@ static int efi_image_exec ( struct image *image ) {
/* Find an appropriate device handle to use */ /* Find an appropriate device handle to use */
snpdev = last_opened_snpdev(); snpdev = last_opened_snpdev();
if ( ! snpdev ) { if ( ! snpdev ) {
DBGC ( image, "EFIIMAGE %p could not identify SNP device\n", DBGC ( image, "EFIIMAGE %s could not identify SNP device\n",
image ); image->name );
rc = -ENODEV; rc = -ENODEV;
goto err_no_snpdev; goto err_no_snpdev;
} }
/* Install file I/O protocols */ /* Install file I/O protocols */
if ( ( rc = efi_file_install ( snpdev->handle ) ) != 0 ) { if ( ( rc = efi_file_install ( snpdev->handle ) ) != 0 ) {
DBGC ( image, "EFIIMAGE %p could not install file protocol: " DBGC ( image, "EFIIMAGE %s could not install file protocol: "
"%s\n", image, strerror ( rc ) ); "%s\n", image->name, strerror ( rc ) );
goto err_file_install; goto err_file_install;
} }
/* Install PXE base code protocol */ /* Install PXE base code protocol */
if ( ( rc = efi_pxe_install ( snpdev->handle, snpdev->netdev ) ) != 0 ){ if ( ( rc = efi_pxe_install ( snpdev->handle, snpdev->netdev ) ) != 0 ){
DBGC ( image, "EFIIMAGE %p could not install PXE protocol: " DBGC ( image, "EFIIMAGE %s could not install PXE protocol: "
"%s\n", image, strerror ( rc ) ); "%s\n", image->name, strerror ( rc ) );
goto err_pxe_install; goto err_pxe_install;
} }
/* Install iPXE download protocol */ /* Install iPXE download protocol */
if ( ( rc = efi_download_install ( snpdev->handle ) ) != 0 ) { if ( ( rc = efi_download_install ( snpdev->handle ) ) != 0 ) {
DBGC ( image, "EFIIMAGE %p could not install iPXE download " DBGC ( image, "EFIIMAGE %s could not install iPXE download "
"protocol: %s\n", image, strerror ( rc ) ); "protocol: %s\n", image->name, strerror ( rc ) );
goto err_download_install; goto err_download_install;
} }
/* Create device path for image */ /* Create device path for image */
path = efi_image_path ( image, snpdev->path ); path = efi_image_path ( image, snpdev->path );
if ( ! path ) { if ( ! path ) {
DBGC ( image, "EFIIMAGE %p could not create device path\n", DBGC ( image, "EFIIMAGE %s could not create device path\n",
image ); image->name );
rc = -ENOMEM; rc = -ENOMEM;
goto err_image_path; goto err_image_path;
} }
@@ -186,8 +186,8 @@ static int efi_image_exec ( struct image *image ) {
/* Create command line for image */ /* Create command line for image */
cmdline = efi_image_cmdline ( image ); cmdline = efi_image_cmdline ( image );
if ( ! cmdline ) { if ( ! cmdline ) {
DBGC ( image, "EFIIMAGE %p could not create command line\n", DBGC ( image, "EFIIMAGE %s could not create command line\n",
image ); image->name );
rc = -ENOMEM; rc = -ENOMEM;
goto err_cmdline; goto err_cmdline;
} }
@@ -199,8 +199,8 @@ static int efi_image_exec ( struct image *image ) {
image->len, &handle ) ) != 0 ) { image->len, &handle ) ) != 0 ) {
/* Not an EFI image */ /* Not an EFI image */
rc = -EEFI_LOAD ( efirc ); rc = -EEFI_LOAD ( efirc );
DBGC ( image, "EFIIMAGE %p could not load: %s\n", DBGC ( image, "EFIIMAGE %s could not load: %s\n",
image, strerror ( rc ) ); image->name, strerror ( rc ) );
if ( efirc == EFI_SECURITY_VIOLATION ) { if ( efirc == EFI_SECURITY_VIOLATION ) {
goto err_load_image_security_violation; goto err_load_image_security_violation;
} else { } else {
@@ -220,8 +220,8 @@ static int efi_image_exec ( struct image *image ) {
/* Some EFI 1.10 implementations seem not to fill in DeviceHandle */ /* Some EFI 1.10 implementations seem not to fill in DeviceHandle */
if ( loaded.image->DeviceHandle == NULL ) { if ( loaded.image->DeviceHandle == NULL ) {
DBGC ( image, "EFIIMAGE %p filling in missing DeviceHandle\n", DBGC ( image, "EFIIMAGE %s filling in missing DeviceHandle\n",
image ); image->name );
loaded.image->DeviceHandle = snpdev->handle; loaded.image->DeviceHandle = snpdev->handle;
} }
@@ -251,14 +251,14 @@ static int efi_image_exec ( struct image *image ) {
/* Start the image */ /* Start the image */
if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) { if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) {
rc = -EEFI_START ( efirc ); rc = -EEFI_START ( efirc );
DBGC ( image, "EFIIMAGE %p could not start (or returned with " DBGC ( image, "EFIIMAGE %s could not start (or returned with "
"error): %s\n", image, strerror ( rc ) ); "error): %s\n", image->name, strerror ( rc ) );
goto err_start_image; goto err_start_image;
} }
/* If image was a driver, connect it up to anything available */ /* If image was a driver, connect it up to anything available */
if ( type == EfiBootServicesCode ) { if ( type == EfiBootServicesCode ) {
DBGC ( image, "EFIIMAGE %p connecting drivers\n", image ); DBGC ( image, "EFIIMAGE %s connecting drivers\n", image->name );
efi_driver_reconnect_all(); efi_driver_reconnect_all();
} }
@@ -324,8 +324,8 @@ static int efi_image_probe ( struct image *image ) {
image->len, &handle ) ) != 0 ) { image->len, &handle ) ) != 0 ) {
/* Not an EFI image */ /* Not an EFI image */
rc = -EEFI_LOAD ( efirc ); rc = -EEFI_LOAD ( efirc );
DBGC ( image, "EFIIMAGE %p could not load: %s\n", DBGC ( image, "EFIIMAGE %s could not load: %s\n",
image, strerror ( rc ) ); image->name, strerror ( rc ) );
if ( efirc == EFI_SECURITY_VIOLATION ) { if ( efirc == EFI_SECURITY_VIOLATION ) {
goto err_load_image_security_violation; goto err_load_image_security_violation;
} else { } else {
-9
View File
@@ -197,11 +197,6 @@ static int script_exec ( struct image *image ) {
size_t saved_offset; size_t saved_offset;
int rc; int rc;
/* Temporarily de-register image, so that a "boot" command
* doesn't throw us into an execution loop.
*/
unregister_image ( image );
/* Preserve state of any currently-running script */ /* Preserve state of any currently-running script */
saved_offset = script_offset; saved_offset = script_offset;
@@ -212,10 +207,6 @@ static int script_exec ( struct image *image ) {
/* Restore saved state */ /* Restore saved state */
script_offset = saved_offset; script_offset = saved_offset;
/* Re-register image (unless we have been replaced) */
if ( ! image->replacement )
register_image ( image );
return rc; return rc;
} }
+1
View File
@@ -723,6 +723,7 @@ extern struct net_device * alloc_netdev ( size_t priv_size );
extern int register_netdev ( struct net_device *netdev ); extern int register_netdev ( struct net_device *netdev );
extern int netdev_open ( struct net_device *netdev ); extern int netdev_open ( struct net_device *netdev );
extern void netdev_close ( struct net_device *netdev ); extern void netdev_close ( struct net_device *netdev );
extern int netdev_reset ( struct net_device *netdev );
extern void unregister_netdev ( struct net_device *netdev ); extern void unregister_netdev ( struct net_device *netdev );
extern void netdev_irq ( struct net_device *netdev, int enable ); extern void netdev_irq ( struct net_device *netdev, int enable );
extern struct net_device * find_netdev ( const char *name ); extern struct net_device * find_netdev ( const char *name );
+2 -6
View File
@@ -130,7 +130,7 @@ static struct image * efi_file_find ( const char *name ) {
struct image *image; struct image *image;
/* Find image */ /* Find image */
list_for_each_entry ( image, &images, list ) { for_each_image ( image ) {
if ( strcasecmp ( image->name, name ) == 0 ) if ( strcasecmp ( image->name, name ) == 0 )
return image; return image;
} }
@@ -240,10 +240,6 @@ static size_t efi_file_read_initrd ( struct efi_file_reader *reader ) {
len = 0; len = 0;
for_each_image ( image ) { for_each_image ( image ) {
/* Ignore currently executing image */
if ( image == current_image )
continue;
/* Pad to alignment boundary */ /* Pad to alignment boundary */
pad_len = ( ( -reader->pos ) & ( INITRD_ALIGN - 1 ) ); pad_len = ( ( -reader->pos ) & ( INITRD_ALIGN - 1 ) );
if ( pad_len ) { if ( pad_len ) {
@@ -1091,7 +1087,7 @@ int efi_file_install ( EFI_HANDLE handle ) {
* instance only if the initrd is non-empty, since Linux does * instance only if the initrd is non-empty, since Linux does
* not gracefully handle a zero-length initrd. * not gracefully handle a zero-length initrd.
*/ */
load = ( list_is_singular ( &images ) ? NULL : &efi_file_initrd.load ); load = ( have_images() ? &efi_file_initrd.load : NULL );
if ( ( rc = efi_file_path_install ( &efi_file_initrd_path.vendor.Header, if ( ( rc = efi_file_path_install ( &efi_file_initrd_path.vendor.Header,
load ) ) != 0 ) { load ) ) != 0 ) {
goto err_initrd; goto err_initrd;
+3 -4
View File
@@ -453,11 +453,10 @@ static int apply_netdev_settings ( void ) {
netdev->name, mtu ); netdev->name, mtu );
} }
/* Close and reopen network device if MTU has increased */ /* Reset network device if MTU has increased */
if ( netdev_is_open ( netdev ) && ( mtu > old_mtu ) ) { if ( netdev_is_open ( netdev ) && ( mtu > old_mtu ) ) {
netdev_close ( netdev ); if ( ( rc = netdev_reset ( netdev ) ) != 0 ) {
if ( ( rc = netdev_open ( netdev ) ) != 0 ) { DBGC ( netdev, "NETDEV %s could not reset: "
DBGC ( netdev, "NETDEV %s could not reopen: "
"%s\n", netdev->name, strerror ( rc ) ); "%s\n", netdev->name, strerror ( rc ) );
return rc; return rc;
} }
+59 -4
View File
@@ -612,6 +612,23 @@ static void netdev_rx_flush ( struct net_device *netdev ) {
} }
} }
/**
* Flush device's transmit and receive queues
*
* @v netdev Network device
*/
static void netdev_flush ( struct net_device *netdev ) {
/* Sanity check */
assert ( ! ( netdev->state & NETDEV_OPEN ) );
/* Flush TX queue */
netdev_tx_flush ( netdev );
/* Flush RX queue */
netdev_rx_flush ( netdev );
}
/** /**
* Finish network device configuration * Finish network device configuration
* *
@@ -657,8 +674,7 @@ static void free_netdev ( struct refcnt *refcnt ) {
container_of ( refcnt, struct net_device, refcnt ); container_of ( refcnt, struct net_device, refcnt );
stop_timer ( &netdev->link_block ); stop_timer ( &netdev->link_block );
netdev_tx_flush ( netdev ); netdev_flush ( netdev );
netdev_rx_flush ( netdev );
clear_settings ( netdev_settings ( netdev ) ); clear_settings ( netdev_settings ( netdev ) );
free ( netdev ); free ( netdev );
} }
@@ -880,8 +896,47 @@ void netdev_close ( struct net_device *netdev ) {
netdev->op->close ( netdev ); netdev->op->close ( netdev );
/* Flush TX and RX queues */ /* Flush TX and RX queues */
netdev_tx_flush ( netdev ); netdev_flush ( netdev );
netdev_rx_flush ( netdev ); }
/**
* Reset transmit and receive queues
*
* @v netdev Network device
* @ret rc Return status code
*/
int netdev_reset ( struct net_device *netdev ) {
int rc;
/* Do nothing unless device is open */
if ( ! ( netdev->state & NETDEV_OPEN ) )
return 0;
DBGC ( netdev, "NETDEV %s resetting\n", netdev->name );
/* Mark as closed */
netdev->state &= ~NETDEV_OPEN;
/* Close the device */
netdev->op->close ( netdev );
/* Flush TX and RX queues */
netdev_flush ( netdev );
/* Mark as opened */
netdev->state |= NETDEV_OPEN;
/* Reopen device */
if ( ( rc = netdev->op->open ( netdev ) ) != 0 )
goto err;
return 0;
err:
netdev->state &= ~NETDEV_OPEN;
list_del ( &netdev->open_list );
netdev_notify ( netdev );
return rc;
} }
/** /**
+6
View File
@@ -601,6 +601,12 @@ static void dhcp_request_rx ( struct dhcp_session *dhcp,
return; return;
} }
/* Unregister any existing ProxyDHCP or PXEBS settings */
if ( ( settings = find_settings ( PROXYDHCP_SETTINGS_NAME ) ) != NULL )
unregister_settings ( settings );
if ( ( settings = find_settings ( PXEBS_SETTINGS_NAME ) ) != NULL )
unregister_settings ( settings );
/* Perform ProxyDHCP if applicable */ /* Perform ProxyDHCP if applicable */
if ( dhcp->proxy_offer /* Have ProxyDHCP offer */ && if ( dhcp->proxy_offer /* Have ProxyDHCP offer */ &&
( ! dhcp->no_pxedhcp ) /* ProxyDHCP not disabled */ ) { ( ! dhcp->no_pxedhcp ) /* ProxyDHCP not disabled */ ) {