Commit Graph

7499 Commits

Author SHA1 Message Date
Michael Brown 85700526ec [linux] Fix console output on big-endian targets
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-13 16:12:40 +01:00
Michael Brown e6e9ae9804 [efi] Fix parsing of EFI signature lists on big-endian targets
Though UEFI is fundamentally little-endian, the EFI signature list
image format is available even on non-EFI platforms (and is covered by
the unit test suite).

Add le32_to_cpu() macros as needed to allow EFI signature lists to be
parsed correctly on big-endian targets.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-13 16:11:29 +01:00
Michael Brown 6476f7c7c5 [peerdist] Fix segment identifier constant on big-endian targets
The "MS_P2P_CACHING" constant (used as part of the HMAC digest
calculation for the segment identifier) is a UTF-16LE string.  On a
big-endian target, a wide-character string literal will have the wrong
endianness.

Fix by using a byte array rather than a wide-character string.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-13 16:03:33 +01:00
Michael Brown bfdbd1c4e0 [build] Fix building for big-endian targets
Fix build errors that arise when building for a big-endian target such
as s390x.  (Runtime endianness errors may remain: this fixes only
those errors that are detected at build time.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-13 16:02:05 +01:00
Michael Brown e68ca57f46 [crypto] Use generic implementations of slow-path big integer functions
In the original big integer implementation, big integers were entirely
opaque to the caller and only the architecture-dependent code knew any
details of the internal structure.

This has long since ceased to be the case: for the sake of arithmetic
efficiency, many portions of the codebase now presume that big
integers are represented as an array of elements, with each element
being a native-endian unsigned value (with the precise type being
chosen by the architecture-specific header file) and with the least
significant element being first in the array.

The functions bigint_init(), bigint_done(), bigint_is_zero(),
bigint_is_geq(), and bigint_max_bit_set() are never used on fast code
paths, and most architectures use a generic C implementation of these
functions.

Provide generic implementations of these slow-path functions to be
used on all architectures.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-13 15:53:19 +01:00
Michael Brown 05a459f795 [iscsi] Ensure SCSI sense data is present before parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-09 15:10:04 +01:00
Michael Brown 95ffbf4745 [crypto] Add RFC 7919 FFDHE key exchange algorithms
We currently support fully parameterized finite field Diffie-Hellman
key exchange, where the peer provides not only its public key but also
the (fully arbitrary) selection of the field prime and generator.

RFC 7919 defines a family of finite fields all constructed from the
natural logarithm constant "e", intended to be used as well-known
fields where the peer simply names the field (e.g. "ffdhe2048") rather
than providing the raw prime and generator values.

Add support for this family of finite fields as key exchange
algorithms, to allow for protocols such as TLS version 1.3 where
parameterized fields are not permitted.

We choose to support only up to ffdhe4096, since this is sufficient to
exceed the security strength of our RNG (128 bits).

Support for ffdhe6144 and ffdhe8192 could trivially be added by simply
extending the "euler" constant and adding the relevant FFDHE_GROUP()
declarations.  Doing so would approximately double the space
requirements for both read-only data (from 0.5kB to 1kB) and for
uninitialised data (from 3.5kB to 7kB).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-09 14:00:18 +01:00
Michael Brown 6dcb3b1e67 [test] Allow for large values in key exchange self-tests
Allow for the existence of key exchange algorithms where the public
keys and shared secrets may be too large for a stack allocation.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-09 13:55:49 +01:00
Michael Brown f2ade220f9 [test] Verify test vector lengths for key exchange self-tests
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-09 13:51:13 +01:00
Michael Brown 36e8cc28c7 [crypto] Remove redundant ECDHE algorithm
Remove the now-unused implementation of ECDHE that requires an
underlying elliptic curve abstraction, since we now use a standalone
key exchange algorithm abstraction instead.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-06 16:53:04 +01:00
Michael Brown 5e427326ea [crypto] Remove elliptic curve abstraction for X25519
X25519 is defined as a key exchange algorithm, not as a generic
elliptic curve.  We have never supported arbitrary point addition on
the underlying curve, and we have never supported pure multiplication
(without the clamping defined in RFC7748, which modifies the scalar
multiple).

Now that we have an abstraction for key exchange that exists
independently of the elliptic curve abstraction, there are no further
consumers of the elliptic curve abstraction for X25519.  Remove this
redundant abstraction to simplify the codebase.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-06 16:53:04 +01:00
Michael Brown 3faae34685 [tls] Use generic key exchange algorithm abstraction for ECDHE
Remove any knowledge of elliptic curve point formats from the TLS
layer and use the generic key exchange algorithm abstraction instead.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-06 16:26:10 +01:00
Michael Brown 3bd8516e9b [crypto] Provide Weierstrass curves as generic key exchange algorithms
Provide the Weierstrass curves P-256 and P-384 as generic key exchange
algorithms (independent of the elliptic curve abstraction).  Only the
"uncompressed" point format is supported, and the knowledge of the
format byte is internalised within the key exchange algorithm so that
the caller can just treat all values as opaque byte strings.

Add a random selection of the NIST "ECC CDH Primitive (SP800-56A
Section 5.7.1.2)" key exchange test vectors.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-06 15:32:17 +01:00
Michael Brown 4dc99fc040 [crypto] Provide X25519 as a generic key exchange algorithm
Provide X25519 as a generic key exchange algorithm (independent of the
elliptic curve abstraction).

