summaryrefslogtreecommitdiff
path: root/na
diff options
context:
space:
mode:
Diffstat (limited to 'na')
-rw-r--r--na/arch/riscv/include/arch/config.h47
-rw-r--r--na/include/lume/config.h12
2 files changed, 58 insertions, 1 deletions
diff --git a/na/arch/riscv/include/arch/config.h b/na/arch/riscv/include/arch/config.h
index e7b1027..0949c41 100644
--- a/na/arch/riscv/include/arch/config.h
+++ b/na/arch/riscv/include/arch/config.h
@@ -25,7 +25,7 @@ namespace arch {
* Higher-half layout (defaults before KASLR):
*
* 0xFFFFFFC0_00000000 (256) Direct map (PA+offset)
- * 0xFFFFFFD0_00000000 (320) Vmemmap (Frame array)
+ * 0xFFFFFFD0_00000000 (320) Vmemmap (Page array)
*
* The 64GB gap between them is the KASLR slide range.
* ================================================================ */
@@ -46,11 +46,56 @@ extern uint64 g_direct_map_base;
extern uint64 g_vmemmap_base;
/* ================================================================
+ * KASLR Layout Structure (Phase A: Unified KASLR State)
+ *
+ * This struct holds all KASLR results: the random seed, derived
+ * hash, selected slot, and the randomised virtual address bases.
+ * It serves as the single source of truth for all KASLR decisions
+ * and is filled once during boot and read-only thereafter.
+ * ================================================================ */
+
+enum class KaslrSeedSource : uint8 {
+ kFdt = 0, /* Loaded from FDT /random node */
+ kHardware = 1, /* From hardware RNG (e.g., RDRAND) */
+ kCycle = 2, /* Fallback: CPU cycle counter */
+};
+
+struct KaslrLayout {
+ /* Seed and provenance */
+ uint64 seed; /* 64-bit random seed value */
+ uint64 seed_hash; /* Non-plaintext derived hash (splitmix64) */
+ KaslrSeedSource source; /* Seed provenance (fdt/hw/cycle) */
+
+ /* Randomisation parameters */
+ uint64 slot; /* Slot index: [0, 63] */
+ uint64 slide_bytes; /* Byte offset: slot * 1GB */
+
+ /* Build-time policy */
+ uint32 policy_id; /* CONFIG_KASLR_POLICY_ID at build time */
+
+ /* Randomised base addresses (post-KASLR) */
+ uint64 direct_map_base; /* Direct map VA (kDirectMapBaseDefault + slide) */
+ uint64 vmemmap_base; /* Vmemmap VA (kVmemmapBaseDefault + slide) */
+
+ /* Validation flags (for debug logging) */
+ bool canonical_ok; /* All VA ranges passed canonical check */
+ bool overlap_ok; /* No overlaps detected between regions */
+};
+
+/* ================================================================
* KASLR entry point
*
* Must be called AFTER random_early_init() and BEFORE vmm_init().
+ * Fills g_kaslr_layout with randomised bases and self-check results.
* When CONFIG_KASLR is disabled this is a no-op.
* ================================================================ */
+extern KaslrLayout g_kaslr_layout;
+
void kaslr_init();
+/* Helper to query the KASLR layout safely */
+static inline const KaslrLayout& kaslr_layout_get() {
+ return g_kaslr_layout;
+}
+
} // namespace arch
diff --git a/na/include/lume/config.h b/na/include/lume/config.h
index 40787cc..d3539c5 100644
--- a/na/include/lume/config.h
+++ b/na/include/lume/config.h
@@ -60,6 +60,14 @@
#define CONFIG_DEFAULT_TIMESLICE (CONFIG_HZ / 10)
#endif
+#ifndef CONFIG_KASLR_POLICY_ID
+#define CONFIG_KASLR_POLICY_ID 0 /* Default: basic KASLR policy */
+#endif
+
+#ifndef CONFIG_KASLR_LOG_LEVEL
+#define CONFIG_KASLR_LOG_LEVEL 1 /* 0=off, 1=minimal, 2=debug */
+#endif
+
/* ================================================================
* Legacy compatibility aliases (shared with assembly)
* ================================================================ */
@@ -78,4 +86,8 @@ inline constexpr int kMaxCpus = CONFIG_NR_CPUS;
/* Virtual memory page size (4KB, matching SV39 base page). */
inline constexpr uint64 kPageSize = CONFIG_PAGE_SIZE;
+/* KASLR policy ID and logging level (build-time configurable) */
+inline constexpr uint32 kKaslrPolicyId = CONFIG_KASLR_POLICY_ID;
+inline constexpr int kKaslrLogLevel = CONFIG_KASLR_LOG_LEVEL;
+
#endif /* __ASSEMBLER__ */ \ No newline at end of file