Skip to content

Commit

Permalink
lkdtm/usercopy: Moves the KERNEL_DS test to non-canonical
Browse files Browse the repository at this point in the history
The prior implementation of the KERNEL_DS fault checking would work on
any unmapped kernel address, but this was narrowed to the non-canonical
range instead. This adjusts the LKDTM test to match.

Fixes: 00c4237 ("x86-64: add warning for non-canonical user access address dereferences")
Signed-off-by: Kees Cook <keescook@chromium.org>
  • Loading branch information
Kees Cook committed Apr 7, 2019
1 parent 8c2ffd9 commit 2bf8496
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/misc/lkdtm/usercopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,16 @@ void lkdtm_USERCOPY_KERNEL(void)

void lkdtm_USERCOPY_KERNEL_DS(void)
{
char __user *user_ptr = (char __user *)ERR_PTR(-EINVAL);
char __user *user_ptr =
(char __user *)(0xFUL << (sizeof(unsigned long) * 8 - 4));
mm_segment_t old_fs = get_fs();
char buf[10] = {0};

pr_info("attempting copy_to_user on unmapped kernel address\n");
pr_info("attempting copy_to_user() to noncanonical address: %px\n",
user_ptr);
set_fs(KERNEL_DS);
if (copy_to_user(user_ptr, buf, sizeof(buf)))
pr_info("copy_to_user un unmapped kernel address failed\n");
if (copy_to_user(user_ptr, buf, sizeof(buf)) == 0)
pr_err("copy_to_user() to noncanonical address succeeded!?\n");
set_fs(old_fs);
}

Expand Down

0 comments on commit 2bf8496

Please sign in to comment.