tpm2-software/tpm2-tss

libtpms: FreeBSD does not support mremap()

joholl opened this issue · 1 comments

joholl commented

FreeBSD does not support mremap(), which is called in tcti_libtpms_map_state_file().

Currently, we open the state file, map it into memory, and then close it again. We can then continue working with the memory. If the memory is too small, we can use mremap() to enlarge it (without having to open the file again).

Two possible solutions:

A) We remove the state file feature for FreeBSD

If tcti-libtpms uses memory-only (without state file), then we never call mremap(). We could remove the state file feature for FreeBSD via #ifdef. For this to work we must be able to run out tests completely stateless :)

B) Replacing mremap() with munmap() and mmap().

This is unfortunately a bit unpleasant. As an alternative to mremap(), we could use munmap() and tcti_libtpms_map_state_file(min_size) instead. Unfortunately, this openes, maps, and then closes the file again.

This might get a bit ugly in the unit tests.

For Reference

/*
* Map the state file for this context into memory and allocate disk space. The
* file descriptor is closed again. Once this context reaches the end of its
* lifetime, the memory must be unmapped and the file must be truncated to its
* real size (rather than the allocated size).
*/
static TSS2_RC
tcti_libtpms_map_state_file(TSS2_TCTI_LIBTPMS_CONTEXT *tcti_libtpms)
{

@JuergenReppSIT What do you think?

@JuergenReppSIT What do you think?

I think there are two FAPI integration tests which would cause problems with version A) But they could be skipped for netBSD ;-)