Skip to content

Commit

Permalink
kmsan: print addresses in reports when possible
Browse files Browse the repository at this point in the history
This is currently only possible for kmsan_check_memory()
  • Loading branch information
ramosian-glider committed Jun 7, 2018
1 parent 6bcacad commit b047672
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions mm/kmsan/kmsan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ inline void *return_address(int arg)
// |deep| is a dirty hack to skip an additional frame when calling
// kmsan_report() from kmsan_copy_to_user().
inline void kmsan_report(void *caller, depot_stack_handle_t origin,
int size, int off_first, int off_last, bool deep)
u64 address, int size, int off_first, int off_last, bool deep)
{
unsigned long flags;
struct stack_trace trace;
Expand Down Expand Up @@ -1093,6 +1093,9 @@ inline void kmsan_report(void *caller, depot_stack_handle_t origin,
else
kmsan_pr_err("Bytes %d-%d of %d are uninitialized\n", off_first, off_last, size);
}
if (address) {
kmsan_pr_err("Memory access starts at %px\n", address);
}
kmsan_pr_err("==================================================================\n");
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
spin_unlock_irqrestore(&report_lock, flags);
Expand Down Expand Up @@ -1171,7 +1174,7 @@ void kmsan_internal_check_memory(const void *addr, size_t size)
for (i = 0; i < size; i++) {
if (!shadow[i]) {
if (prev_start != -1)
kmsan_report(_THIS_IP_, prev_origin, size, prev_start, i - 1, /*deep*/true);
kmsan_report(_THIS_IP_, prev_origin, addr, size, prev_start, i - 1, /*deep*/true);
prev_origin = 0;
prev_start = -1;
continue;
Expand All @@ -1184,13 +1187,13 @@ void kmsan_internal_check_memory(const void *addr, size_t size)
continue;
}
if (origin != prev_origin) {
kmsan_report(_THIS_IP_, prev_origin, size, prev_start, i - 1, /*deep*/true);
kmsan_report(_THIS_IP_, prev_origin, addr, size, prev_start, i - 1, /*deep*/true);
prev_origin = origin;
prev_start = i;
}
}
if (prev_origin) {
kmsan_report(_THIS_IP_, prev_origin, size, prev_start, size - 1, /*deep*/true);
kmsan_report(_THIS_IP_, prev_origin, addr, size, prev_start, size - 1, /*deep*/true);
}
LEAVE_RUNTIME(irq_flags);
}
Expand Down
3 changes: 2 additions & 1 deletion mm/kmsan/kmsan.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ depot_stack_handle_t kmsan_internal_chain_origin(depot_stack_handle_t id, bool f
void do_kmsan_thread_create(struct task_struct *task);
void kmsan_set_origin(u64 address, int size, u32 origin);
inline void kmsan_report(void *caller, depot_stack_handle_t origin,
int size, int off_first, int off_last, bool deep);
u64 address, int size,
int off_first, int off_last, bool deep);

int kmsan_alloc_meta_for_pages(struct page *page, unsigned int order,
gfp_t flags, int node);
Expand Down
3 changes: 2 additions & 1 deletion mm/kmsan/kmsan_instr.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ void __msan_warning_32(u32 origin)
return;
ENTER_RUNTIME(irq_flags);
caller = __builtin_return_address(0);
kmsan_report(caller, origin, /*size*/0, /*off_first*/0, /*off_last*/0, /*deep*/false);
kmsan_report(caller, origin, /*address*/0, /*size*/0,
/*off_first*/0, /*off_last*/0, /*deep*/false);
LEAVE_RUNTIME(irq_flags);
}
EXPORT_SYMBOL(__msan_warning_32);
Expand Down

0 comments on commit b047672

Please sign in to comment.