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/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) | |
static 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, userptr_t 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, userptr_t 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 | ) |
|
static |
Free executable image.
refcnt | Reference counter |
Definition at line 80 of file image.c.
References image::cmdline, container_of, image::data, DBGC, for_each_table_entry, free, image_put(), IMAGE_TAGS, image::name, NULL, image::replacement, tag, ufree(), image::uri, and uri_put().
Referenced by alloc_image().
Allocate executable image.
uri | URI, or NULL |
image | Executable image |
Definition at line 103 of file image.c.
References free_image(), image_put(), image_set_uri(), NULL, rc, ref_init, image::refcnt, and zalloc().
Referenced by image_extract(), image_memory(), and imgdownload().
Set image URI.
image | Image |
uri | New image URI |
rc | Return status code |
Definition at line 132 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 160 of file image.c.
References ENOMEM, free, image::name, name, and strdup().
Referenced by cms_decrypt(), 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 181 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 201 of file image.c.
References cmdline, image::cmdline, ENOMEM, free, NULL, and strdup().
Referenced by 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 220 of file image.c.
References image::data, ENOMEM, len, image::len, and urealloc().
Referenced by 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 241 of file image.c.
References data, image::data, image_set_len(), len, memcpy_user(), and rc.
Referenced by image_memory().
|
static |
Determine image type.
image | Executable image |
rc | Return status code |
Definition at line 260 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 286 of file image.c.
References image::data, DBGC, image::flags, image_get(), image_probe(), IMAGE_REGISTERED, image_set_name(), images, image::len, image::list, list_add_tail, image::name, name, rc, snprintf(), image::type, and user_to_phys().
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 322 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(), 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 340 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 357 of file image.c.
References for_each_image, NULL, and tag.
Referenced by efi_file_open(), efi_image_exec(), 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 378 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(), image_extract_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 489 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(), and imgexec().
int image_select | ( | struct image * | image | ) |
Select image for execution.
image | Executable image |
rc | Return status code |
Definition at line 525 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 544 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 569 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 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 612 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 57 of file image.c.
Referenced by first_image(), initrd_dump(), initrd_reshuffle(), initrd_squash_high(), initrd_swap(), and register_image().
struct image_tag current_image __image_tag |
|
static |
Current image trust requirement.
Definition at line 70 of file image.c.
Referenced by image_exec(), and image_set_trust().
|
static |
Prevent changes to image trust requirement.
Definition at line 73 of file image.c.
Referenced by image_set_trust().