Skip to content

Commit

Permalink
Fix off-by-one in the driver (#318)
Browse files Browse the repository at this point in the history
The existing driver code checks whether an enclave's requested size is
less than or equal to some `MAX_ORDER` defined in the Linux kernel, and
chooses the kernel allocator to use based on this. However, this should
be a strict less than check instead. If we attempt to instantiate an
enclave of size exactly `MAX_ORDER`, we will trigger a bug condition in
Linux's `page_alloc.c` in the `__alloc_pages` function on line 5406.
This condition is enforced when the requested order is greater than or
equal to `MAX_ORDER`. This PR changes the driver such that we do not
attempt to use the wrong allocator and no longer see these bug messages.
  • Loading branch information
grg-haas committed Mar 23, 2023
1 parent 2982908 commit 747e6a1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion linux-keystone-driver/keystone-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int epm_init(struct epm* epm, unsigned int min_pages)
count = 0x1 << order;

/* prevent kernel from complaining about an invalid argument */
if (order <= MAX_ORDER)
if (order < MAX_ORDER)
epm_vaddr = (vaddr_t) __get_free_pages(GFP_HIGHUSER, order);

#ifdef CONFIG_CMA
Expand Down

0 comments on commit 747e6a1

Please sign in to comment.