Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752885AbcLKAvW (ORCPT ); Sat, 10 Dec 2016 19:51:22 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:34654 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751639AbcLKAvT (ORCPT ); Sat, 10 Dec 2016 19:51:19 -0500 From: Alexander Popov To: Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , Rob Herring , Kefeng Wang , AKASHI Takahiro , Jon Masters , David Daney , Ganapatrao Kulkarni , Andrew Morton , Dmitry Vyukov , Nicolai Stange , James Morse , Andrey Ryabinin , Andrey Konovalov , Alexander Popov , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, syzkaller Subject: [PATCH 2/2] kcov: make kcov work properly with KASLR enabled Date: Sun, 11 Dec 2016 03:50:56 +0300 Message-Id: <1481417456-28826-3-git-send-email-alex.popov@linux.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481417456-28826-1-git-send-email-alex.popov@linux.com> References: <1481417456-28826-1-git-send-email-alex.popov@linux.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1131 Lines: 43 Subtract KASLR offset from the kernel addresses reported by kcov. Tested on x86_64 and AArch64 (Hikey LeMaker). Signed-off-by: Alexander Popov --- kernel/kcov.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/kcov.c b/kernel/kcov.c index 3cbb0c8..f8f3f4c 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -14,6 +14,7 @@ #include #include #include +#include /* * kcov descriptor (one per opened debugfs file). @@ -68,6 +69,11 @@ void notrace __sanitizer_cov_trace_pc(void) if (mode == KCOV_MODE_TRACE) { unsigned long *area; unsigned long pos; + unsigned long ip = _RET_IP_; + +#ifdef CONFIG_RANDOMIZE_BASE + ip -= kaslr_offset(); +#endif /* * There is some code that runs in interrupts but for which @@ -81,7 +87,7 @@ void notrace __sanitizer_cov_trace_pc(void) /* The first word is number of subsequent PCs. */ pos = READ_ONCE(area[0]) + 1; if (likely(pos < t->kcov_size)) { - area[pos] = _RET_IP_; + area[pos] = ip; WRITE_ONCE(area[0], pos); } } -- 2.7.4