The existing RFC7748 test vectors are not structured in a way amenable
to treatment as a generic key exchange algorithm.  Retain these test
vectors unaltered for completeness, add the single "Alice/Bob" key
exchange example presented in RFC7748, and add a selection of test
vectors from Project Wycheproof (including some known edge cases).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-05 16:57:00 +01:00
Michael Brown 5179c22cde [crypto] Add a generic concept of a key exchange algorithm
TLS version 1.3 does not use static RSA or parameterized DHE for key
exchange: all key exchange algorithms are identified via a "named
group" enumeration and have predefined group parameters with fixed
input and output sizes.

Add an abstraction of a key exchange algorithm matching this usage
pattern, along with corresponding test support code.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-05 16:57:00 +01:00
Theodore Riera ce6ad2be02 [nfs] Fix off-by-one heap overflow in nfs_uri_symlink()
The length calculations in nfs_uri_symlink() omitted space for the
NUL terminator, causing strcpy() to write one byte past the heap
allocation.

Signed-off-by: Theodore Riera <warsang@hotmail.com>
2026-06-04 12:15:12 +01:00
Michael Brown e0a2ca984f [linux] Disable implicit linking against libatomic
GCC 16 attempts to link against -latomic_asneeded by default, and
expects that this library will be provided by the installed build
toolchain alongside libgcc.

The Fedora cross-gcc packages do not include libatomic, which causes
the build to fail.

We do not require any functions provided by libatomic.  Work around
the missing packaged files in Fedora by disabling gcc's implicit
linking via the -fno-link-libatomic build option.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-06-01 14:18:43 +01:00
Joseph Wong 409747f42c [tg3] Use updated DMA APIs
Replace malloc_phys with dma_alloc, free_phys with dma_free, alloc_iob
with alloc_rx_iob, free_iob with free_rx_iob, virt_to_bus with dma or
iob_dma.  Replace dma_addr_t with physaddr_t.

Signed-off-by: Joseph Wong <joseph.wong@broadcom.com>
2026-05-28 12:25:38 +01:00
Michael Brown 4906a255e3 [loong64] Port the RISC-V optimised TCP/IP checksum implementation
As with most other assembly code in iPXE, LoongArch64 is sufficiently
close to RISC-V that a straightforward transcription of the assembly
language code generally works.

Copy the RISC-V implementation for TCP/IP checksumming, retain the
register names and ABI, and just adjust the syntax to match
LoongArch64 requirements.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-26 10:53:11 +01:00
Michael Brown 127d8fd40e [riscv] Simplify TCP/IP checksum calculation
Use the tighter provable constraint

  carry.2^n + x <= (2^n - 1) + (2^n - 1)
                <= 2^n + (2^n - 2)

and so

  x + carry <= (2^n - 2) + 1
            <= (2^n - 1)

