Commit Graph

6992 Commits

Author SHA1 Message Date
Michael Brown
a4b5dd63c5 [riscv] Split out runtime relocator to libprefix.S
Split out the runtime relocation logic from sbiprefix.S to a new
library libprefix.S.

Since this logically decouples the process of runtime relocation from
the _sbi_start symbol (currently used to determine the base address
for applying relocations), provide an alternative mechanism for the
relocator to determine the base address.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-05-01 14:36:26 +01:00
Michael Brown
1534b0a6e9 [uaccess] Remove redundant virt_to_user() and userptr_t
Remove the last remaining traces of the concept of a user pointer,
leaving iPXE with a simpler and cleaner memory model that implicitly
assumes that all memory locations can be reached through pointer
dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-30 16:26:16 +01:00
Michael Brown
a169d73593 [uaccess] Reduce scope of included uaccess.h header
The uaccess.h header is no longer required for any code that touches
external ("user") memory, since such memory accesses are now performed
through pointer dereferences.  Reduce the number of files including
this header.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-30 16:16:02 +01:00
Michael Brown
05ad7833c5 [image] Make image data read-only to most consumers
Almost all image consumers do not need to modify the content of the
image.  Now that the image data is a pointer type (rather than the
opaque userptr_t type), we can rely on the compiler to enforce this at
build time.

Change the .data field to be a const pointer, so that the compiler can
verify that image consumers do not modify the image content.  Provide
a transparent .rwdata field for consumers who have a legitimate (and
now explicit) reason to modify the image content.

We do not attempt to impose any runtime restriction on checking
whether or not an image is writable.  The only existing instances of
genuinely read-only images are the various unit test images, and it is
acceptable for defective test cases to result in a segfault rather
than a runtime error.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-30 15:38:15 +01:00
Michael Brown
cd803ff2e2 [image] Add the concept of a static image
Not all images are allocated via alloc_image().  For example: embedded
images, the static images created to hold a runtime command line, and
the images used by unit tests are all static structures.

Using image_set_cmdline() (via e.g. the "imgargs" command) to set the
command-line arguments of a static image will succeed but will leak
memory, since nothing will ever free the allocated command line.
There are no code paths that can lead to calling image_set_len() on a
static image, but there is no safety check against future code paths
attempting this.

Define a flag IMAGE_STATIC to mark an image as statically allocated,
generalise free_image() to also handle freeing dynamically allocated
portions of static images (such as the command line), and expose
free_image() for use by static images.

Define a related flag IMAGE_STATIC_NAME to mark the name as statically
allocated.  Allow a statically allocated name to be replaced with a
dynamically allocated name since this is a potentially valid use case
(e.g. if "imgdecrypt --name <name>" is used on an embedded image).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-30 15:38:15 +01:00
Michael Brown
3303910010 [image] Move embedded images from .rodata to .data
Decrypting a CMS-encrypted image will overwrite the existing image
data in place, and using an encrypted embedded image is a valid use
case.

Move embedded images from .rodata to .data to reflect the fact that
they are intended to be writable.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-30 15:38:15 +01:00
Michael Brown
2d9a6369dd [test] Separate read-only and writable CMS test images
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-30 15:38:15 +01:00
Michael Brown
b6f9e4bab0 [uaccess] Remove redundant copy_from_user() and copy_to_user()
Remove the now-redundant copy_from_user() and copy_to_user() wrapper
functions.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-30 15:32:03 +01:00
Michael Brown
a69c42dd9f [image] Clear recorded replacement image immediately after consuming
If an embedded script uses "chain --replace", the embedded image will
retain a reference to the replacement image in perpetuity.

Fix by clearing any recorded replacement image immediately in
image_exec(), instead of relying upon image_free() to drop the
reference.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-29 16:32:01 +01:00
Michael Brown
9962c0a58f [bofm] Remove userptr_t from BOFM table parsing and updating
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-29 13:42:42 +01:00
Michael Brown
0800723845 [bofm] Allow BOFM tests to be run without a BOFM-capable device driver
The BOFM tests are not part of the standard unit test suite, since
they are designed to allow for exercising real BOFM driver code
outside of the context of a real IBM blade server.

