aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2022-12-14[build] Disable dangling pointer checking for GCCgcc12Michael Brown1-2/+4
The dangling pointer warning introduced in GCC 12 reports false positives that result in build failures. In particular, storing the address of a local code label used to record the current state of a state machine (as done in crypto/deflate.c) is reported as an error. There seems to be no way to mark the pointer type as being permitted to hold such a value, so unconditionally disable the warning. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-12-14[build] Disable array bounds checking for GCCMichael Brown1-2/+2
The array bounds checker on GCC 12 and newer reports a very large number of false positives that result in build failures. In particular, accesses through pointers to zero-length arrays (such as those used by the linker table mechanism in include/ipxe/tables.h) are reported as errors, contrary to the GCC documentation. Work around this GCC issue by unconditionally disabling the warning. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-15[intel] Add PCI ID for I219-V and -LM 16,17Christian I. Nilsson1-0/+4
Signed-off-by: Christian I. Nilsson <nikize@gmail.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-13[pci] Backup and restore standard config space across PCIe FLRMichael Brown1-2/+7
The behaviour of PCI devices across a function-level reset seems to be inconsistent in practice: some devices will preserve PCI BARs, some will not. Fix the behaviour of FLR on devices that do not preserve PCI BARs by backing up and restoring PCI configuration space across the reset. Preserve only the standard portion of the configuration space, since there may be registers with unexpected side effects in the remaining non-standardised space. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-13[pci] Allow PCI config space backup to be limited by maximum offsetMichael Brown5-13/+22
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-10[tls] Add GCM cipher suitesMichael Brown7-8/+147
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-10[tests] Verify ability to perform in-place encryption and decryptionMichael Brown1-4/+6
TLS relies upon the ability of ciphers to perform in-place decryption, in order to avoid allocating additional I/O buffers for received data. Add verification of in-place encryption and decryption to the cipher self-tests. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-10[crypto] Support in-place decryption for GCM ciphersMichael Brown1-34/+32
The hash calculation is currently performed incorrectly when decrypting in place, since the ciphertext will have been overwritten with the plaintext before being used to update the hash value. Restructure the code to allow for in-place encryption and decryption. Choose to optimise for the decryption case, since we are likely to decrypt much more data than we encrypt. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-09[tests] Verify ability to reset cipher initialisation vectorMichael Brown1-0/+38
TLS relies upon the ability to reuse a cipher by resetting only the initialisation vector while reusing the existing key. Add verification of resetting the initialisation vector to the cipher self-tests. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-09[crypto] Ensure relevant GCM cipher state is cleared by cipher_setiv()Michael Brown2-11/+17
Reset the accumulated authentication state when cipher_setiv() is called, to allow the cipher to be reused without resetting the key. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-09[tls] Allow handshake digest algorithm to be specified by cipher suiteMichael Brown4-68/+125
All existing cipher suites use SHA-256 as the TLSv1.2 and above handshake digest algorithm (even when using SHA-1 as the MAC digest algorithm). Some GCM cipher suites use SHA-384 as the handshake digest algorithm. Allow the cipher suite to specify the handshake (and PRF) digest algorithm to be used for TLSv1.2 and above. This requires some restructuring to allow for the fact that the ClientHello message must be included within the handshake digest, even though the relevant digest algorithm is not yet known at the point that the ClientHello is sent. Fortunately, the ClientHello may be reproduced verbatim at the point of receiving the ServerHello, so we rely on reconstructing (rather than storing) this message. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-09[tls] Always send maximum supported version in ClientHelloMichael Brown1-1/+1
Always send the maximum supported version in our ClientHello message, even when performing renegotiation (in which case the current version may already be lower than the maximum supported version). This is permitted by the specification, and allows the ClientHello to be reconstructed verbatim at the point of selecting the handshake digest algorithm in tls_new_server_hello(). Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-08[tls] Add support for AEAD ciphersMichael Brown1-2/+39
Allow for AEAD cipher suites where the MAC length may be zero and the authentication is instead provided by an authenticating cipher, with the plaintext authentication tag appended to the ciphertext. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-08[tls] Treat invalid block padding as zero length paddingMichael Brown1-2/+2
Harden against padding oracle attacks by treating invalid block padding as zero length padding, thereby deferring the failure until after computing the (incorrect) MAC. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-08[tls] Allow for arbitrary-length initialisation vectorsMichael Brown2-186/+148
Restructure the encryption and decryption operations to allow for the use of ciphers where the initialisation vector is constructed by concatenating the fixed IV (derived as part of key expansion) with a record IV (prepended to the ciphertext). Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-08[tls] Add MAC length as a cipher suite parameterMichael Brown4-16/+28
TLS stream and block ciphers use a MAC with a length equal to the output length of the digest algorithm in use. For AEAD ciphers there is no MAC, with the equivalent functionality provided by the cipher algorithm's authentication tag. Allow for the existence of AEAD cipher suites by making the MAC length a parameter of the cipher suite. Assume that the MAC key length is equal to the MAC length, since this is true for all currently supported cipher suites. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-08[tls] Abstract out concept of a TLS authentication headerMichael Brown2-21/+27
All TLS cipher types use a common structure for the per-record data that is authenticated in addition to the plaintext itself. This data is used as a prefix in the HMAC calculation for stream and block ciphers, or as additional authenticated data for AEAD ciphers. Define a "TLS authentication header" structure to hold this data as a contiguous block, in order to meet the alignment requirement for AEAD ciphers such as GCM. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-07[tls] Ensure cipher alignment size is respectedMichael Brown1-0/+18
Adjust the length of the first received ciphertext data buffer to ensure that all decryption operations respect the cipher's alignment size. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-07[crypto] Add concept of cipher alignment sizeMichael Brown8-1/+33
The GCM cipher mode of operation (in common with other counter-based modes of operation) has a notion of blocksize that does not neatly fall into our current abstraction: it does operate in 16-byte blocks but allows for an arbitrary overall data length (i.e. the final block may be incomplete). Model this by adding a concept of alignment size. Each call to encrypt() or decrypt() must begin at a multiple of the alignment size from the start of the data stream. This allows us to model GCM by using a block size of 1 byte and an alignment size of 16 bytes. As a side benefit, this same concept allows us to neatly model the fact that raw AES can encrypt only a single 16-byte block, by specifying an alignment size of zero on this cipher. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-07[tls] Formalise notions of fixed and record initialisation vectorsMichael Brown4-5/+48
TLS block ciphers always use CBC (as per RFC 5246 section 6.2.3.2) with a record initialisation vector length that is equal to the cipher block size, and no fixed initialisation vector. The initialisation vector for AEAD ciphers such as GCM is less straightforward, and requires both a fixed and per-record component. Extend the definition of a cipher suite to include fixed and record initialisation vector lengths, and generate the fixed portion (if any) as part of key expansion. Do not add explicit calls to cipher_setiv() in tls_assemble_block() and tls_split_block(), since the constraints imposed by RFC 5246 are specifically chosen to allow implementations to avoid doing so. (Instead, add a sanity check that the record initialisation vector length is equal to the cipher block size.) Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-07[tls] Remove support for TLSv1.0Michael Brown2-36/+6
The TLSv1.0 protocol was deprecated by RFC 8996 (along with TLSv1.1), and has been disabled by default in iPXE since commit dc785b0fb ("[tls] Default to supporting only TLSv1.1 or above") in June 2020. While there is value in continuing to support older protocols for interoperability with older server appliances, the additional complexity of supporting the implicit initialisation vector for TLSv1.0 is not worth the cost. Remove support for the obsolete TLSv1.0 protocol, to reduce complexity of the implementation and simplify ongoing maintenance. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-11-04[efi] Clear DMA-coherent buffers before mappingioactiveMichael Brown1-0/+3
The DMA mapping is performed implicitly as part of the call to dma_alloc(). The current implementation creates the IOMMU mapping for the allocated and potentially uninitialised data before returning to the caller (which will immediately zero out or otherwise initialise the buffer). This leaves a small window within which a malicious PCI device could potentially attempt to retrieve firmware-owned secrets present in the uninitialised buffer. (Note that the hypothetically malicious PCI device has no viable way to know the address of the buffer from which to attempt a DMA read, rendering the attack extremely implausible.) Guard against any such hypothetical attacks by zeroing out the allocated buffer prior to creating the coherent DMA mapping. Suggested-by: Mateusz Siwiec <Mateusz.Siwiec@ioactive.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-27[bzimage] Fix parsing of "vga=..." when not at end of command linevgafixMichael Brown1-4/+10
bzimage_parse_cmdline() uses strcmp() to identify the named "vga=..." kernel command line option values, which will give a false negative if the option is not last on the command line. Fix by temporarily changing the relevant command line separator (if any) to a NUL terminator. Debugged-by: Simon Rettberg <simon.rettberg@rz.uni-freiburg.de> Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-25[crypto] Add block cipher Galois/Counter mode of operationMichael Brown7-0/+1072
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-25[crypto] Add concept of authentication tag to cipher algorithmsMichael Brown9-7/+64
Some ciphers (such as GCM) support the concept of a tag that can be used to authenticate the encrypted data. Add a cipher method for generating an authentication tag. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-25[crypto] Add concept of additional data to cipher algorithmsMichael Brown4-23/+47
Some ciphers (such as GCM) support the concept of additional authenticated data, which does not appear in the ciphertext but may affect the operation of the cipher. Allow cipher_encrypt() and cipher_decrypt() to be called with a NULL destination buffer in order to pass additional data. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-25[crypto] Allow initialisation vector length to vary from cipher blocksizeMichael Brown7-16/+24
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-25[crypto] Expose null crypto algorithm methods for reuseMichael Brown4-51/+54
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-11[tls] Add support for DHE variants of the existing cipher suitesMichael Brown3-4/+56
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-11[tls] Add support for Ephemeral Diffie-Hellman key exchangeHEADMichael Brown2-0/+247
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-11[tls] Add key exchange mechanism to definition of cipher suiteMichael Brown4-3/+48
Allow for the key exchange mechanism to vary depending upon the selected cipher suite. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-11[tls] Record ServerKeyExchange record, if providedMichael Brown2-0/+40
Accept and record the ServerKeyExchange record, which is required for key exchange mechanisms such as Ephemeral Diffie-Hellman (DHE). Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-11[tls] Generate pre-master secret at point of sending ClientKeyExchangeMichael Brown2-26/+27
The pre-master secret is currently constructed at the time of instantiating the TLS connection. This precludes the use of key exchange mechanisms such as Ephemeral Diffie-Hellman (DHE), which require a ServerKeyExchange message to exchange additional key material before the pre-master secret can be constructed. Allow for the use of such cipher suites by deferring generation of the master secret until the point of sending the ClientKeyExchange message. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-11[tls] Generate master secret at point of sending ClientKeyExchangeMichael Brown1-8/+13
The master secret is currently constructed upon receiving the ServerHello message. This precludes the use of key exchange mechanisms such as Ephemeral Diffie-Hellman (DHE), which require a ServerKeyExchange message to exchange additional key material before the pre-master secret and master secret can be constructed. Allow for the use of such cipher suites by deferring generation of the master secret until the point of sending the ClientKeyExchange message. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-11[crypto] Add Ephemeral Diffie-Hellman key exchange algorithmMichael Brown5-0/+936
Add an implementation of the Ephemeral Diffie-Hellman key exchange algorithm as defined in RFC2631, with test vectors taken from the NIST Cryptographic Toolkit. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-10[crypto] Simplify internal HMAC APIMichael Brown16-163/+142
Simplify the internal HMAC API so that the key is provided only at the point of calling hmac_init(), and the (potentially reduced) key is stored as part of the context for later use by hmac_final(). This simplifies the calling code, and avoids the need for callers such as TLS to allocate a potentially variable length block in order to retain a copy of the unmodified key. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-10-10[test] Add HMAC self-testsMichael Brown2-0/+212
The HMAC code is already tested indirectly via several consuming algorithms that themselves provide self-tests (e.g. HMAC-DRBG, NTLM authentication, and PeerDist content identification), but lacks any direct test vectors. Add explicit HMAC tests and ensure that corner cases such as empty keys, block-length keys, and over-length keys are all covered. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-19[ena] Assign memory BAR if left empty by BIOSMichael Brown1-0/+45
Some BIOSes in AWS EC2 (observed with a c6i.metal instance in eu-west-2) will fail to assign an MMIO address to the ENA device, which causes ioremap() to fail. Experiments show that the ENA device is the only device behind its bridge, even when multiple ENA devices are present, and that the BIOS does assign a memory window to the bridge. We may therefore choose to assign the device an MMIO address at the start of the bridge's memory window. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-19[pci] Add minimal PCI bridge driverMichael Brown4-0/+191
Add a minimal driver for PCI bridges that can be used to locate the bridge to which a PCI device is attached. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-18[pci] Select PCI I/O API at runtime for cloud imagesMichael Brown11-1/+256
Pretty much all physical machines and off-the-shelf virtual machines will provide a functional PCI BIOS. We therefore default to using only the PCI BIOS, with no fallback to an alternative mechanism if the PCI BIOS fails. AWS EC2 provides the opportunity to experience some exceptions to this rule. For example, the t3a.nano instances in eu-west-1 have no functional PCI BIOS at all. As of commit 83516ba ("[cloud] Use PCIAPI_DIRECT for cloud images") we therefore use direct Type 1 configuration space accesses in the images built and published for use in the cloud. Recent experience has discovered yet more variation in AWS EC2 instances. For example, some of the metal instance types have multiple PCI host bridges and the direct Type 1 accesses therefore see only a subset of the PCI devices. Attempt to accommodate future such variations by making the PCI I/O API selectable at runtime and choosing ECAM (if available), falling back to the PCI BIOS (if available), then finally falling back to direct Type 1 accesses. This is implemented as a dedicated PCIAPI_CLOUD API, rather than by having the PCI core select a suitable API at runtime (as was done for timers in commit 302f1ee ("[time] Allow timer to be selected at runtime"). The common case will remain that only the PCI BIOS API is required, and we would prefer to retain the optimisations that come from inlining the configuration space accesses in this common case. Cloud images are (at present) disk images rather than ROM images, and so the increased code size required for this design approach in the PCIAPI_CLOUD case is acceptable. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-18[bios] Allow pcibios_discover() to return an empty rangeMichael Brown1-3/+5
Allow pcibios_discover() to return an empty range if the INT 1A,B101 PCI BIOS installation check call fails. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-16[pci] Add support for the Enhanced Configuration Access Mechanism (ECAM)Michael Brown5-0/+461
The ACPI MCFG table describes a direct mapping of PCI configuration space into MMIO space. This mapping allows access to extended configuration space (up to 4096 bytes) and also provides for the existence of multiple host bridges. Add support for the ECAM mechanism described by the ACPI MCFG table, as a selectable PCI I/O API alongside the existing PCI BIOS and Type 1 mechanisms. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-15[pci] Generalise pci_num_bus() to pci_discover()Michael Brown10-43/+78
Allow pci_find_next() to discover devices beyond the first PCI segment, by generalising pci_num_bus() (which implicitly assumes that there is only a single PCI segment) with pci_discover() (which has the ability to return an arbitrary contiguous chunk of PCI bus:dev.fn address space). Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-15[pci] Check for wraparound in callers of pci_find_next()Michael Brown3-3/+10
The semantics of the bus:dev.fn parameter passed to pci_find_next() are "find the first existent PCI device at this address or higher", with the caller expected to increment the address between finding devices. This does not allow the parameter to distinguish between the two cases "start from address zero" and "wrapped after incrementing maximal possible address", which could therefore lead to an infinite loop in the degenerate case that a device with address ffff:ff:1f.7 really exists. Fix by checking for wraparound in the caller (which is already responsible for performing the increment). Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-15[pci] Allow pci_find_next() to return non-zero PCI segmentsMichael Brown3-16/+14
Separate the return status code from the returned PCI bus:dev.fn address, in order to allow pci_find_next() to be used to find devices with a non-zero PCI segment number. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-15[linux] Add missing PROVIDE_PCIAPI_INLINE() macrosMichael Brown1-0/+9
Ensure type consistency of the PCI I/O API methods by adding the missing PROVIDE_PCIAPI_INLINE() macros. Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-13[ipv6] Ignore SLAAC on prefixes with an incompatible prefix lengthMichael Brown1-11/+25
Experience suggests that routers are often misconfigured to advertise SLAAC even on prefixes that do not have a SLAAC-compatible prefix length. iPXE will currently treat this as an error, resulting in the prefix being ignored completely. Handle this misconfiguration by ignoring the autonomous address flag when the prefix length is unsuitable for SLAAC. Reported-by: Malte Janduda <mail@janduda.net> Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-06[ipv6] Fix mask calculation when prefix length is not a multiple of 8Michael Brown2-1/+38
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-09-06[test] Validate constructed IPv6 routing table entriesMichael Brown1-12/+52
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2022-08-26[ena] Increase receive ring size to 128 entriesMichael Brown2-5/+12
Some versions of the ENA hardware (observed on a c6i.large instance in eu-west-2) seem to require a receive ring containing at least 128 entries: any smaller ring will never see receive completions or will stall after the first few completions. Increase the receive ring size to 128 entries (determined empirically) for compatibility with these hardware versions. Limit the receive ring fill level to 16 (as at present) to avoid consuming more memory than will typically be available in the internal heap. Signed-off-by: Michael Brown <mcb30@ipxe.org>