|
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) | |
| void | free_image (struct refcnt *refcnt) |
| Free executable image. More... | |
| struct image * | alloc_image (struct uri *uri) |
| Allocate executable image. More... | |
| int | image_set_uri (struct image *image, struct uri *uri) |
| Set image URI. More... | |
| int | image_set_name (struct image *image, const char *name) |
| Set image name. More... | |
| char * | image_strip_suffix (struct image *image) |
| Strip dot suffix from image name, if present. More... | |
| int | image_set_cmdline (struct image *image, const char *cmdline) |
| Set image command line. More... | |
| int | image_set_len (struct image *image, size_t len) |
| Set image length. More... | |
| int | image_set_data (struct image *image, const void *data, size_t len) |
| Set image data. More... | |
| static int | image_probe (struct image *image) |
| Determine image type. More... | |
| int | register_image (struct image *image) |
| Register executable image. More... | |
| void | unregister_image (struct image *image) |
| Unregister executable image. More... | |
| struct image * | find_image (const char *name) |
| Find image by name. More... | |
| struct image * | find_image_tag (struct image_tag *tag) |
| Find image by tag. More... | |
| int | image_exec (struct image *image) |
| Execute image. More... | |
| int | image_replace (struct image *replacement) |
| Set replacement image. More... | |
| int | image_select (struct image *image) |
| Select image for execution. More... | |
| int | image_set_trust (int require_trusted, int permanent) |
| Change image trust requirement. More... | |
| struct image * | image_memory (const char *name, const void *data, size_t len) |
| Create registered image from block of memory. More... | |
| const char * | image_argument (struct image *image, const char *key) |
| Find argument within image command line. More... | |
Variables | |
| struct list_head | images = LIST_HEAD_INIT ( images ) |
| List of registered images. More... | |
| struct image_tag selected_image | __image_tag |
| Image selected for execution. More... | |
| static int | require_trusted_images = 0 |
| Current image trust requirement. More... | |
| static int | require_trusted_images_permanent = 0 |
| Prevent changes to image trust requirement. More... | |
Executable images.
Definition in file image.c.
| #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" ) |
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| 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 85 of file image.c.
References assert(), image::cmdline, container_of, refcnt::count, DBGC, image::flags, for_each_table_entry, free, image_put(), IMAGE_STATIC, IMAGE_STATIC_NAME, IMAGE_TAGS, image::name, NULL, image::replacement, image::rwdata, tag, ufree(), 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 123 of file image.c.
References 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.
| image | Image |
| uri | New image URI |
| rc | Return status code |
Definition at line 152 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.
| image | Image |
| name | New image name |
| rc | Return status code |
Definition at line 180 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 205 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.
| image | Image |
| cmdline | New image command line, or NULL |
| rc | Return status code |
Definition at line 225 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.
| image | Image |
| len | Length of image data |
| rc | Return status code |
Definition at line 244 of file image.c.
References ENOMEM, ENOTTY, image::flags, IMAGE_STATIC, image::len, len, image::rwdata, and urealloc().
Referenced by cpio_okx(), gzip_extract(), image_set_data(), and zlib_deflate().
Set image data.
| image | Image |
| data | Image data |
| len | Length of image data |
| rc | Return status code |
Definition at line 269 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 288 of file image.c.
References DBGC, ENOTSUP, for_each_table_entry, IMAGE_TYPES, image::name, rc, strerror(), type, and image::type.
Referenced by register_image().
| int register_image | ( | struct image * | image | ) |
Register executable image.
| image | Executable image |
| rc | Return status code |
Definition at line 314 of file image.c.
References assert(), image::cmdline, image::data, DBGC, 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(), 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 357 of file image.c.
References DBGC, image::flags, image_put(), IMAGE_REGISTERED, image::list, list_del, and image::name.
Referenced by 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(), gzip_okx(), image_exec(), image_extract(), image_extract_exec(), imgdecrypt_exec(), imgextract_exec(), imgfree_exec(), imgverify_exec(), pixbuf_okx(), and zlib_okx().
| struct image* find_image | ( | const char * | name | ) |
Find image by name.
| name | Image name |
| image | Executable image, or NULL |
Definition at line 375 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 392 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 413 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(), replacement, image::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 528 of file image.c.
References assert(), current_image, DBGC, ENOEXEC, ENOTTY, image_tag::image, image_get(), image_put(), IMAGE_REGISTERED, image::name, rc, replacement, image::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 564 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 583 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.
| name | Name |
| data | Image data |
| len | Length |
| image | Image, or NULL on error |
Definition at line 608 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 fdt_test_exec(), gzip_okx(), imgmem(), initrd_init(), and zlib_okx().
| const char* image_argument | ( | struct image * | image, |
| const char * | key | ||
| ) |
Find argument within image command line.
| image | Image |
| key | Argument search key (including trailing delimiter) |
| value | Argument value, or NULL if not found |
Definition at line 652 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 58 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 71 of file image.c.
Referenced by image_exec(), and image_set_trust().
|
static |
Prevent changes to image trust requirement.
Definition at line 74 of file image.c.
Referenced by image_set_trust().
1.8.15