From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35B8A3A0B1C for ; Mon, 11 May 2026 10:46:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778496399; cv=none; b=YB7NGKpmogPQpgVPAr+gj/90LNATcMmdf3bE9DVE34itor27uzUFdjOTWUp/0OvhxzrfKL7bVAl24LHJxgPdQoSUMhXsmj4MkULbYhF4EOyx1HM/xF8hXsi3h5PgHAAotasi+pfqDGZGrE3W67tACzdtt53FrRljUssqIxg/lqk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778496399; c=relaxed/simple; bh=Y5mUbefp9XBFg6fpQ787wEyH+xfV2Y7Jsw0fmz0xXRE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kTlsbOGVR1ya+3cvWcwUnH9tXnhb2i+oj4LtcWLHYNXz63xCK2d9RfaxGn7FdfGoCth1iYAJ0Ib+CfCr7SGs36+wVzNhuATN7+QpGeOScAv9eYZtnKRLxrKT5b/BRxePAVVgem+8UT2jEtIm2UkO4fwhPr8h2AYGCTA1QYMNaXg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hev.cc; spf=pass smtp.mailfrom=hev.cc; dkim=pass (2048-bit key) header.d=hev-cc.20251104.gappssmtp.com header.i=@hev-cc.20251104.gappssmtp.com header.b=M3i02A0g; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hev.cc Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hev.cc Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hev-cc.20251104.gappssmtp.com header.i=@hev-cc.20251104.gappssmtp.com header.b="M3i02A0g" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-8353ca0f1f1so2038725b3a.1 for ; Mon, 11 May 2026 03:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hev-cc.20251104.gappssmtp.com; s=20251104; t=1778496396; x=1779101196; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HkqpHwr57m2TFfldzHKpZdrF2VStUjZkl//5CCmr3Dc=; b=M3i02A0gvfvLhkzU9/PTtWf1vGngR0Vx6YLidbVldeXHSdopgzIjZZZsn+/xij9Tet pykihI8whhvNY74oGw0ov3yp+fdiIH1CoAwWrP7KSg4Wxnfh75UFV2TEA0ad1kOV7egu 9CPSehPXPGQSMCedDB8JEs29fqlNAvCSVq4SRFzUZXRCFwzngTTcLig8WfbOmskKqKVs 6dQ6AcUPKZQHImq6ZRV5fjlEBsj8b9FAzw4vY27cLM0bRzeFxpW0Jtw+8a3siOzhYVE9 EM5jnlrSln2dsIELRc97hJ8hf/32C6hGkddbAJd7AjBi8j459+fTxV78UKS7qNdZFCAg j9Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778496396; x=1779101196; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HkqpHwr57m2TFfldzHKpZdrF2VStUjZkl//5CCmr3Dc=; b=gLpQ9Y8Oe0b74itsP24s0aR0hQVrl49ijvjU3VjsoxLq0pMrwqDDH9qL+BIHNexUzy zGWiQNOyCh9iQ8ZQECNIGEX1/LC6i1FhNNRIKjeMI/g8NA/H87bJbPaX8FpiYRZkcI33 AN9/mc0vkgyPcmH6vnwvrFmFd0r8TfrQCN2EoJ/+ch7sI2QiXoJrcI4ZNN1MhMBoZ7AW xgn0IQGguNkPZbsT3JMks25v/03kLHwxBBPXPpolCmzXsqXpijSNUNXv9tS9zuuua+Ha LWsuIRDLqkOE3tKBd1KaB1IEOUbAj22sIzU3kNaVudTabRpxC/B/DznzaH1Sx7NsNp9a w00g== X-Forwarded-Encrypted: i=1; AFNElJ998Sc5+8uj5v86d55ekdQ4sMIFHlM1u3CiPK7VECtUocVROYH4LYts7IORLh/lI6kdRLY96VEQYm3VPwc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4keC8oh/GCGHy9fv9CWPLj4dHpsWpJsX/JMrzT+O87k0w+IxD aw+vrp920IlC0kCkLmJEVVmDRElpyrEQRVOGMPXoTa6pNNiO1glJv+cvcwRXpvrdk0s= X-Gm-Gg: Acq92OEdupZ5L0yKK2Pa/G+Swy72UuHhCMKbBE2fzhvHMFORNPSXTwrlYxr3eIwqXru i1/RltCjU8HFmOr6H22t89t5xoBA0hSdtODtRXe9ZhuG1iiQqPmTeBCm7y7abXiTWSLzoVksPac riY+CDdpiKhft0vVNSy2OtJbU3X9T/GlcanXISnBlOWrv5D2JfBIYwZxPakOtT2Nzk6RS9Y2Fsn awVl1KuFr4dIzuZX2pp9oKPVTRv/Lmiv057N0T2EZ0YJ+UwTQE/c4wimGGuxF0qqP8B9Ts4XlWI nWRf+SVLQWIrGKtB6oTG/urlZB56Cj/6kbcjo/AchAi9pk03PiFnYacBc6EWIsFDC0fvht7GvIS nwvKnfD3YAZQxKGTSvySWSHh0UVoEaBioksT4j8ci6oLRMHny2rcvt1SCxOjCI5m+bvsy3e/Svt UukhcPendB X-Received: by 2002:a05:6a00:a214:b0:838:1f6b:dcbc with SMTP id d2e1a72fcca58-83bb65f3f6dmr14902315b3a.6.1778496396421; Mon, 11 May 2026 03:46:36 -0700 (PDT) Received: from localhost ([2400:8902:e002:de3f:344e:4435:2c77:3920]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-839679c861esm24927599b3a.30.2026.05.11.03.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 03:46:35 -0700 (PDT) From: WANG Rui To: Huacai Chen , Ard Biesheuvel Cc: WANG Xuerui , Ilias Apalodimas , Haiyong Sun , Lisa Robinson , loongarch@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, WANG Rui Subject: [PATCH v5 0/3] LoongArch: Move KASLR to EFI stub to avoid initrd overlap Date: Mon, 11 May 2026 18:45:52 +0800 Message-ID: <20260511104555.196270-1-r@hev.cc> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Changes since [v4]: * Add a comment above kaslr_disabled() introducing the terms "strictly-defined KASLR" and "broadly-defined KASLR", and explaining what kaslr_disabled() returns. (Huacai Chen) * Set efi_nokaslr when "resume=" is present, since LoongArch hibernation does not support KASLR. (Huacai Chen) * Adjust local variable declarations, comment wording, and function placement. (Huacai Chen) Changes since [v3]: * Minor cleanups based on review comments. Changes since [v2]: * Add a new patch to prevent initrd overlap during relocation. * Revert changes to the CONFIG_RANDOMIZE_BASE_MAX_OFFSET range. Changes since [v1]: * Drop the patch "LoongArch: Allow rdtime_h() and rdtime_l() in 64-bit builds". * Use random_get_entropy() instead of rdtime_l(). This series addresses a potential overlap issue between the kernel image and the initrd when KASLR is enabled. In the normal boot flow, the bootloader is responsible for loading both vmlinux and the initrd, and it can guarantee that the two do not overlap in memory. However, this assumption only holds as long as neither image changes its location afterwards. The in-kernel KASLR implementation breaks that assumption. When the initrd is placed close to the kernel image, randomizing the kernel location at runtime may move it into the initrd region, leading to memory corruption early during boot. To fix this, this series moves the KASLR logic out of the kernel proper and into the EFI stub. With this change, the final placement of both the kernel image and the initrd is determined by the EFI memory allocator. This ensures that the two allocations are coordinated and cannot overlap. Functionally, the kernel still supports KASLR as before, but the randomization now happens before the kernel is entered, rather than during early kernel relocation. [v4]: https://lore.kernel.org/loongarch/20260429120300.1786210-1-r@hev.cc [v3]: https://lore.kernel.org/loongarch/20260429051318.1581350-1-r@hev.cc [v2]: https://lore.kernel.org/loongarch/20260428040159.1065822-1-r@hev.cc [v1]: https://lore.kernel.org/loongarch/20260427104721.47724-1-r@hev.cc WANG Rui (3): efi/loongarch: Randomize kernel preferred address for KASLR LoongArch: Skip relocation-time KASLR if already applied LoongArch: Avoid initrd overlap during kernel relocation arch/loongarch/include/asm/efi.h | 4 +- arch/loongarch/kernel/relocate.c | 50 +++++++++++++++++++ .../firmware/efi/libstub/efi-stub-helper.c | 4 ++ drivers/firmware/efi/libstub/loongarch.c | 16 ++++++ 4 files changed, 73 insertions(+), 1 deletion(-) -- 2.54.0