From patchwork Mon Jul 30 06:24:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupesh Sharma X-Patchwork-Id: 10548475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D657B14E0 for ; Mon, 30 Jul 2018 06:33:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C51092987D for ; Mon, 30 Jul 2018 06:33:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8B4129880; Mon, 30 Jul 2018 06:33:55 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 83DB22987D for ; Mon, 30 Jul 2018 06:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=E/BFlqbJKbfWhslFnW0x1g0zYUXbGMjhMJe06ZGGyO0=; b=b/g TVJxVWRaG1OVUBlBwhubHc4SzsdrgMZhgXYagDDhi9ugX21Z3jcCIFS/UQY/FjRjSSFGQnbikYVVi lzbZmLGGbxJ8LySDKaHOOkEM0jIE2S6dhY6wiH7iKBsM8wdqzvrr5bzKBfX6xzo3OvJC9qbxJy+EI LSxP3eyNP40Vky7cLlK+e0KfwluZ1LY64OpTiNXT0Mtv9k8NEMiLBYKXN71N+7YbefYRbjPuS7tPO dCT41FxTIT4RhjjOVs6fdwg/9ZhfZ8j76UWtByzli3o7rBma+VR1dtt8WAyRKkV6ygX6Gle5wjy3Y WTKoe4CAR0c/47EMZyZEriLPDLxoYCg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fk1kZ-0005Qr-SU; Mon, 30 Jul 2018 06:33:47 +0000 Received: from mail-pg1-f196.google.com ([209.85.215.196]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fk1kW-0005QN-JM for linux-arm-kernel@lists.infradead.org; Mon, 30 Jul 2018 06:33:46 +0000 Received: by mail-pg1-f196.google.com with SMTP id z8-v6so6677485pgu.8 for ; Sun, 29 Jul 2018 23:33:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kt9ZQAiJsVNxoMrMkwqek1esIb3BwXrUZQNVQU45+VI=; b=jU9I2gwcbYb8CoCs2xm4JO2ckEypxAx6ds8Vn4lLuj08wn5LX9E+WpF0TguWjG/Ahk djPrwwupuxqEIONmxbX/bus8B+pJ/x1MZvhc31ONU8SCFuf6qv7W1NF9VkruGmyMXDyO Fc2RDyWl25gnBy5aEsh3IZH/MVJruJZIbcbSe5sveejLhNAFq2e0++uJA3jSj5IyQ9Vc CFwXHYWZcOlPpnDXNWjooBd2r2eMXh9poE6rZUQ++ssuw6vZZJ0FUbRcniqokIPKf+PJ tUJfrRHf4ImTa+1Y+v08iQyX4LYSY0mkSroATBv8BaJS4Fzlrif1QZbqSv4BfEhMvbAc 0QIw== X-Gm-Message-State: AOUpUlE6owfjzLbhz7GvbyBlk2m2FChmlMmlqLuMYLKDMOERImhOsZAe TDahMiUlCDWuIhoNEgX9hB1tFO90fJc= X-Google-Smtp-Source: AAOMgpeOGkQYieWQnz5sv/3hZiuPjm/Pmd3lMiLk6fsHRhsStmy/7g3N+k9odeUDdmV+OURtjz/NLw== X-Received: by 2002:a63:342:: with SMTP id 63-v6mr14856268pgd.290.1532931908322; Sun, 29 Jul 2018 23:25:08 -0700 (PDT) Received: from localhost ([122.177.135.53]) by smtp.gmail.com with ESMTPSA id d18-v6sm11915423pgo.74.2018.07.29.23.25.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Jul 2018 23:25:06 -0700 (PDT) From: Bhupesh Sharma To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] arm64, kaslr: export offset in VMCOREINFO ELF notes Date: Mon, 30 Jul 2018 11:54:43 +0530 Message-Id: <1532931883-16132-1-git-send-email-bhsharma@redhat.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180729_233344_637004_0FA0EE46 X-CRM114-Status: GOOD ( 16.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ard Biesheuvel , catalin.marinas@arm.com, Bhupesh Sharma , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Will Deacon , takahiro.akashi@linaro.org, James Morse , bhupesh.linux@gmail.com 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 Include KASLR offset in arm64 VMCOREINFO ELF notes to assist in debugging. vmcore parsing in user-space already expects this value in the notes and we are providing it for portability of those existing tools with x86. Ideally we would like core code to do this (so that way this information won't be missed when an architecture adds KASLR support), but mips has CONFIG_RANDOMIZE_BASE, and doesn't provide kaslr_offset(), so I am not sure if this is needed for mips (and other such similar arch cases in future). So, lets keep this architecture specific for now. As an example of a user-space use-case, consider the makedumpfile user-space utility which will need fixup to use this KASLR offset to work with cases where we need to find a way to translate symbol address from vmlinux to kernel run time address in case of KASLR boot on arm64. I have already submitted the makedumpfile user-space patch upstream and the maintainer has suggested to wait for the kernel changes to be included (see [0]). I tested this on my qualcomm amberwing board both for KASLR and non-KASLR boot cases: Without this patch: # cat > scrub.conf << EOF [vmlinux] erase jiffies erase init_task.utime for tsk in init_task.tasks.next within task_struct:tasks erase tsk.utime endfor EOF # makedumpfile --split -d 31 -x vmlinux --config scrub.conf vmcore dumpfile_{1,2,3} readpage_elf: Attempt to read non-existent page at 0xffffa8a5bf180000. readmem: type_addr: 1, addr:ffffa8a5bf180000, size:8 vaddr_to_paddr_arm64: Can't read pgd readmem: Can't convert a virtual address(ffff0000092a542c) to physical address. readmem: type_addr: 0, addr:ffff0000092a542c, size:390 check_release: Can't get the address of system_utsname After this patch check_release() is ok, and also we are able to erase symbol from vmcore (I checked this with kernel 4.18.0-rc4+): # makedumpfile --split -d 31 -x vmlinux --config scrub.conf vmcore dumpfile_{1,2,3} The kernel version is not supported. The makedumpfile operation may be incomplete. Checking for memory holes : [100.0 %] \ Checking for memory holes : [100.0 %] | Checking foExcluding unnecessary pages : [100.0 %] \ Excluding unnecessary pages : [100.0 %] \ The dumpfiles are saved to dumpfile_1, dumpfile_2, and dumpfile_3. makedumpfile Completed. [0] https://www.spinics.net/lists/kexec/msg21195.html Cc: Ard Biesheuvel Cc: Will Deacon Cc: Mark Rutland Cc: Catalin Marinas Cc: James Morse Signed-off-by: Bhupesh Sharma Acked-by: James Morse --- Changes since v1: - Addressed review comments from James regarding commit log - v1 can be viewed here: https://lkml.org/lkml/2018/7/18/951 - v2 is rebased against linux-next/master arch/arm64/kernel/machine_kexec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index f62effc6e064..028df356a5fd 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -360,4 +360,5 @@ void arch_crash_save_vmcoreinfo(void) kimage_voffset); vmcoreinfo_append_str("NUMBER(PHYS_OFFSET)=0x%llx\n", PHYS_OFFSET); + vmcoreinfo_append_str("KERNELOFFSET=%lx\n", kaslr_offset()); }