Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7037549rwd; Tue, 6 Jun 2023 05:41:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6NfRjBIE4ddw4G/CzMRwpnm1REbIS97K/eoup43+b7GLRgwY5/c3nKrm6t15DkXTMUx+5T X-Received: by 2002:a05:6a00:13a8:b0:64d:f5a:3fd2 with SMTP id t40-20020a056a0013a800b0064d0f5a3fd2mr1981694pfg.28.1686055309006; Tue, 06 Jun 2023 05:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686055308; cv=none; d=google.com; s=arc-20160816; b=uU1H7H/RppOS+tUO0ZxT+FBj8YARZXKS/D/KKguVgiYTjqzOkOuE/AND5gsilSVrQI rvnFRktsXy+jx6MRAtRDLcVh/xmYJoUhdJv29ydH06/JrNY53Z4DUdKgaxnRC07gCJzx baGUjASxlygJvadcN/IuDottgZe3LQn8LemMiyYbw1ydIVIr36KKPD5mPSobUgMJ+a3G Uu+eX6acfIXRue2aJpou64y5bFYT/tRGkRAPuh8hYrGaZ7D5Y4/7Rfr1s64792TOXrcx 5oCu4YO01XKyTUhjtt949kiqGyjzbHKY9dOurdLWXcKCqh1TK//B9xf3m/U/5vUqFohr UVyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9VkYPmR4uwo3dQGo/xrqreqAL15LP1pmyYPpri/bVQI=; b=VKz65g4GlOv9cmzAHjL5eINLlebP5BaqYWfsOmgOU53rrnpUwIMAKD+DcoztJGqN4j drkwg0MKw+BgMCjhFwh2FMJk4F05X1jsdZ9kaF+2z3410fNDeFo6KwK70BLKPcVeLSBD FUGc8dLkbVV7PPhsyXWopXQaGEmHlNlzS6kpEslxdlpB1+I218IDCzyjQNYHWQyTecKD peIQg86Zr+FJci9JVSSAxxtOMpskUg4/Q1uZOLPS5RYH+K+wYDJOFkuj/5FYryLCNwwX PXJ0LV0PmPsstOXvImxIOd4YQ+D2QP93NKMdmQJ4s3FkuoWsu4LJ6NNDxFfpIYOzXcVJ cI9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b="A/uKqwtE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020aa79f45000000b0064cecf7b981si4672913pfr.311.2023.06.06.05.41.36; Tue, 06 Jun 2023 05:41:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b="A/uKqwtE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236845AbjFFMcu (ORCPT + 99 others); Tue, 6 Jun 2023 08:32:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233201AbjFFMct (ORCPT ); Tue, 6 Jun 2023 08:32:49 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AF6610C3 for ; Tue, 6 Jun 2023 05:32:48 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f6e4554453so52758935e9.3 for ; Tue, 06 Jun 2023 05:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1686054766; x=1688646766; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9VkYPmR4uwo3dQGo/xrqreqAL15LP1pmyYPpri/bVQI=; b=A/uKqwtEcKgcSPKr31oKfGQWzCDK+I5uwySB1amNGpoL/G+Ux4zhDv4E04xf3WVRFq S3iIfxO9PFeO56O3e5MIYfHsA2DkNv/h2mpJ8q7CverBninN0QglliYDjavjhaLO5oRg ZNIGSfjRLaJTQgVlSntipLaPFHWACUdYlBqRztLu4IemmeohNlFkUwVUXgVC1nb2AA4k iF9QKa6vzSO1S+ywsL4MbD83dwt1gV9WdnaILv3UHceuQbzhnrBhfIxqS2+pL5bEcoxZ EkoymbRON3DS498HuawQ6nGqW5lNlVpo7gKBu1bvy3YyTFGkRjDcMmmPf/gQ6P0B13tu Gy4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686054766; x=1688646766; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9VkYPmR4uwo3dQGo/xrqreqAL15LP1pmyYPpri/bVQI=; b=Yiz/gNcw/P2s1BzWR1bpFJTglWOQl++x9XSqzuX/SRdG6yR2kTrXn7/Tk1TQYldWGI gzEaMrxFnSgi6lIZVr70aTjVooQsZQYs1ZUahCCADj4Ls4OjqjZClnOw9ZWnJL9jzn8O zvv33Pi5K991EBt1vXF+aW6pTbYZjbPDh0I30N8QJLwDSbXqxIK7NvECIcZBYqD+4LfJ AAm4R4Z+o7sr1DwNLqoc8ze3jt1+O4w6uL4I9rtbyyNkm/rPAJImpMbE9l2qRsGwjRCM 10eAOsNF826Mc3QUVSCLq1u3U87V+UyE5mHKYW6NGHNjXQI0v/lXF8rcpmmsu5qIPPf4 WpeQ== X-Gm-Message-State: AC+VfDyL3U6GIrKvGjOpa1ioGYrqSkfcvQm07fimtd6Eo+RpBNC0PDtf AB+Y3VWXtMCxoBWpYSi70KPpcQ== X-Received: by 2002:a1c:4c15:0:b0:3f6:688:f658 with SMTP id z21-20020a1c4c15000000b003f60688f658mr1733922wmf.20.1686054766516; Tue, 06 Jun 2023 05:32:46 -0700 (PDT) Received: from localhost.localdomain (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id m9-20020a7bce09000000b003f7e6d7f71esm4761868wmc.36.2023.06.06.05.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 05:32:46 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Alexandre Ghiti Subject: [PATCH v3 0/5] riscv: Introduce KASLR Date: Tue, 6 Jun 2023 14:32:37 +0200 Message-Id: <20230606123242.20804-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following KASLR implementation allows to randomize the kernel mapping: - virtually: we expect the bootloader to provide a seed in the device-tree - physically: only implemented in the EFI stub, it relies on the firmware to provide a seed using EFI_RNG_PROTOCOL. arm64 has a similar implementation hence the patch 3 factorizes KASLR related functions for riscv to take advantage. The new virtual kernel location is limited by the early page table that only has one PUD and with the PMD alignment constraint, the kernel can only take < 512 positions. base-commit-tag: v6.4-rc2 Changes in v3: * Rebase on top of 6.4-rc2 * Make RANDOMIZE_BASE depend on 64bit * Fix efi_icache_sync and efi_get_kimg_min_align which were undefined in x86 (and certainly other archs) * Add patch 4 to fix warning on rv32 Changes in v2: * Rebase on top of 6.3-rc1 * Add a riscv cache sync after memcpying the kernel * Add kaslr_offset implementation for KCOV * Add forward declaration to quiet LLVM Alexandre Ghiti (5): riscv: Introduce virtual kernel mapping KASLR riscv: Dump out kernel offset information on panic arm64: libstub: Move KASLR handling functions to efi-stub-helper.c libstub: Fix compilation warning for rv32 riscv: libstub: Implement KASLR by using generic functions arch/arm64/include/asm/efi.h | 4 + arch/riscv/Kconfig | 19 +++ arch/riscv/include/asm/efi.h | 4 + arch/riscv/include/asm/page.h | 3 + arch/riscv/kernel/image-vars.h | 1 + arch/riscv/kernel/pi/Makefile | 2 +- arch/riscv/kernel/pi/cmdline_early.c | 13 ++ arch/riscv/kernel/pi/fdt_early.c | 30 ++++ arch/riscv/kernel/setup.c | 25 +++ arch/riscv/mm/init.c | 36 ++++- drivers/firmware/efi/libstub/arm64-stub.c | 112 +------------ drivers/firmware/efi/libstub/arm64.c | 5 + .../firmware/efi/libstub/efi-stub-helper.c | 151 ++++++++++++++++++ drivers/firmware/efi/libstub/efistub.h | 18 +++ drivers/firmware/efi/libstub/riscv-stub.c | 28 ++-- drivers/firmware/efi/libstub/riscv.c | 5 + 16 files changed, 332 insertions(+), 124 deletions(-) create mode 100644 arch/riscv/kernel/pi/fdt_early.c -- 2.39.2