to eliminate some unnecessary folding steps, and hold the folded value
in the most significant bits of the register rather than the least
significant bits so that the final one's complement negation can be
accomplished naturally without requiring an explicit 0xffff constant.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-26 10:52:11 +01:00
Michael Brown 56a4f695d6 [ci] Update action versions to silence GitHub warnings
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-21 16:18:56 +01:00
Michael Brown fa473fd138 [ci] Include UEFI Secure Boot builds for RISC-V 64 and LoongArch64
The usage pattern for UEFI Secure Boot on RISC-V 64 and LoongArch64 is
not yet well defined: there is no equivalent on those architectures
for the UEFI shim or the Microsoft signing submission infrastructure.

Include signed binaries for these architectures within the release
artifacts.  Users may choose to enrol the iPXE Secure Boot CA
certificate on their own systems in order to use these binaries with
UEFI Secure Boot enabled.

OEMs such as Loongson may choose to include the iPXE Secure Boot CA
certificate within their default enrolled certificate list, or to
issue a cross-signed version of the iPXE Secure Boot CA certificate
(which could then be included within the official iPXE binaries in
future releases).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-21 15:41:08 +01:00
Michael Brown 6dcc401054 [loong64] Replace optimised string operations
The current implementation of the optimised string operations appears
to have been ported from the (old) arm64 implementation, and does not
cleanly match the LoongArch64 instruction set.

Replace with code derived from the riscv64 implementation, modified to
use indexed load and store instructions.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-21 15:21:20 +01:00
Michael Brown 63eeb23ad6 [build] Mark core riscv64 files as permitted for UEFI Secure Boot
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-21 14:42:23 +01:00
Michael Brown 2d8236995f [neighbour] Discard deferred packets before discarding complete entries
Discarding neighbour cache entries for active connections is known to
be extremely disruptive, and is therefore done only as a last resort
when attempting to free up memory for a new allocation attempt.

There is currently no way to discard the deferred packet queue
separately from discarding the complete neighbour cache entry.  Under
some conditions (such as a sustained ICMP echo request packet flood
from an IP address that will never complete neighbour resolution),
this can lead to the deferred packet queue growing without limit,
which will eventually lead to complete neighbour cache entries being
discarded.

Split out the logic in neighbour_destroy() for dropping deferred
packets to a separate neighbour_drop() function, and add a separate
cache discarder that will use this to free up memory without requiring
the complete neighbour cache entry to be discarded.

Reported-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-21 13:01:28 +01:00
Michael Brown 28b4b70867 [build] Mark core loong64 headers as permitted for UEFI Secure Boot
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-21 11:36:09 +01:00
Michael Brown fed3c38fd6 [doc] Add an AI contribution policy
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-21 08:41:46 +01:00
Michael Brown ca85200809 [virtio] Replace the virtio core and network device driver
The existing virtio network driver has been somewhat hacked together
over the past two decades by multiple contributors, and includes a
substantial amount of logic that is almost but not quite duplicated
between the "legacy" and "modern" code paths.

