|
iPXE
|
Executable images. More...
#include <stddef.h>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <errno.h>#include <assert.h>#include <libgen.h>#include <syslog.h>#include <ipxe/list.h>#include <ipxe/uaccess.h>#include <ipxe/umalloc.h>#include <ipxe/uri.h>#include <ipxe/image.h>Go to the source code of this file.
Macros | |
| #define | EACCES_UNTRUSTED __einfo_error ( EINFO_EACCES_UNTRUSTED ) |
| #define | EINFO_EACCES_UNTRUSTED __einfo_uniqify ( EINFO_EACCES, 0x01, "Untrusted image" ) |
| #define | EACCES_PERMANENT __einfo_error ( EINFO_EACCES_PERMANENT ) |
| #define | EINFO_EACCES_PERMANENT __einfo_uniqify ( EINFO_EACCES, 0x02, "Trust requirement is permanent" ) |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| FILE_SECBOOT (PERMITTED) | |
| void | free_image (struct refcnt *refcnt) |
| Free executable image. | |
| struct image * | alloc_image (struct uri *uri) |
| Allocate executable image. | |
| int | image_set_uri (struct image *image, struct uri *uri) |
| Set image URI. | |
| int | image_set_name (struct image *image, const char *name) |
| Set image name. | |
| char * | image_strip_suffix (struct image *image) |
| Strip dot suffix from image name, if present. | |
| int | image_set_cmdline (struct image *image, const char *cmdline) |
| Set image command line. | |
| int | image_set_len (struct image *image, size_t len) |
| Set image length. | |
| int | image_set_data (struct image *image, const void *data, size_t len) |
| Set image data. | |
| static int | image_probe (struct image *image) |
| Determine image type. | |
| int | register_image (struct image *image) |
| Register executable image. | |
| void | unregister_image (struct image *image) |
| Unregister executable image. | |
| struct image * | find_image (const char *name) |
| Find image by name. | |
| struct image * | find_image_tag (struct image_tag *tag) |
| Find image by tag. | |
| int | image_exec (struct image *image) |
| Execute image. | |
| int | image_replace (struct image *replacement) |
| Set replacement image. | |
| int | image_select (struct image *image) |
| Select image for execution. | |
| int | image_set_trust (int require_trusted, int permanent) |
| Change image trust requirement. | |
| struct image * | image_memory (const char *name, const void *data, size_t len) |
| Create registered image from block of memory. | |
| const char * | image_argument (struct image *image, const char *key) |
| Find argument within image command line. | |
Variables | |
| struct list_head | images = LIST_HEAD_INIT ( images ) |
| List of registered images. | |
| struct image_tag selected_image | __image_tag |
| Image selected for execution. | |
| static int | require_trusted_images = 0 |
| Current image trust requirement. | |
| static int | require_trusted_images_permanent = 0 |
| Prevent changes to image trust requirement. | |
| const char | empty_image_data [] = { '\0' } |
| Empty image terminating NUL. | |
Executable images.
Definition in file image.c.
| #define EACCES_UNTRUSTED __einfo_error ( EINFO_EACCES_UNTRUSTED ) |
Definition at line 49 of file image.c.
Referenced by image_exec(), and x509_validate().
| #define EINFO_EACCES_UNTRUSTED __einfo_uniqify ( EINFO_EACCES, 0x01, "Untrusted image" ) |
| #define EACCES_PERMANENT __einfo_error ( EINFO_EACCES_PERMANENT ) |
Definition at line 53 of file image.c.
Referenced by image_set_trust().
| #define EINFO_EACCES_PERMANENT __einfo_uniqify ( EINFO_EACCES, 0x02, "Trust requirement is permanent" ) |
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
| void free_image | ( | struct refcnt * | refcnt | ) |
Free executable image.
| refcnt | Reference counter |
Image consumers must call image_put() rather than calling free_image() directly. This function is exposed for use only by static images.
Definition at line 89 of file image.c.
References assert, image::cmdline, container_of, refcnt::count, DBGC, image::flags, for_each_table_entry, free, image_put(), image_set_len(), IMAGE_STATIC, IMAGE_STATIC_NAME, IMAGE_TAGS, image::name, NULL, image::replacement, tag, image::uri, and uri_put().
Referenced by alloc_image(), cmdline_image_free(), efi_cmdline_free(), and lkrn_exec().
Allocate executable image.
| uri | URI, or NULL |
| image | Executable image |
Definition at line 127 of file image.c.
References image::data, empty_image_data, free_image(), image_put(), image_set_uri(), NULL, rc, ref_init, image::refcnt, and zalloc().
Referenced by cpio_okx(), image_extract(), image_memory(), and imgdownload().
Set image URI.
| rc | Return status code |
Definition at line 157 of file image.c.
References basename(), image_set_name(), image::name, name, uri::opaque, uri::path, rc, image::uri, uri_get(), and uri_put().
Referenced by alloc_image(), and downloader_vredirect().
| int image_set_name | ( | struct image * | image, |
| const char * | name ) |
Set image name.
| rc | Return status code |
Definition at line 185 of file image.c.
References ENOMEM, image::flags, free, IMAGE_STATIC_NAME, image::name, name, and strdup().
Referenced by cms_decrypt(), cpio_okx(), image_extract(), image_memory(), image_set_uri(), imgsingle_exec(), and register_image().
| char * image_strip_suffix | ( | struct image * | image | ) |
Strip dot suffix from image name, if present.
| image | Image |
| sep | Position of old dot separator, or NULL |
Definition at line 210 of file image.c.
References image::name, NULL, and strrchr().
Referenced by cms_decrypt(), and image_extract().
| int image_set_cmdline | ( | struct image * | image, |
| const char * | cmdline ) |
Set image command line.
| rc | Return status code |
Definition at line 230 of file image.c.
References cmdline, image::cmdline, ENOMEM, free, NULL, and strdup().
Referenced by cpio_okx(), image_clear_cmdline(), image_extract_exec(), and imgsingle_exec().
Set image length.
| rc | Return status code |
Definition at line 249 of file image.c.
References data, image::data, empty_image_data, ENOMEM, ENOTTY, ERANGE, image::flags, IMAGE_STATIC, image::len, len, NULL, image::rwdata, and urealloc().
Referenced by cpio_okx(), free_image(), gzip_extract(), image_set_data(), mime_decode_base64(), mime_decode_identity(), mime_extract_part(), xferbuf_image_realloc(), and zlib_deflate().
Set image data.
| rc | Return status code |
Definition at line 291 of file image.c.
References data, image_set_len(), len, memcpy(), rc, and image::rwdata.
Referenced by image_memory(), and zimg_extract().
|
static |
Determine image type.
| image | Executable image |
| rc | Return status code |
Definition at line 310 of file image.c.
References DBGC, ENOTSUP, for_each_table_entry, IMAGE_TYPES, image::name, rc, strerror(), image::type, and type.
Referenced by register_image().
| int register_image | ( | struct image * | image | ) |
Register executable image.
| image | Executable image |
| rc | Return status code |
Definition at line 336 of file image.c.
References assert, image::cmdline, image::data, DBGC, EINVAL, image::flags, image_get(), image_probe(), IMAGE_REGISTERED, image_set_name(), IMAGE_STATIC, IMAGE_STATIC_NAME, images, image::len, image::list, list_add_tail, image::name, name, NULL, rc, snprintf(), image::text, and image::type.
Referenced by asn1_okx(), cmdline_init(), cms_decrypt(), efi_cmdline_init(), efi_image_exec(), embedded_init(), image_exec(), image_extract(), image_memory(), imgdownload(), pixbuf_okx(), and test_init().
| void unregister_image | ( | struct image * | image | ) |
Unregister executable image.
| image | Executable image |
Definition at line 390 of file image.c.
References DBGC, image::flags, image_put(), IMAGE_REGISTERED, image::list, list_del, and image::name.
Referenced by archive_okx(), asn1_okx(), bzimage_exec(), cert_exec(), cms_decrypt(), com32_exec_loop(), comboot_exec_loop(), console_exec(), efi_autoexec_load(), efi_image_exec(), fdt_test_exec(), image_exec(), image_extract(), image_extract_exec(), imgdecrypt_exec(), imgextract_exec(), imgfree_exec(), imgset_exec(), imgverify_exec(), and pixbuf_okx().
| struct image * find_image | ( | const char * | name | ) |
Find image by name.
| name | Image name |
| image | Executable image, or NULL |
Definition at line 408 of file image.c.
References for_each_image, image::name, name, NULL, and strcmp().
Referenced by imgacquire(), and imgmulti_exec().
Find image by tag.
| tag | Image tag |
| image | Executable image, or NULL |
Definition at line 425 of file image.c.
References for_each_image, NULL, and tag.
Referenced by efi_file_open(), efi_image_exec(), fdt_create(), imgsingle_exec(), and shim_exec().
| int image_exec | ( | struct image * | image | ) |
Execute image.
| image | Executable image |
| rc | Return status code |
The image must already be registered. Note that executing an image may cause it to unregister itself. The caller must therefore assume that the image pointer becomes invalid.
Definition at line 446 of file image.c.
References assert, churi(), current_image, cwuri, DBGC, EACCES_UNTRUSTED, ENOEXEC, image_type::exec, image::flags, IMAGE_AUTO_UNREGISTER, image_exec(), image_get(), image_put(), IMAGE_REGISTERED, image_tag(), IMAGE_TRUSTED, LOG_ERR, LOG_NOTICE, image::name, NULL, rc, register_image(), image::replacement, replacement, require_trusted_images, strerror(), syslog, image::type, unregister_image(), image::uri, uri_get(), and uri_put().
Referenced by image_exec(), imgexec(), ipxe(), and uriboot().
| int image_replace | ( | struct image * | replacement | ) |
Set replacement image.
| replacement | Replacement image |
| rc | Return status code |
The replacement image must already be registered, and must remain registered until the currently-executing image returns.
Definition at line 561 of file image.c.
References assert, current_image, DBGC, ENOEXEC, ENOTTY, image_get(), image_put(), IMAGE_REGISTERED, image::name, rc, image::replacement, replacement, and strerror().
Referenced by comboot_fetch_kernel(), image_extract_exec(), and imgexec().
| int image_select | ( | struct image * | image | ) |
Select image for execution.
| image | Executable image |
| rc | Return status code |
Definition at line 597 of file image.c.
References ENOEXEC, image_type::exec, image_tag(), selected_image, and image::type.
Referenced by embedded_init(), and imgselect().
| int image_set_trust | ( | int | require_trusted, |
| int | permanent ) |
Change image trust requirement.
| require_trusted | Require trusted images |
| permanent | Make trust requirement permanent |
| rc | Return status code |
Definition at line 616 of file image.c.
References EACCES_PERMANENT, require_trusted_images, and require_trusted_images_permanent.
Referenced by imgtrust_exec().
Create registered image from block of memory.
| image | Image, or NULL on error |
Definition at line 641 of file image.c.
References alloc_image(), data, ENOMEM, image_put(), image_set_data(), image_set_name(), len, name, NULL, rc, and register_image().
Referenced by archive_okx(), fdt_test_exec(), imgmem(), and initrd_init().
| const char * image_argument | ( | struct image * | image, |
| const char * | key ) |
Find argument within image command line.
| value | Argument value, or NULL if not found |
Definition at line 685 of file image.c.
References cmdline, image::cmdline, isspace(), key, next, NULL, strlen(), and strstr().
Referenced by bzimage_parse_cmdline(), and cpio_parse_cmdline().
| struct list_head images = LIST_HEAD_INIT ( images ) |
List of registered images.
Definition at line 59 of file image.c.
Referenced by first_image(), initrd_dump(), initrd_load(), initrd_region(), initrd_squash_high(), initrd_startup(), initrd_swap(), lkrn_exec(), and register_image().
| struct image_tag current_image __image_tag |
|
static |
Current image trust requirement.
Definition at line 72 of file image.c.
Referenced by image_exec(), and image_set_trust().
|
static |
Prevent changes to image trust requirement.
Definition at line 75 of file image.c.
Referenced by image_set_trust().
| const char empty_image_data[] = { '\0' } |
Empty image terminating NUL.
Definition at line 78 of file image.c.
Referenced by alloc_image(), and image_set_len().