Skip to content

Commit

Permalink
Some additional assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Jan 23, 2025
1 parent 9aa64a3 commit 354516b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions liblfi/pal/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lfi_new_plat(size_t pagesize)
struct PlatOptions opts = (struct PlatOptions) {
.pagesize = pagesize,
.vmsize = gb(4),
.verifier = NULL,
};

struct LFIPlatform* plat = malloc(sizeof(struct LFIPlatform));
Expand Down
5 changes: 4 additions & 1 deletion liblfi/pal/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ mapmem(struct LFIAddrSpace* as, uintptr_t start, size_t size, int prot,
static int
protectverify(lfiptr_t base, size_t size, int prot, LFIVerifier* verifier)
{
if ((prot & LFI_PROT_EXEC) == 0 || !verifier) {
if (((prot & LFI_PROT_EXEC) == 0) || !verifier) {
return host_mprotect((void*) base, size, prot);
} else if ((prot & LFI_PROT_EXEC) && (prot & LFI_PROT_WRITE)) {
return -1;
}

assert(verifier);
if (!lfiv_verify(verifier, (void*) base, size, (uintptr_t) base)) {
return -1;
}
Expand All @@ -93,6 +94,7 @@ mapverify(struct LFIAddrSpace* as, uintptr_t start, size_t size, int prot,
int r;
if ((r = mapmem(as, start, size, LFI_PROT_READ, flags, hf, off)) < 0)
return r;
assert(as->plat);
if (protectverify(start, size, prot, as->plat->opts.verifier) < 0) {
host_munmap((void*) start, size);
return -1;
Expand Down Expand Up @@ -147,6 +149,7 @@ lfi_as_mprotect(struct LFIAddrSpace* as, lfiptr_t addr, size_t size, int prot)
assert(addr >= as->minaddr && addr + size <= as->maxaddr);

// TODO: mark the mapping with libmmap?
assert(as->plat);
return protectverify(addr, size, prot, as->plat->opts.verifier);
}

Expand Down

0 comments on commit 354516b

Please sign in to comment.