From patchwork Sun Dec 11 00:50:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 9469553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 918AB60231 for ; Sun, 11 Dec 2016 00:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80031281D2 for ; Sun, 11 Dec 2016 00:54:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72A6028420; Sun, 11 Dec 2016 00:54:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 282CA281D2 for ; Sun, 11 Dec 2016 00:54:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cFsN2-0006iW-9h; Sun, 11 Dec 2016 00:52:04 +0000 Received: from mail-lf0-f65.google.com ([209.85.215.65]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cFsMc-0006f0-RE for linux-arm-kernel@lists.infradead.org; Sun, 11 Dec 2016 00:51:39 +0000 Received: by mail-lf0-f65.google.com with SMTP id p100so3137118lfg.2 for ; Sat, 10 Dec 2016 16:51:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=O7In3Dr711/yRAniLqaqnsWsiwnnuA4Cyh9q8xXMW8M=; b=ax3Oa5BTFR8RSV+Sa4PNrUNI69ymZcrwpLR2nBxA2H5svXOqp28VQkCOAl+YyTFmr6 vlke8nLjjZII7GBXvlba95sH92h8VRjkGZg2TPezYBCHV1+xGUb2CJlK2okYjT07uhQ+ PeRW7KK7So+G1Ve+kWoXjU2lKoWbVSM8T14xmUaBaApm9hNVm0hy4JEPf1sbtb7Teuua 7ePlOpnrZy2CQsSoIz5uY7f9eYA0z+W5NGMzqRF7a83sdqtSmEPQYx1WPbwh04jGBTTh VTzUMB/5N4VL63D32UhJaaOOuSWuezzJXImU9xezf33n3eCf5VizLh9nsCL/4SkCwjCV LuvQ== X-Gm-Message-State: AKaTC01g38O4MCuEuQd5pSwzLm6QjDwpxV8flZa2b9lYSpW8D3RN0S0wu4WuIs+7qmV+/w== X-Received: by 10.46.72.18 with SMTP id v18mr30482876lja.12.1481417478130; Sat, 10 Dec 2016 16:51:18 -0800 (PST) Received: from localhost.localdomain (95-26-155-251.broadband.corbina.ru. [95.26.155.251]) by smtp.gmail.com with ESMTPSA id 17sm7739080ljh.39.2016.12.10.16.51.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Dec 2016 16:51:17 -0800 (PST) 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161210_165139_138276_0158D920 X-CRM114-Status: GOOD ( 13.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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); } }