]> git.ipfire.org Git - thirdparty/ipxe.git/commit
[image] Make image data read-only to most consumers
authorMichael Brown <mcb30@ipxe.org>
Wed, 30 Apr 2025 13:14:51 +0000 (14:14 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 30 Apr 2025 14:38:15 +0000 (15:38 +0100)
commit05ad7833c51c942a5cb91540a054852bb991333b
treece84699ba21615ae75f3d4d5619dfac63d293e1f
parentcd803ff2e2424b56a7ae5886e4cfe17b47652e6e
[image] Make image data read-only to most consumers

Almost all image consumers do not need to modify the content of the
image.  Now that the image data is a pointer type (rather than the
opaque userptr_t type), we can rely on the compiler to enforce this at
build time.

Change the .data field to be a const pointer, so that the compiler can
verify that image consumers do not modify the image content.  Provide
a transparent .rwdata field for consumers who have a legitimate (and
now explicit) reason to modify the image content.

We do not attempt to impose any runtime restriction on checking
whether or not an image is writable.  The only existing instances of
genuinely read-only images are the various unit test images, and it is
acceptable for defective test cases to result in a segfault rather
than a runtime error.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
15 files changed:
src/arch/x86/image/initrd.c
src/arch/x86/image/sdi.c
src/core/fdt.c
src/core/image.c
src/crypto/cms.c
src/image/efi_image.c
src/image/embedded.c
src/image/zlib.c
src/include/ipxe/image.h
src/interface/efi/efi_cmdline.c
src/tests/asn1_test.c
src/tests/asn1_test.h
src/tests/cms_test.c
src/tests/pixbuf_test.c
src/tests/pixbuf_test.h