From nobody Thu Apr 9 12:31:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 361A1C43219 for ; Fri, 4 Nov 2022 11:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231671AbiKDLbi (ORCPT ); Fri, 4 Nov 2022 07:31:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbiKDLbg (ORCPT ); Fri, 4 Nov 2022 07:31:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70697B1C4 for ; Fri, 4 Nov 2022 04:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667561439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E9ieE4VIDGcBaiULL1C+z5L6S0lWIm/B8H9v1NRSxPo=; b=gAR02Aj8AYRUhmjLI+TOuvOa+bDU/kEgG/NAnDulhvyWd8SraunnW4oX4aDpnEJJfAZsqk /rLjlbiVA8pqWZVTXqT6JXTtZv7XyNkT1KM7SFFZmEsolnPtefNwP/CmfEfu6CTYNpxtZV Hq1Mv6Rz0Bb320aewkmAyXBzMSmQ+U0= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-282-2zYp7OsXMkWZ78UyaOendA-1; Fri, 04 Nov 2022 07:30:38 -0400 X-MC-Unique: 2zYp7OsXMkWZ78UyaOendA-1 Received: by mail-pg1-f200.google.com with SMTP id k71-20020a63844a000000b004701e90da0dso2309333pgd.22 for ; Fri, 04 Nov 2022 04:30:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E9ieE4VIDGcBaiULL1C+z5L6S0lWIm/B8H9v1NRSxPo=; b=LR0toxKy55NaIPecI2j16LdYZ+EMsixUPcVlxbNunuZgG4bXQz1L6lq2oaCyZy1rE+ OUA8/XkLOr0OvMzc/CVaBxuRLqzJEvspW8elWUp7slP2HJdyflf1bRjV7FNU+X1JMP7D sJ9qpqihn/cEuoTfeWlcUPNGmiZQIXiwoM5yC5r3hRYh+Lff7RUi3Bcxl8FKcJDY0e51 Lj4RGahAdBze7AFc4Ns4ln1aV9bTVbk97AHkCZlMWkRANwzJkh9ybMfXMICsrg5kZh7i U3lnTyNx6JD0R115QDxIKctUP6T6GiPgXPAU2eAUIdA9pvcOzbLhQ6bmnZ8XBG2+RPsn RoDw== X-Gm-Message-State: ACrzQf0lpbRYmegEFc97syZVTIK3HBL+6wP7c+GSdk73noB2bApzih0y d88JOwsGpUSpZOn4jYcpboolCg3kJY7bU9IeaIghbGI9PN5X9B+KskRXnol3LSuOPjQeCaFnV0P UagvIawz2GyArX7Azh0CZQbg3 X-Received: by 2002:a17:902:f28b:b0:186:b069:63fc with SMTP id k11-20020a170902f28b00b00186b06963fcmr35566382plc.38.1667561437565; Fri, 04 Nov 2022 04:30:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qypMeRgTqbqOB76+RxKWKqrfx12CwgsfSjDZBxgJGySGlq0PpZpwe2FJNfIghklVFI91+FQ== X-Received: by 2002:a17:902:f28b:b0:186:b069:63fc with SMTP id k11-20020a170902f28b00b00186b06963fcmr35566345plc.38.1667561437294; Fri, 04 Nov 2022 04:30:37 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k30-20020aa7999e000000b0056bcfe015c9sm2458149pfh.204.2022.11.04.04.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 04:30:36 -0700 (PDT) From: Coiby Xu To: kexec@lists.infradead.org Cc: Milan Broz , Thomas Staudt , Kairui Song , dm-devel@redhat.com, Jan Pazdziora , Pingfan Liu , Baoquan He , Dave Young , linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Eric Biederman Subject: [RFC v2 3/5] x86/crash: pass the LUKS volume key to kdump kernel Date: Fri, 4 Nov 2022 19:29:58 +0800 Message-Id: <20221104113000.487098-4-coxu@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221104113000.487098-1-coxu@redhat.com> References: <20221104113000.487098-1-coxu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 1st kernel will build up the kernel command parameter luksvolumekey as similar to elfcorehdr to pass the memory address of the stored info of LUKS volume key to kdump kernel. Signed-off-by: Coiby Xu --- arch/x86/include/asm/crash.h | 1 + arch/x86/kernel/crash.c | 47 ++++++++++++++++++++++++++++++- arch/x86/kernel/kexec-bzimage64.c | 7 +++++ include/linux/kexec.h | 4 +++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/crash.h b/arch/x86/include/asm/crash.h index 8b6bd63530dc..485f75dce2ca 100644 --- a/arch/x86/include/asm/crash.h +++ b/arch/x86/include/asm/crash.h @@ -4,6 +4,7 @@ =20 struct kimage; =20 +int crash_load_luks_volume_key(struct kimage *image); int crash_load_segments(struct kimage *image); int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params); diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 9730c88530fc..5ceda2802482 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -304,6 +304,7 @@ static int memmap_exclude_ranges(struct kimage *image, = struct crash_mem *cmem, unsigned long long mend) { unsigned long start, end; + int r; =20 cmem->ranges[0].start =3D mstart; cmem->ranges[0].end =3D mend; @@ -312,7 +313,19 @@ static int memmap_exclude_ranges(struct kimage *image,= struct crash_mem *cmem, /* Exclude elf header region */ start =3D image->elf_load_addr; end =3D start + image->elf_headers_sz - 1; - return crash_exclude_mem_range(cmem, start, end); + r =3D crash_exclude_mem_range(cmem, start, end); + + if (r) + return r; + + /* Exclude LUKS volume key region */ + if (image->luks_volume_key_addr) { + start =3D image->luks_volume_key_addr; + end =3D start + image->luks_volume_key_sz - 1; + return crash_exclude_mem_range(cmem, start, end); + } + + return r; } =20 /* Prepare memory map for crash dump kernel */ @@ -383,6 +396,38 @@ int crash_setup_memmap_entries(struct kimage *image, s= truct boot_params *params) return ret; } =20 +int crash_load_luks_volume_key(struct kimage *image) +{ + int ret; + struct kexec_buf kbuf =3D { + .image =3D image, + .buf_min =3D 0, + .buf_max =3D ULONG_MAX, + .top_down =3D false, + .random =3D true, + }; + + image->luks_volume_key_addr =3D 0; + ret =3D crash_pass_temp_luks_volume_key(&kbuf.buffer, &kbuf.bufsz); + if (ret) + return ret; + + kbuf.memsz =3D kbuf.bufsz; + kbuf.buf_align =3D ELF_CORE_HEADER_ALIGN; + kbuf.mem =3D KEXEC_BUF_MEM_UNKNOWN; + ret =3D kexec_add_buffer(&kbuf); + if (ret) { + vfree((void *)kbuf.buffer); + return ret; + } + image->luks_volume_key_addr =3D kbuf.mem; + image->luks_volume_key_sz =3D kbuf.bufsz; + pr_debug("Loaded LUKS volume key at 0x%lx bufsz=3D0x%lx memsz=3D0x%lx\n", + image->luks_volume_key_addr, kbuf.bufsz, kbuf.bufsz); + + return ret; +} + int crash_load_segments(struct kimage *image) { int ret; diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzim= age64.c index f299b48f9c9f..e556dbf96695 100644 --- a/arch/x86/kernel/kexec-bzimage64.c +++ b/arch/x86/kernel/kexec-bzimage64.c @@ -75,6 +75,10 @@ static int setup_cmdline(struct kimage *image, struct bo= ot_params *params, if (image->type =3D=3D KEXEC_TYPE_CRASH) { len =3D sprintf(cmdline_ptr, "elfcorehdr=3D0x%lx ", image->elf_load_addr); + + if (image->luks_volume_key_addr !=3D 0) + len +=3D sprintf(cmdline_ptr + len, + "luksvolumekey=3D0x%lx ", image->luks_volume_key_addr); } memcpy(cmdline_ptr + len, cmdline, cmdline_len); cmdline_len +=3D len; @@ -371,6 +375,9 @@ static void *bzImage64_load(struct kimage *image, char = *kernel, ret =3D crash_load_segments(image); if (ret) return ERR_PTR(ret); + ret =3D crash_load_luks_volume_key(image); + if (ret) + pr_debug("Either no LUKS volume key or error to retrieve the LUKS volum= e key\n"); } =20 /* diff --git a/include/linux/kexec.h b/include/linux/kexec.h index c0edb64bf6c4..ed7a0ec70129 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -385,6 +385,10 @@ struct kimage { void *elf_headers; unsigned long elf_headers_sz; unsigned long elf_load_addr; + + /* LUKS volume key buffer */ + unsigned long luks_volume_key_addr; + unsigned long luks_volume_key_sz; }; =20 /* kexec interface functions */ --=20 2.37.3