From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 967CB33A9DD for ; Wed, 29 Apr 2026 05:13:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777439641; cv=none; b=gT+NDvc7DlA7ZBoYlBdcUmiUfkzCyiSSbAU3/QyMSXWKaHXFw5vLpo4nLFM1o4tY/B1O8GW98DUrzvwAc3ed0e3hmaEC4ffD1vcIPX4poaNwANqcgZ9Ru5Jqbyw59YVsXHNI8rqikxkHXkEdcbFQ3p7DEV26cTXZ7zto8bxlMho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777439641; c=relaxed/simple; bh=fLx7XKHTHH6UDvhEAPenncyVd6XtMyelO2DdvXwhRGM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=D+5PeIw2jThUX8vLDX9oOAOmXEp5PIWaHGC1FQr9qju7PuENSsYTCyq7wjOOViFRnLGPrNaRx7BoM6HA0Jqb6PG+aOEclFTsh6SMCb7EAeb6CXk7Z6CrMDuc2I76rMBaHu71q1bhjCFAJ8hD7ezimQtfAhhMQutu2AuAMrdNpCc= 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=fioWP+r6; arc=none smtp.client-ip=209.85.216.48 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="fioWP+r6" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-35691a231a7so8105592a91.3 for ; Tue, 28 Apr 2026 22:13:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hev-cc.20251104.gappssmtp.com; s=20251104; t=1777439639; x=1778044439; 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=bM1p8teMQ8tc32DGf5XZZMDcKwPJm9rYVZ05iIFpvhU=; b=fioWP+r6gaWKHVW/jjMdZ/aEi5L8jQF+p1+WY/YDf8L7Z5o+xIWGPVgDgrT95WxgNw 7ClK9jnFJKFcYMOCAKM7BqbVnm//hfjHqjb3oQdvsyhzmjO/ewtrYJkG+ipFjMQABwat spf2sJgOyftjFzML4S0o/E22d6scICnm/TeIJp3YO0SKA4NtlmHQ6RIgKLnr5sHhNLMs 1m8YZ28CdY0lq7k0jk8aKqCSu7YVEsJh59QmFJqLyLUgPC6Fu2WKEfNzNaAeuVL2gfBc yZaCiqiYsS8rSIgJGmz6S4IJCfN13SWqBP8v1ZucikGJH8iW3/FTsUqKCcWMB1JXmyW5 Td/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777439639; x=1778044439; 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=bM1p8teMQ8tc32DGf5XZZMDcKwPJm9rYVZ05iIFpvhU=; b=F7+qGRUA7183WJx7oCoAqBEL16g7/3mQworFaG/MCYPYcQWAR8T8TCDFGaewZEl5xN ffuIzy1g71tWquZKBxP+Fj4VHrw4w6nPPKNZ2maUPK/HBq3qJ1aCTBihuizdt2jGIZtC c2OQeLhZWE/1isWA40PeFneKqRJsnAa/0t3GMMxj7M1BQxVXRGoRtwRrQDKW50SlAuQb dl50HBRHGI48StqqqnslvDle2PNEi/Ex706S2O07K2flv5TywYDT5S1B8SfQm0Xi5yBA rM0vGg460Zvg6E6WwK5EZgSxqbOtygXin/s/6uoxZ98KTAPwxn+BAPjDhF9JZaSvtEE2 NN/w== X-Forwarded-Encrypted: i=1; AFNElJ8mZ/krwl5BEkUOvxyiSqVd8BQ6Tkc6vXU4VmvQx7GKyU8gTIKpYQEpQWGUnjxE+X1xF8nhM4o74gFasxw=@vger.kernel.org X-Gm-Message-State: AOJu0YzxGDga+GHqaNBdbu7v5eSjv9kdWDeh6h9R7RYkDyyOgdCbIZ61 NMfkvEPErKOxzcwbFLXYInQQb6AFxY0IwS9YwSytSrEUuuwI4Amz9r0RAPmaK4fwzlI= X-Gm-Gg: AeBDiet/ZmbpAvtR93A+gxzH3Y1DJOuNWKyzDg/nvw82k8JpH3gI7aJ4w4PkQbtnXzj II3SaharrXy0QbNTimW/qd3Iabv46kHZsMwnKuljyHYwkGKO9/7ON04jGgv7VNKPL3ZV4S/AKk8 bs8UNIBBwAHgDkJHTF5nFGv7t6Nr5VtlR4YYTK+/uMjSZuGuqBVbEz9XlvBfG4+A33sQnTNc6KA K5VWfHXPrJxPo95uu5sfANtyAe2ueezCSGpwrxDyxGsFFjJnvg27xKfaJ7AlZdbywH3oXwVpXU3 lzvtTvd1efjIvfLuzmrrQ5JjkMaaTO7MhNsf7YvqJKaznQ7RNUCrpiszGhtYECaDIYWAZuTPG8f g3rXMrDj7pGVYWeB7Tz7NRy6gAo2+efR9M/N50/YBpt+03bxAmqctuPcyY4rkVi5zacF3ZHSKZk FTdSArt1Q/Wh8jHi475A== X-Received: by 2002:a17:903:1b66:b0:2ae:8253:1452 with SMTP id d9443c01a7336-2b98734184amr21843565ad.11.1777439638849; Tue, 28 Apr 2026 22:13:58 -0700 (PDT) Received: from localhost ([2400:8902:e002:de33:3dbd:69cf:4a22:309]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b988787360sm8846935ad.20.2026.04.28.22.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 22:13:58 -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 v3 0/3] LoongArch: Move KASLR to EFI stub to avoid initrd overlap Date: Wed, 29 Apr 2026 13:13:15 +0800 Message-ID: <20260429051318.1581350-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 [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. [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 it has already been applied LoongArch: Avoid initrd overlap during kernel relocation arch/loongarch/include/asm/efi.h | 4 +- arch/loongarch/kernel/relocate.c | 49 ++++++++++++++++++++++++ drivers/firmware/efi/libstub/loongarch.c | 16 ++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) -- 2.54.0