Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2083891ybb; Fri, 29 Mar 2019 18:38:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwd/y8MYn1o+9pZGn0H37TZmIKO9TymSKy186lVwU8uwnbnRP+dHsODIrSSB4fm0NRGUEYO X-Received: by 2002:a65:50c2:: with SMTP id s2mr40916853pgp.112.1553909897048; Fri, 29 Mar 2019 18:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553909897; cv=none; d=google.com; s=arc-20160816; b=uATcXR1tR7U3up532ri/5Q0jeRYLH+KwmruIqpATTRmXJhTmHMisrNHGOHHGRHA0kA FpJWGt8wNQvQeWeoeFYaMfyNjW8vMdvrxnuOi/TMYKhhUG6sJFlLFGZJPy+y3eeuvW8u Pt9X7RspOg6xTVF7dKhWy9fMY0N5HQL20N778sLHrCn2XiJ+X/ILVYrQBx2+QlODhtsJ ECmrC9MTEaWDZPASggnoIKr+BXOc+nVBq4Q7DZ3/sn8IuQ9UMCY8vZd8xb5WjKBZUMa1 FoJUCmgVv8Hz/0iUCVfen+al1Ji3kjf6pdHSY7gyAtBZ+a+DyjLRGFhXu8wXbLkTrr1w dKwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=f/ONcfJbq63kJrnk1Hc9EWoMWj34/Pn32VyXM6CTut0=; b=BygOi19yDUt7cDjdlPbpFLZWYsrhmTtJqt3LrZcGnmBRzNhuBxkpOVNKPICGCS8oeR iI20guIOqiR7tC04lsLK7G0pnC1zzXJUW1C4YKVEvVecrmgRhOabh0DbISKXQ2BuKKoY fhHzHl2YYeg7+XAbaHWDtcS8WcVYc4oM+DytfXfBFDx+/VS3rAi4Bgwu+CveQYI8Tjk/ O2zG94SJMFyIOyCcmvW3PNsRZ0UA0C4Rx2iEyDp2V/zjxUAK81LrIBZqsPZivB6vS8rc d1CAnGJvDh4pF0QUHY+bd1phjtJZgD+2vgqyKAG6XNNHy58bg1okmr+4fAog+TtghNoD XUqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cvlGxQEg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w67si3258490pfb.20.2019.03.29.18.38.01; Fri, 29 Mar 2019 18:38:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cvlGxQEg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730928AbfC3BbR (ORCPT + 99 others); Fri, 29 Mar 2019 21:31:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:38624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730933AbfC3BbL (ORCPT ); Fri, 29 Mar 2019 21:31:11 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 897AD218D8; Sat, 30 Mar 2019 01:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909470; bh=KWCTemIsquG7Y9GTcsTvkGOFi4ehdUv/YZSv8/UFDoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cvlGxQEgMbRUvPaLpd9SCfLnpT2pbT9ITe99fHLaCf+nPDiiniRn4BEr9sw4hzPVv FnfGN0iKkWPqBcfSXenDQsGp6gHD0ey7jTYIdsBUktspuxVACImC+PbvxSji4m5MLa VCevPB8P4kQLZdbwcMl+oNHoEDyoE5Mc4Nf9UYfE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christophe Leroy , Kees Cook , Sasha Levin Subject: [PATCH AUTOSEL 4.14 26/37] lkdtm: Print real addresses Date: Fri, 29 Mar 2019 21:30:09 -0400 Message-Id: <20190330013020.379-26-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330013020.379-1-sashal@kernel.org> References: <20190330013020.379-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe Leroy [ Upstream commit 4c411157a42f122051ae3469bee0b5cabe89e139 ] 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 Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- drivers/misc/lkdtm_perms.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/misc/lkdtm_perms.c b/drivers/misc/lkdtm_perms.c index 53b85c9d16b8..fa54add6375a 100644 --- a/drivers/misc/lkdtm_perms.c +++ b/drivers/misc/lkdtm_perms.c @@ -47,7 +47,7 @@ static noinline void execute_location(void *dst, bool write) { void (*func)(void) = dst; - pr_info("attempting ok execution at %p\n", do_nothing); + pr_info("attempting ok execution at %px\n", do_nothing); do_nothing(); if (write == CODE_WRITE) { @@ -55,7 +55,7 @@ static noinline void execute_location(void *dst, bool write) flush_icache_range((unsigned long)dst, (unsigned long)dst + EXEC_SIZE); } - pr_info("attempting bad execution at %p\n", func); + pr_info("attempting bad execution at %px\n", func); func(); } @@ -66,14 +66,14 @@ static void execute_user_location(void *dst) /* Intentionally crossing kernel/user memory boundary. */ void (*func)(void) = dst; - pr_info("attempting ok execution at %p\n", do_nothing); + pr_info("attempting ok execution at %px\n", do_nothing); do_nothing(); copied = access_process_vm(current, (unsigned long)dst, do_nothing, EXEC_SIZE, FOLL_WRITE); if (copied < EXEC_SIZE) return; - pr_info("attempting bad execution at %p\n", func); + pr_info("attempting bad execution at %px\n", func); func(); } @@ -82,7 +82,7 @@ void lkdtm_WRITE_RO(void) /* Explicitly cast away "const" for the test. */ unsigned long *ptr = (unsigned long *)&rodata; - pr_info("attempting bad rodata write at %p\n", ptr); + pr_info("attempting bad rodata write at %px\n", ptr); *ptr ^= 0xabcd1234; } @@ -100,7 +100,7 @@ void lkdtm_WRITE_RO_AFTER_INIT(void) return; } - pr_info("attempting bad ro_after_init write at %p\n", ptr); + pr_info("attempting bad ro_after_init write at %px\n", ptr); *ptr ^= 0xabcd1234; } @@ -112,7 +112,7 @@ void lkdtm_WRITE_KERN(void) size = (unsigned long)do_overwritten - (unsigned long)do_nothing; ptr = (unsigned char *)do_overwritten; - pr_info("attempting bad %zu byte write at %p\n", size, ptr); + pr_info("attempting bad %zu byte write at %px\n", size, ptr); memcpy(ptr, (unsigned char *)do_nothing, size); flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size)); @@ -185,11 +185,11 @@ void lkdtm_ACCESS_USERSPACE(void) ptr = (unsigned long *)user_addr; - pr_info("attempting bad read at %p\n", ptr); + pr_info("attempting bad read at %px\n", ptr); tmp = *ptr; tmp += 0xc0dec0de; - pr_info("attempting bad write at %p\n", ptr); + pr_info("attempting bad write at %px\n", ptr); *ptr = tmp; vm_munmap(user_addr, PAGE_SIZE); -- 2.19.1