You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2009-2019. All rights reserved.
|
|
* Description: support KASLR(kernel addess space layout randomization)
|
|
* Author:
|
|
* Create: 2020-02-21
|
|
*/
|
|
|
|
#include "kaslr.h"
|
|
#include <malloc.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <linux/string.h>
|
|
#include "common_ext.h"
|
|
#include "pdm_ext.h"
|
|
#include "fdt_support.h"
|
|
#include "soc_errno.h"
|
|
#include "drv_cipher_ext.h"
|
|
|
|
#ifndef SOCT_MINIBOOT_SUPPORT
|
|
#include <common.h>
|
|
#endif
|
|
|
|
int fdt_modify_kaslr(void)
|
|
{
|
|
#ifndef SLAVE_BOOT_ENV
|
|
int nodeoffset; /* node offset from libfdt */
|
|
int ret;
|
|
u32 seed;
|
|
u64 kaslr_seed;
|
|
#ifdef KASLR_DEBUG
|
|
u32 kaslr_dtb[2]; /* 2 for Array */
|
|
int i;
|
|
#endif
|
|
|
|
void *fdt = (void *)CONFIG_DTB_ADDR;
|
|
ret = fdt_path_offset (fdt, "/chosen");
|
|
if (ret < 0) {
|
|
printf("fdt_path_offset failed, ret = 0x%x\n", ret);
|
|
return ret;
|
|
}
|
|
nodeoffset = ret;
|
|
|
|
ret = ext_drv_cipher_init();
|
|
if (ret != TD_SUCCESS) {
|
|
printf("Cipher init failed.\n");
|
|
return ret;
|
|
}
|
|
ret = ext_drv_cipher_trng_get_random(&seed);
|
|
if (ret != 0) {
|
|
printf("ext_drv_cipher_trng_get_random fail!");
|
|
(td_void)ext_drv_cipher_deinit();
|
|
return ret;
|
|
}
|
|
kaslr_seed = cpu_to_fdt64((u64)seed);
|
|
ret = fdt_setprop(fdt, nodeoffset, (const char *)"kaslr-seed", &kaslr_seed, sizeof(u64));
|
|
if (ret < 0) {
|
|
printf("fdt_setprop fail, ret = 0x%x\n", ret);
|
|
(td_void)ext_drv_cipher_deinit();
|
|
return ret;
|
|
}
|
|
#ifdef KASLR_DEBUG
|
|
ret = ext_get_dts_config_u32array_byname("chosen", "kaslr-seed", kaslr_dtb, 2); /* 2 for Array */
|
|
for (i = 0; i < 2; i++) { /* 2 for Array */
|
|
printf("/chosen-> kaslr-seed: 0x%x\n", kaslr_dtb[i]);
|
|
}
|
|
#endif
|
|
(td_void)ext_drv_cipher_deinit();
|
|
#endif
|
|
return 0;
|
|
}
|