Skip to content

Commit 4c41115

Browse files
chleroykees
authored andcommitted
lkdtm: Print real addresses
Today, when doing a lkdtm test before the readiness of the random generator, (ptrval) is printed instead of the address at which it perform the fault: [ 1597.337030] lkdtm: Performing direct entry EXEC_USERSPACE [ 1597.337142] lkdtm: attempting ok execution at (ptrval) [ 1597.337398] lkdtm: attempting bad execution at (ptrval) [ 1597.337460] kernel tried to execute user page (77858000) -exploit attempt? (uid: 0) [ 1597.344769] Unable to handle kernel paging request for instruction fetch [ 1597.351392] Faulting instruction address: 0x77858000 [ 1597.356312] Oops: Kernel access of bad area, sig: 11 [#1] If the lkdtm test is done later on, it prints an hashed address. In both cases this is pointless. The purpose of the test is to ensure the kernel generates an Oops at the expected address, so real addresses needs to be printed. This patch fixes that. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent a77d087 commit 4c41115

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/misc/lkdtm/perms.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ static noinline void execute_location(void *dst, bool write)
4747
{
4848
void (*func)(void) = dst;
4949

50-
pr_info("attempting ok execution at %p\n", do_nothing);
50+
pr_info("attempting ok execution at %px\n", do_nothing);
5151
do_nothing();
5252

5353
if (write == CODE_WRITE) {
5454
memcpy(dst, do_nothing, EXEC_SIZE);
5555
flush_icache_range((unsigned long)dst,
5656
(unsigned long)dst + EXEC_SIZE);
5757
}
58-
pr_info("attempting bad execution at %p\n", func);
58+
pr_info("attempting bad execution at %px\n", func);
5959
func();
6060
}
6161

@@ -66,14 +66,14 @@ static void execute_user_location(void *dst)
6666
/* Intentionally crossing kernel/user memory boundary. */
6767
void (*func)(void) = dst;
6868

69-
pr_info("attempting ok execution at %p\n", do_nothing);
69+
pr_info("attempting ok execution at %px\n", do_nothing);
7070
do_nothing();
7171

7272
copied = access_process_vm(current, (unsigned long)dst, do_nothing,
7373
EXEC_SIZE, FOLL_WRITE);
7474
if (copied < EXEC_SIZE)
7575
return;
76-
pr_info("attempting bad execution at %p\n", func);
76+
pr_info("attempting bad execution at %px\n", func);
7777
func();
7878
}
7979

@@ -82,7 +82,7 @@ void lkdtm_WRITE_RO(void)
8282
/* Explicitly cast away "const" for the test. */
8383
unsigned long *ptr = (unsigned long *)&rodata;
8484

85-
pr_info("attempting bad rodata write at %p\n", ptr);
85+
pr_info("attempting bad rodata write at %px\n", ptr);
8686
*ptr ^= 0xabcd1234;
8787
}
8888

@@ -100,7 +100,7 @@ void lkdtm_WRITE_RO_AFTER_INIT(void)
100100
return;
101101
}
102102

103-
pr_info("attempting bad ro_after_init write at %p\n", ptr);
103+
pr_info("attempting bad ro_after_init write at %px\n", ptr);
104104
*ptr ^= 0xabcd1234;
105105
}
106106

@@ -112,7 +112,7 @@ void lkdtm_WRITE_KERN(void)
112112
size = (unsigned long)do_overwritten - (unsigned long)do_nothing;
113113
ptr = (unsigned char *)do_overwritten;
114114

115-
pr_info("attempting bad %zu byte write at %p\n", size, ptr);
115+
pr_info("attempting bad %zu byte write at %px\n", size, ptr);
116116
memcpy(ptr, (unsigned char *)do_nothing, size);
117117
flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size));
118118

@@ -185,11 +185,11 @@ void lkdtm_ACCESS_USERSPACE(void)
185185

186186
ptr = (unsigned long *)user_addr;
187187

188-
pr_info("attempting bad read at %p\n", ptr);
188+
pr_info("attempting bad read at %px\n", ptr);
189189
tmp = *ptr;
190190
tmp += 0xc0dec0de;
191191

192-
pr_info("attempting bad write at %p\n", ptr);
192+
pr_info("attempting bad write at %px\n", ptr);
193193
*ptr = tmp;
194194

195195
vm_munmap(user_addr, PAGE_SIZE);

0 commit comments

Comments
 (0)