Allow for the BOFM tests to be run without a real BOFM driver, by
providing a dummy driver for the specified PCI test device.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-29 13:39:12 +01:00
Michael Brown
4e909cc2b0 [build] Remove some long-obsolete unused header files
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-29 12:17:16 +01:00
Michael Brown
6c9dc063f6 [peerdist] Remove never-used peerdist_msg_blk() macro
The peerdist_msg_blk() macro seems to have been introduced in the
original commit that added pccrr.h, but this macro was never used by
the version of the code present in that commit.

Remove this unused macro and the corresponding nonexistent external
function declaration.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-29 12:08:33 +01:00
Michael Brown
54c4217bdd [peerdist] Remove userptr_t from PeerDist content information parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-29 11:28:45 +01:00
Michael Brown
837b77293b [xferbuf] Simplify and generalise data transfer buffers
Since all data transfer buffer contents are now accessible via direct
pointer dereferences, remove the unnecessary abstractions for read and
write operations and create two new data transfer buffer types: a
fixed-size buffer, and a void buffer that records its size but can
never receive non-zero lengths of data.  These replace the custom data
buffer types currently implemented for EFI PXE TFTP downloads and for
block device translations.

A new operation xferbuf_detach() is required to take ownership of the
data accumulated in the data transfer buffer, since we no longer rely
on the existence of an independently owned external data pointer for
data transfer buffers allocated via umalloc().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-29 11:27:22 +01:00
Michael Brown
43fc516298 [prefix] Remove userptr_t from command line image construction
Simplify cmdline_init() by assuming that the externally provided
command line is directly accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-29 00:30:34 +01:00
Michael Brown
c9fb94dbaa [comboot] Remove userptr_t from COM32 API implementation
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-29 00:24:55 +01:00
Michael Brown
f001e61a68 [comboot] Remove userptr_t from COMBOOT API implementation
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 22:50:23 +01:00
Michael Brown
ef97119589 [comboot] Remove userptr_t from COMBOOT image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 22:31:18 +01:00
Michael Brown
0b45db3972 [uaccess] Remove redundant UNULL definition
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 17:36:18 +01:00
Michael Brown
6ccb6bcfc8 [bzimage] Remove userptr_t from bzImage parsing
Simplify bzImage parsing by assuming that the various headers are
directly accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 16:30:35 +01:00
Michael Brown
412ad56012 [initrd] Use physical addresses for calculations on initrd locations
Commit ef03849 ("[uaccess] Remove redundant userptr_add() and
userptr_diff()") exposed a signedness bug in the comparison of initrd
locations, since the expression (initrd->data - current) was
effectively no longer coerced to a signed type.

In particular, the common case will be that the top of the initrd
region is the start of the iPXE .textdata region, which has virtual
address zero.  This causes initrd->data to compare as being above the
top of the initrd region for all images, when this bug would
previously have been limited to affecting only initrds placed 2GB or
more below the start of .textdata.

Fix by using physical addresses for all comparisons on initrd
locations.

Reported-by: Sven Dreyer <sven@dreyer-net.de>
Reported-by: Harald Jensås <hjensas@redhat.com>
Reported-by: Jan ONDREJ (SAL) <ondrejj@salstar.sk>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 15:35:55 +01:00
Michael Brown
ef3827cf14 [bzimage] Use image name in debug messages
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 14:43:19 +01:00
Michael Brown
083e273bbc [efi] Add ability to reboot to firmware setup menu
Add the ability to reboot to the firmware setup menu (if supported) by
setting the relevant value in the OsIndications variable.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 14:01:17 +01:00
Michael Brown
7eaa2daf6f [reboot] Generalise warm reboot indicator to a flags bitmask
Allow for the possibility of additional reboot types by extending the
reboot() function to use a flags bitmask rather than a single flag.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 13:44:53 +01:00
Michael Brown
ba2135d0fd [multiboot] Remove userptr_t from Multiboot and ELF image parsing
Simplify Multiboot and ELF image parsing by assuming that the
Multiboot and ELF headers are directly accessible via pointer
dereferences, and add some missing header validations.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 13:06:18 +01:00
Michael Brown
c8c5cd685f [multiboot] Use image name in Multiboot and ELF debug messages
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-28 12:59:25 +01:00
Michael Brown
3befb5eb57 [linux] Enable compiler warnings when building the linux_api.o object
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-27 23:36:34 +01:00
Michael Brown
024439f339 [linux] Add missing return statement to linux_poll()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-27 23:28:51 +01:00
Michael Brown
bd4ca67cf4 [build] Disable gcc unterminated-string-initializer warnings
GCC 15 generates a warning when a string initializer is too large to
allow for a trailing NUL terminator byte.  This type of initializer is
fairly common in signature strings such as ACPI table identifiers.

Fix by disabling the warning.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-27 18:40:52 +01:00
Michael Brown
15c1111c78 [build] Remove unsafe disable function wrapper from legacy NIC drivers
The legacy NIC drivers do not consistently take a second parameter in
their disable function.  We currently use an unsafe function wrapper
that declares no parameters, and rely on the ABI allowing a second
parameter to be silently ignored if not expected by the caller.  As of
GCC 15, this hack results in an incompatible pointer type warning.

Fix by removing the hack, and instead updating all relevant legacy NIC
drivers to take an unused second parameter in their disable function.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-27 18:40:52 +01:00
Miao Wang
7741756afc [build] Prevent the use of reserved words in C23
GCC 15 defaults to C23, which reserves bool, true, and false as
keywords.  Avoid using these as parameter or variable names.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-27 18:40:33 +01:00
Michael Brown
b816b816ab [build] Fix old-style function definition
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-27 18:40:03 +01:00
Michael Brown
58e6729cb6 [build] Fix typo in xenver.h header guard
GCC 15 helpfully reports mismatched #ifdef and #define lines in header
guards.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-27 18:40:03 +01:00
Michael Brown
4c8bf666f4 [pnm] Remove userptr_t from PNM image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-25 17:23:37 +01:00
Michael Brown
d29651ddec [png] Remove userptr_t from PNG image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-25 16:43:11 +01:00
Michael Brown
76a17b0986 [fbcon] Avoid redrawing unchanged characters when scrolling
Scrolling currently involves redrawing every character cell, which can
be frustratingly slow on large framebuffer consoles.  Accelerate this
operation by skipping the redraw for any unchanged character cells.

In the common case that large areas of the screen contain whitespace,
this optimises away the vast majority of the redrawing operations.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-25 13:44:18 +01:00
Michael Brown
aa3cc56ab2 [fbcon] Remove userptr_t from framebuffer console drivers
Simplify the framebuffer console drivers by assuming that the raw
framebuffer, character cell array, background picture, and glyph data
are all directly accessible via pointer dereferences.

In particular, this avoids the need to copy each glyph during drawing:
the VESA framebuffer driver can simply return a pointer to the glyph
data stored in the video ROM.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-25 12:44:28 +01:00
Michael Brown
4cca1cadf8 [efi] Remove userptr_t from EFI PE image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-25 00:49:27 +01:00
Michael Brown
338cebfeef [pxe] Remove userptr_t from PXE file API implementation
Simplify the PXE file API implementation by assuming that all string
buffers are directly accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-25 00:43:30 +01:00
Michael Brown
8b3b4f2454 [pxe] Remove userptr_t from PXE API call dispatcher
Simplify the PXE API call dispatcher code by assuming that the PXE
parameter block is accessible via a direct pointer dereference.  This
avoids the need for the API call dispatcher to know the size of the
parameter block.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 23:38:50 +01:00
Michael Brown
c1b558f59e [cmdline] Remove userptr_t from "digest" command
Simplify the implementation of the "digest" command by assuming that
the entire image data can be passed directly to digest_update().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 23:24:29 +01:00
Michael Brown
0edbc4c082 [nbi] Remove userptr_t from NBI image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 23:17:16 +01:00
Michael Brown
3cb33435f5 [sdi] Remove userptr_t from SDI image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 23:01:25 +01:00
Michael Brown
d7c94c4aa5 [pxe] Remove userptr_t from PXE NBP image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 22:46:50 +01:00
Michael Brown
2f11f466e6 [block] Remove userptr_t from block device abstraction
Simplify the block device code by assuming that all read/write buffers
are directly accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 17:11:30 +01:00
Michael Brown
2742ed5d77 [uaccess] Remove now-obsolete memchr_user()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 16:35:49 +01:00
Michael Brown
4f4f6c33ec [script] Remove userptr_t from script image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 16:28:32 +01:00
Michael Brown
8923a216b0 [ucode] Remove userptr_t from microcode image parsing
Simplify microcode image parsing by assuming that all image content is
directly accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 14:25:00 +01:00
Michael Brown
605cff4c84 [ucode] Remove userptr_t from microcode update mechanism
Simplify the microcode update mechanism by assuming that status
reports are accessible via direct pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 13:48:57 +01:00