Skip to content

Commit

Permalink
arch, pagetables: fix vmap()'s initial va alignment check
Browse files Browse the repository at this point in the history
It should check VA alignment based on requested order, not just
PAGE_MASK (4K pages order).

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Jul 11, 2022
1 parent a53e1b4 commit ef13eb9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arch/x86/pagetables.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void *vmap(void *va, mfn_t mfn, unsigned int order,
mfn_t l1t_mfn, l2t_mfn, l3t_mfn;
pgentry_t *tab, *entry;

if (!va || _ul(va) & ~PAGE_MASK)
if (!va || (_ul(va) & ~PAGE_ORDER_TO_MASK(order)))
return NULL;

dprintk("%s: va: %p mfn: 0x%lx (order: %u)\n", __func__, va, mfn, order);
Expand Down
2 changes: 2 additions & 0 deletions include/arch/x86/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#define MAX_PAGE_ORDER PAGE_ORDER_1G
#define PAGE_ORDER_INVALID (-1)

#define PAGE_ORDER_TO_MASK(order) (~((PAGE_SIZE << (order)) - 1))

#define _PAGE_PRESENT 0x0001
#define _PAGE_RW 0x0002
#define _PAGE_USER 0x0004
Expand Down

0 comments on commit ef13eb9

Please sign in to comment.