Rip out the existing driver and replace with a completely new driver
written based on the Virtual I/O Device specification document, not
derived from the Linux kernel driver.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-13 15:32:17 +01:00
Michael Brown 2b4a3efcc6 [lacp] Use the same system identifier for all ports
Commit 3d43789 ("[lacp] Detect and ignore erroneously looped back LACP
packets") added protection against LACP packet storms that arise when
our own transmitted packets are somehow looped back to the same port,
but does not protect against a situation in which we have two
different ports that are externally bridged to each other.

This situation is unlikely to arise in practice since a properly
configured link partner should not be both sending and forwarding LACP
packets.  Triggering this situation essentially requires our two ports
to be connected to a non-LACP-capable switch, while another port on
the same switch is connected to a separate device that is sending out
LACP packets.

Guard against this situation by using the MAC address of the first
network device as the LACP system identifier, thereby allowing the
loopback detection to reject any packets that were sent from any of
our ports.

Since the system identifier is no longer unique between ports, use the
guaranteed-unique network device scope ID as the group key to indicate
that we do not support aggregation.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-12 20:50:18 +01:00
Michael Brown ab9d7b0067 [pci] Provide pci_bar_is_io() to determine BAR type
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-12 20:50:18 +01:00
Michael Brown cac27e4882 [ioapi] Allow combined port accessors to be used in Secure Boot builds
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-12 20:48:18 +01:00
Michael Brown 63c1a63017 [tls] Add support for RSA-PSS signature scheme
The RSA-PSS signature scheme is crowbarred somewhat awkwardly into TLS
version 1.2.  Certificates with the standard rsaEncryption OID in the
public key may be used with either PKCS#1 or RSA-PSS, which breaks the
straightforward mapping between the OID and the signature algorithm.

Extend the definition of a TLS signature hash algorithm to include a
required OID-identified algorithm in the certificate's public key.
This allows us to define signature schemes such as rsa_pss_rsae_sha256
where the signature scheme uses an algorithm that differs from the
algorithm identified in the certificate's public key.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-07 14:29:15 +01:00
Michael Brown efa9515b14 [tls] Split out hybrid MD5+SHA1 algorithm used in TLS version 1.1
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-07 12:50:39 +01:00
Michael Brown 0c617b9132 [crypto] Add support for RSA-PSS signature scheme
Add support for the RSA-PSS signature scheme as defined in RFC 8017
and required for TLS version 1.3.

Signature verification is deliberately implemented by first deriving
the salt value and then reconstructing the entire expected signature.
This is arguably inefficient since it involves two invocations of the
mask generation function when only one is required.  However, this
implementation approach keeps the code size minimal (since there is no
need to implement separate verification logic), and makes it provably
impossible to accidentally omit a verification step (such as checking
the leading zero bits or the fixed 0x01 or 0xbc bytes).  Since
signature verification is not a fast-path operation, the guaranteed
correctness is more valuable than a marginally faster execution.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-06 22:14:41 +01:00
Michael Brown c8743b8c8e [crypto] Allow for alternative RSA signature schemes
The RSA-PSS signature scheme has the same basic structure as the
existing PKCS#1 signature scheme, with a difference only in how the
digest value is encoded before being enciphered.

Abstract out the digest encoding from the signature and verification
methods, and add an explicit "pkcs1" to the relevant method names.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-06 22:14:37 +01:00
Michael Brown 7fe8b7fde4 [test] Use mock random data for public key self-tests
Make the public key self-tests fully deterministic by temporarily
overriding the function used to obtain random data for RSA encryption.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-06 21:43:44 +01:00
Joseph Wong ae8defc279 [bnxt] Do not abort teardown on command failure
Modify bnxt_hwrm_run() to accept a flag indicating whether to abort
immediately upon a command failure.  During initialization path,
driver will continue to abort on first error.  During teardown,
sequence will continue executing subsequent cleanup commands even if
one fails.  This ensures a best-effort cleanup.

Signed-off-by: Joseph Wong <joseph.wong@broadcom.com>
2026-05-01 17:09:32 +01:00
Joseph Wong 822d4b1437 [bnxt] Improve code readability and debug output
Enhance code readability in the completion queue servicing logic to
use explicit function calls per case statement, rather than falling
through to the next statement.  Add debug print in ring allocation
path.  Fix typo in PCI ROM entry.

Signed-off-by: Joseph Wong <joseph.wong@broadcom.com>
2026-05-01 16:54:46 +01:00
Michael Brown be35d67a02 [librm] Specify regparm function attribute only for i386
The regparm function attribute is meaningful only for i386, not for
x86_64, and is reported as a build error by GCC 16.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-01 14:34:52 +01:00
Michael Brown c18d0a23b6 [build] Remove redundant regparm function attribute for x86_64
The regparm function attribute is meaningful only for i386, not for
x86_64, and is reported as a build error by GCC 16.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-01 14:17:00 +01:00
Michael Brown 2d28657ef6 [w89c840] Fix build warnings with GCC 16
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-05-01 13:56:32 +01:00
Christian I. Nilsson 3d1a20eacd [intel] Add PCI ID for I219-V and -LM existing of 18-29
Signed-off-by: Christian I. Nilsson <nikize@gmail.com>
2026-04-30 14:43:35 +01:00
Michael Brown 997e3f40ce [efi] Register EFI IPv6 device path settings as netX.ndp
The EFI device path settings are currently registered as the
"netX.dhcp" settings block, in order that they will be automatically
overridden if a real DHCP configuration takes place.  This does not
work as expected in an IPv6-only network, since the IPv6 configurator
will register "netX.ndp" rather than "netX.dhcp".

Fix by registering the EFI device path settings as either "netX.dhcp"
or "netX.ndp" based on the first address family encountered within the
device path.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-04-30 14:25:18 +01:00
Michael Brown 009bcf17a0 [tls] Treat signature algorithm identifiers as opaque 16-bit values
RFC 5246 defines the signature_algorithm extension values for TLS
version 1.2 as being tuples of {HashAlgorithm, SignatureAlgorithm}
pairs.  RFC 8446 redefines the signature_algorithm extension values
for TLS version 1.3 in a backwards-compatible way as opaque 16-bit
SignatureScheme values, and RFC 8447 updates RFC 5246 to allow these
values to be used with TLS version 1.2.

Redefine our concept of a signature algorithm identifier to remove the
internal structure that no longer exists.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-04-30 13:14:20 +01:00
Michael Brown 8c7c084e0f [crypto] Fail all operations for the null public-key algorithm
The null crypto algorithms are intended to do nothing: the null digest
algorithm accepts all input and generates a zero-length digest, and
the null cipher algorithm simply copies the input unmodifed to the
output.

The null public-key algorithm currently does nothing successfully.
Unlike the null digest and cipher algorithms, the null public-key
algorithm's methods are never called.

Change the null public-key algorithm to fail all operations, thereby
allowing its methods to be used as stubs by algorithms such as ECDSA
that do not implement all of the possible public-key operations.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-04-29 15:05:20 +01:00
Huzaifa Ali Zar df4eec8cfb [efi] Fix operator precedence in autoexec network download
The != operator has higher precedence than = in C, so the expressions:

  rc = imgacquire ( ..., image ) != 0

are parsed as:

  rc = ( imgacquire ( ..., image ) != 0 )

This assigns the boolean result (0 or 1) to rc instead of the actual
return code from imgacquire().  As a result, strerror(rc) reports an
incorrect error message when debugging is enabled.

Add parentheses around each assignment to ensure rc captures the
actual return value, matching the pattern already used in
efi_autoexec_filesystem() within the same file.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-04-29 11:25:59 +01:00
Michael Brown 8d2ebbf8a1 [crypto] Add support for HKDF key derivation
Add support for the HMAC-based Extract-and-Expand Key Derivation
Function (HKDF) as used in TLS version 1.3 and defined in RFC 5869.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-04-28 13:31:36 +01:00
Michael Brown a42daf6e88 [cloud] Separate snapshot deletion from image deletion for Alibaba Cloud
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-04-24 12:55:29 +01:00
Michael Brown 295f3bed20 [virtio] Ensure that device is closed before unmapping regions
Commit 988243c ("[virtio] Add virtio-net 1.0 support") erroneously
placed the code to unmap the device regions before the code to
unregister the network device.  In the common case that the network
device is still open at the time that we shut down to boot the OS,
this results in the regions being accessed after having been unmapped.

For 32-bit BIOS or for UEFI with no IOMMU enabled, the iounmap()
operation is a no-op and so the driver still happens to work despite
the ordering bug.  For 64-bit BIOS or for UEFI with an IOMMU enabled,
the iounmap() operation is not a no-op, and the driver will trigger a
page fault.

Fix by moving the call to unregister_netdev() to before the code that
unmaps the device regions.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-04-23 23:10:24 +01:00
Michael Brown 1c54e7e8a4 [virtio] Fix assertion failures when interface is closed
The unused RX I/O buffers are currently freed without being deleted
from the list, with the list head being reinitialised only after all
buffers have been deleted.  This triggers assertion failures due to
the list integrity checks when debugging is enabled.

Fix by deleting each buffer individually, so that the list structure
remains valid at all times.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2026-04-23 14:57:20 +01:00