diff options
author | Xiang Wang <wxjstz@126.com> | 2019-03-06 10:29:34 +0300 |
---|---|---|
committer | Atish Patra <atishp04@gmail.com> | 2019-03-06 22:10:35 +0300 |
commit | 9eb8f0f90d5c873576d18d405bbd932ad9688741 (patch) | |
tree | b1e5b974fe6d35fef9b141c955ba8ddad43cdf87 /lib | |
parent | 27fae182dc54e08314034a03eeb583b94c64f4c8 (diff) | |
download | opensbi-9eb8f0f90d5c873576d18d405bbd932ad9688741.tar.xz |
platform: Make the `platform` read-only
platform should be a read-only variable, if it is placed in the data
segment, it may be exploited.
Signed-off-by: Xiang Wang <wxjstz@126.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sbi_console.c | 2 | ||||
-rw-r--r-- | lib/sbi_hart.c | 12 | ||||
-rw-r--r-- | lib/sbi_init.c | 6 | ||||
-rw-r--r-- | lib/sbi_ipi.c | 4 | ||||
-rw-r--r-- | lib/sbi_timer.c | 2 |
5 files changed, 13 insertions, 13 deletions
diff --git a/lib/sbi_console.c b/lib/sbi_console.c index 527748f..da2f823 100644 --- a/lib/sbi_console.c +++ b/lib/sbi_console.c @@ -11,7 +11,7 @@ #include <sbi/sbi_console.h> #include <sbi/riscv_locks.h> -static struct sbi_platform *console_plat = NULL; +static const struct sbi_platform *console_plat = NULL; static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER; bool sbi_isprintable(char c) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index e3b2219..03e2dd5 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -28,7 +28,7 @@ unsigned int sbi_current_hartid() static void mstatus_init(struct sbi_scratch *scratch, u32 hartid) { - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); /* Enable FPU */ if (misa_extension('D') || misa_extension('F')) @@ -79,7 +79,7 @@ static int fp_init(u32 hartid) static int delegate_traps(struct sbi_scratch *scratch, u32 hartid) { - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); unsigned long interrupts, exceptions; if (!misa_extension('S')) @@ -122,7 +122,7 @@ unsigned long log2roundup(unsigned long x) void sbi_hart_pmp_dump(struct sbi_scratch *scratch) { - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); unsigned long prot, addr, size, l2l; unsigned int i; @@ -160,7 +160,7 @@ static int pmp_init(struct sbi_scratch *scratch, u32 hartid) u32 i, count; unsigned long fw_start, fw_size_log2; ulong prot, addr, log2size; - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); if (!sbi_platform_has_pmp(plat)) return 0; @@ -297,7 +297,7 @@ static unsigned long coldboot_wait_bitmap = 0; void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid) { unsigned long mipval; - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); if ((sbi_platform_hart_count(plat) <= hartid) || (COLDBOOT_WAIT_BITMAP_SIZE <= hartid)) @@ -324,7 +324,7 @@ void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid) void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid) { - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); int max_hart = sbi_platform_hart_count(plat); for(int i = 0; i < max_hart ; i++) { diff --git a/lib/sbi_init.c b/lib/sbi_init.c index 81feb56..edcc365 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -32,7 +32,7 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) { int rc; char str[64]; - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); rc = sbi_system_early_init(scratch, TRUE); if (rc) @@ -96,7 +96,7 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid) { int rc; - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); if (!sbi_platform_has_hart_hotplug(plat)) sbi_hart_wait_for_coldboot(scratch, hartid); @@ -156,7 +156,7 @@ void __noreturn sbi_init(struct sbi_scratch *scratch) { bool coldboot = FALSE; u32 hartid = sbi_current_hartid(); - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); if (sbi_platform_hart_disabled(plat, hartid)) sbi_hart_hang(); diff --git a/lib/sbi_ipi.c b/lib/sbi_ipi.c index 5f189c8..0e371d7 100644 --- a/lib/sbi_ipi.c +++ b/lib/sbi_ipi.c @@ -22,7 +22,7 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 hartid, u32 event) { struct sbi_scratch *remote_scratch = NULL; - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); if (sbi_platform_hart_disabled(plat, hartid)) return -1; @@ -72,7 +72,7 @@ void sbi_ipi_clear_smode(struct sbi_scratch *scratch) void sbi_ipi_process(struct sbi_scratch *scratch) { - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); volatile unsigned long ipi_type; unsigned int ipi_event; u32 hartid = sbi_current_hartid(); diff --git a/lib/sbi_timer.c b/lib/sbi_timer.c index a687a5f..a2fb1a7 100644 --- a/lib/sbi_timer.c +++ b/lib/sbi_timer.c @@ -39,7 +39,7 @@ u64 get_ticks(void) u64 sbi_timer_value(struct sbi_scratch *scratch) { - struct sbi_platform *plat = sbi_platform_ptr(scratch); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); if (sbi_platform_has_timer_value(plat)) return sbi_platform_timer_value(plat); |