Coder Social home page Coder Social logo

penglai-enclave / penglai-enclave-spmp Goto Github PK

View Code? Open in Web Editor NEW
123.0 8.0 35.0 173.77 MB

Penglai Enclave is an open-sourced, secure and scalable TEE system for RISC-V.

License: Other

Makefile 0.26% Shell 0.29% Roff 0.02% C 97.99% Assembly 1.07% Perl 0.13% C++ 0.03% Awk 0.01% Python 0.17% sed 0.01% Yacc 0.01% Lex 0.01% UnrealScript 0.01% SmPL 0.02% Gherkin 0.01% XS 0.01% Raku 0.01% Clojure 0.01% M4 0.01% GDB 0.01%
risc-v tee enclave

penglai-enclave-spmp's Introduction

build Status: Experimental License: Mulan

Penglai Header

Introduction

Penglai is a RISC-V TEE system, which is designed to be secure, high-performant, and scalable. This repo maintains OpenSBI version of Penglai Enclave based on PMP.

How to use?

Simply replace the OpenSBI used in your system with opensbi-0.9/1.0/1.2 in the top directory in the repo.

You can use our SDK and enclave-driver to build your trusted applications, or even write your own SDKs.

Status and Info

  • Status: experimental: it's still experimental version now, please refer our TVM version for more features.
  • Hardware requirement:for openEuler version $\le$ 20.03, riscv qemu version: $\geq$ 5.2.0 is fine;for openEuler version $\ge$ 22, qemu version:$\geq$ 8.0 is suggested.
  • Supported software system: This repo contains resources to run openEuler with Penglai TEE.
  • Real devices: Penglai for Nuclei devices is maintained in Nuclei Linux SDK.

You can turn to BBL-version by switching to the master branch.

You can refer our Penglai-TVM for more advanced features, including inter-enclave communication, secure storage, shadow fork, and others.

Case: Running openEuler with Penglai

Requirements

Penglai uses Docker for building and uses submodules to track different componets. Therefore, the only requirement to build and run penglai-demo is:

  • Docker: for building/running Penglai
  • Git: for downloading the code
  • Qemu for RISC-V (RV64): suggested version >= 8.0. You can download the qemu here and follow the instructions to build and install qemu.

Build uboot

For openEuler version $\lt$ 23:

There is no need to compile uboot.

# Fetch the uboot submodule
git submodule update --init --recursive

For openEuler version $\ge$ 23:

Follow the instructions in openeuler riscv gitee to compile uboot for OE-23.X.

# Fetch the uboot submodule
git submodule update --init --recursive
docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --network=host --rm -it fly0307/penglai-enclave:v0.5 bash
cd ./u-boot
make qemu-riscv64_smode_defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- -j$(nproc)

Build openEuler Kernel

For openEuler version $\lt$ 23:

Follow the instructions in openeuler riscv gitee to compile openEuler kernel.

For example, download the OKL-5.10 in current directory, and compile with penglai's docker image:

docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it ddnirvana/penglai-enclave:v0.5 bash
# In the docker image
./scripts/build_euler_kernel.sh

For openEuler version $\ge$ 23:

For oe versions greater than 23, you can access the source code after Run openEuler with Penglai Supports and don't need to compile the image like in the previous step for version $\lt$ 23.

Build OpenSBI (with Penglai supports)

If you want to use opensbi 0.9 or 1.0, you need to use the previous version of the penglai-enclave-driver, the corresponding commit is bb5021cd9f76d033d6e174b2b96bbc4503766385. And you can use the latest penglai-enclave-driver to support opensbi-1.2.

For openEuler version $\lt$ 23:

When compiling opensbi-0.9/1.0, you can use the toolchain CROSS_COMPILE=/home/penglai/toolchain-720/bin/riscv64-unkown-linux-gnu-. For opensbi-1.2, you can use CROSS_COMPILE=riscv64-unknown-linux-gnu-.

cp openeuler-kernel/arch/riscv/boot/Image .
docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it fly0307/penglai-enclave:v0.5 bash
# In the docker image
cd /home/penglai/penglai-enclave/opensbi-0.9
mkdir -p build-oe/qemu-virt
CROSS_COMPILE=/home/penglai/toolchain-720/bin/riscv64-unkown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=/home/penglai/penglai-enclave/Image

Note: the /home/penglai/penglai-enclave/Image is the image compiled openEuler Kernel Image.

A simple way: For opensbi-0.9 and oe-2203(oe $\lt$ 23 )

./docker_cmd.sh opensbi-0.9

For openEuler version $\ge$ 23:

docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it fly0307/penglai-enclave:v0.5 bash
cd /home/penglai/penglai-enclave/opensbi-1.2
rm -rf build-oe/qemu-virt
mkdir -p build-oe/qemu-virt
CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=/home/penglai/penglai-enclave/u-boot/u-boot.bin -j$(nproc)

A simpler way: For opensbi-1.2 and oe-2303(oe $\ge$ 23 )

./docker_cmd.sh opensbi-1.2 

For others

./docker_cmd.sh docker
#In the docker image,build opensbi 1.2 for OE20.03
#./scripts/build_opensbi.sh -v [opensbi version] -k [openEuler version]
./scripts/build_opensbi.sh -v 1.2 -k 2003

Note: if you use the simpler way, please copy your latest kernel Image file to the root dir of the repo.

Build Penglai driver module

For openEuler version $\lt$ 23:

When openeuler version is less than 23,following the commands to build enclave driver:

./docker_cmd.sh docker
# In the docker image
./scripts/build_enclave_driver.sh

It will generate penglai.ko in the penglai-enclave-driver dir.

For openEuler version $\ge$ 23:

When openEuler version is >= 23, you need to start openEuler in qemu as the next step Run openEuler with Penglai Supports finished before compiling penglai-driver.

Build Penglai sdk

When penglai.ko is completed,following the commnads to build user-level sdk and demos:

#In host, fetch the sdk submodule
git submodule update --init --recursive

./docker_cmd.sh docker
# In the docker image
cd sdk
PENGLAI_SDK=$(pwd) make -j8

Run openEuler with Penglai Supports

You should download the disk image of openEuler (i.e., openEuler-preview.riscv64.qcow2) and raname image file to openEuler-xxxx-qemu-riscv64.qcow2.

You can download OE 2303 from openEuler-23.03-V1-riscv64(i.e., openEuler-23.03-V1-base-qemu-preview.qcow2)or download openEuler 20.03 from here.

wget https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/preview/openEuler-23.03-V1-riscv64/QEMU/openEuler-23.03-V1-base-qemu-preview.qcow2.zst
unzstd openEuler-23.03-V1-base-qemu-preview.qcow2.zst
mv openEuler-23.03-V1-base-qemu-preview.qcow2 openEuler-2303-qemu-riscv64.qcow2

For openEuler version $\lt$ 23:

Run VM in QEMU:

# For openEuler version is 20.03
qemu-system-riscv64 -nographic -machine virt \
					-smp 4 -m 2G \
					-kernel  ./opensbi-0.9/build-oe/qemu-virt/platform/generic/firmware/fw_payload.elf  \
					-drive file=openEuler-preview.riscv64.qcow2,format=qcow2,id=hd0 \
					-object rng-random,filename=/dev/urandom,id=rng0 \
					-device virtio-rng-device,rng=rng0 \
					-device virtio-blk-device,drive=hd0  \
					-device virtio-net-device,netdev=usernet \
					-netdev user,id=usernet,hostfwd=tcp::12055-:22 \
					-append 'root=/dev/vda1 rw console=ttyS0 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=4096M earlycon' \
					-bios none
  • The test qemu version is 5.2.0 or 8.0.0.
  • The fw_payload.elf is the opensbi file.
  • The openEuler-preview.riscv64.qcow2 is the disk image for openEuler (You can download from https://repo.openeuler.org/openEuler-preview/RISC-V/).
  • To login, username is "root", passwd is "openEuler12#$"

Note: a script, run_openeuler.sh is provided to execute the above command easily

./run_openeuler.sh -k [openEuler version] -o [opensbi version]
#when openEuler version less than 23,eg 2003
./run_openeuler.sh -k 2003 -o 1.2

If everything is fine, you will enter a Linux terminal booted by Qemu with Penglai-installed.

For openEuler version $\ge$ 23:

Run VM in QEMU:

qemu-system-riscv64 -nographic -machine virt \
			-smp 4 -m 2G \
			-bios  ./opensbi-1.2/build-oe/qemu-virt/platform/generic/firmware/fw_payload.bin  \
			-drive file=openEuler-2303-qemu-riscv64.qcow2,format=qcow2,id=hd0 \
			-object rng-random,filename=/dev/urandom,id=rng0 \
			-device virtio-rng-device,rng=rng0 \
			-device virtio-blk-device,drive=hd0  \
			-device virtio-net-device,netdev=usernet \
			-netdev user,id=usernet,hostfwd=tcp::12055-:22 \
			-device qemu-xhci -usb -device usb-kbd -device usb-tablet

Once started, you should execut the following command to obtain the kernel module compilation environment. Execute the following commands and the kernel source code will be downloaded locally, the path is /usr/lib/modules/6.1.19-2.oe2303.riscv64(For openEuler 2303).

#in VM
cd ~/
dnf install -y kernel-devel kernel-source

a simple way:

./run_openeuler.sh -k [openEuler version] -o [opensbi version]
#when openEuler version is greater than or equal 23,eg 2303
./run_openeuler.sh -k 2303 -o 1.2

RUN demo

For openEuler version $\lt$ 23:

Copy files to openEuler Qemu

You can copy any files to the VM using scp.

For example, to run the following demo, you should:

#For version 23, there is no need to copy penglai.ko
scp -P 12055 penglai-enclave-driver/penglai.ko root@localhost:~/
scp -P 12055 sdk/demo/host/host root@localhost:~/
scp -P 12055 sdk/demo/prime/prime root@localhost:~/

The passwd is "openEuler12#$"

For openEuler version $\ge$ 23:

After starting the VM, you need to get the source code in the qemu VM and execute compile kernel moudle with penglai-driver for openEuler version $\ge$ 23.

Copy penglai-enclave-driver to the root/ directory of the oe VM:

#in host
scp -P 12055 -r penglai-enclave-driver root@localhost:~/
scp -P 12055 sdk/demo/host/host root@localhost:~/
scp -P 12055 sdk/demo/prime/prime root@localhost:~/

Go into the penglai-enclave-driver directory and modify the original kernel source path openeuler-kernel in the Makefile from ../openeuler-kernel/to /usr/lib/modules/$(shell uname -r)/build/.

Compile and install the kernel module:

cd ~/penglai-enclave-driver
#modify source path
sed -i 's|make -C ../openeuler-kernel/ ARCH=riscv M=$(PWD) modules|make -C /usr/lib/modules/$(shell uname -r)/build ARCH=riscv M=$(PWD) modules|' Makefile > /dev/null 2>&1
make -j$(nproc)
insmod penglai.ko

Insmod the enclave-driver

If you already installed in the previous step, you don't need to repeat it

cd ~/
insmod penglai.ko

And the, you can run a demo, e.g., a prime enclave, using

./host  prime

Here, the host is an enclave invoker, which will start an enclave (name from input).

License Details

Mulan Permissive Software License,Version 1 (Mulan PSL v1)

Code Structures

  • opensbi-0.9: The Penglai-equipped OpenSBI, version 0.9
  • opensbi-1.0: The Penglai-equipped OpenSBI, version 1.0
  • opensbi-1.2: The Penglai-equipped OpenSBI, version 1.2
  • openeuler-kernel: openEuler Kernel
  • riscv-qemu: The modified qemu (4.1) to support sPMP (you can also use the standard qemu)
  • scripts: some scripts to build/run Penglai demo

Code Contributions

Please fell free to post your concerns, ideas, code or anything others to issues.

Document and Tutorial

Please refer our readthedocs page for documents.

Cite

To cite Penglai, please consider using the following bibtex:

@inproceedings {273705,
	author = {Erhu Feng and Xu Lu and Dong Du and Bicheng Yang and Xueqiang Jiang and Yubin Xia and Binyu Zang and Haibo Chen},
	title = {Scalable Memory Protection in the {PENGLAI} Enclave},
	booktitle = {15th {USENIX} Symposium on Operating Systems Design and Implementation ({OSDI} 21)},
	year = {2021},
	isbn = {978-1-939133-22-9},
	pages = {275--294},
	url = {https://www.usenix.org/conference/osdi21/presentation/feng},
	publisher = {{USENIX} Association},
	month = jul,
}

Collaborators

We thank all of our collaborators (companies, organizations, and communities).

Huawei nuclei StarFive ISCAS
Huawei (华为) Nuclei (芯来科技) StarFive (赛昉科技) ISCAS(中科院软件所)
openEuler OpenHarmony secGear
openEuler community OpenHarmony community secGear framework

Acknowledgements

The design of Penglai was inspired by Sanctum, Keystone and HexFive, thanks to their great work!

penglai-enclave-spmp's People

Contributors

ddnirvana avatar fengerhu1 avatar fly0307 avatar iku-iku-iku avatar liangliang-ll avatar moonquakes avatar pengxuanyao avatar shang-qy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

penglai-enclave-spmp's Issues

注释有一点问题

opensbi-1.2/include/sm/pmp.h 第18行注释中pmp1cfg重复,是否应将字段7-0中的pmp1cfg改为pmp0cfg?

原注释

The RISC-V Instruction Set Manual Volume II: Privileged Architecture (Document Version 20211203)
第57页 3.7.1 Physical Memory Protection CSRs
卷2截图

How to use Penglai Tee-TVM for development?

Hello, I am very interested in Penglai Tee and would like to conduct research and development on it. But I can only use it to run demo, how should I use it to run my own code? Is there a tutorial available for reference?

Facing kernel panic for openEuler 23.09

Hi Dong Du,

Facing kernel panic for openEuler 23.09

Workstation details:
Ubuntu 22.04
RISC-V cross compilier 13.2.0
qemu version 8.1.50

Steps to reproduce:
Cross compilied u-boot, opensbi-1.2 as per the steps for openEuler >23.
when cross compiling sdk it was unsuccessful.
used the https://ipads.se.sjtu.edu.cn:1313/d/6a464e02cd3d4c1bafb0/ sdk source and cross compilation was successful.

Booted the openEuler 23.09 with below command

qemu-system-riscv64 -nographic -machine virt \
			-smp 4 -m 2G \
			-bios  ./opensbi-1.2/build-oe/qemu-virt/platform/generic/firmware/fw_payload.bin  \
			-drive file=openEuler-23.09-qemu-riscv64.qcow2,format=qcow2,id=hd0 \
			-object rng-random,filename=/dev/urandom,id=rng0 \
			-device virtio-rng-device,rng=rng0 \
			-device virtio-blk-device,drive=hd0  \
			-device virtio-net-device,netdev=usernet \
			-netdev user,id=usernet,hostfwd=tcp::12055-:22 \
			-device qemu-xhci -usb -device usb-kbd -device usb-tablet

copied files from host to openEuler qemu as follows:

scp -P 12055 penglai-enclave-driver/penglai.ko root@localhost:~/
scp -P 12055 sdk/demo/host/host root@localhost:~/
scp -P 12055 sdk/demo/prime/prime root@localhost:~/

cross compiled penglai-kernel-driver generated penglai.ko
insert the enclave driver module
insmod penglai.ko

[root@openeuler-riscv64 penglai-enclave-driver]# insmod penglai.ko 
[ 1000.778139] penglai: loading out-of-tree module taints kernel.
[ 1000.780758] enclave_ioctl_init...
[Penglai KModule] sbi_ecall_penglai_host_handler invoked,funcid=100d
[Penglai Monitor] sm_mm_init invoked
[Penglai Monitor] sm_mm_init paddr:0xa3c00000, size:0x400000
[Debug:SM@dump_pmps] pmp_0: mode(0x18) perm(0x0) paddr(0x80028000) size(0x2000)
[Debug:SM@dump_pmps] pmp_1: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_2: mode(0x18) perm(0x7) paddr(0x0) size(0x8)
[Debug:SM@dump_pmps] pmp_3: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_4: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_5: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_6: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_7: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_8: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_9: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_10: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_11: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_12: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_13: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_14: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_15: mode(0x18) perm(0x7) paddr(0x0) size(0x8)
[Debug:SM@dump_pmps] pmp_0: mode(0x18) perm(0x0) paddr(0x80028000) size(0x2000)
[Debug:SM@dump_pmps] pmp_1: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_2: mode(0x18) perm(0x0) paddr(0xa3c00000) size(0x400000)
[Debug:SM@dump_pmps] pmp_3: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_4: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_5: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_6: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_7: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_8: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_9: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_10: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_11: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_12: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_13: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_14: mode(0x0) perm(0x0) paddr(0x0) size(0x0)
[Debug:SM@dump_pmps] pmp_15: mode(0x18) perm(0x7) paddr(0x0) size(0x8)
[Penglai Monitor] sm_mm_init ret:0d 
[ 1000.794471] [Penglai KModule] register_chrdev succeeded!

prime enclave execution was successful
./host prime
there is kernel call trace after enclave execution and kernel panic after some seconds

[root@openeuler ~]# rmo[  157.717647][  T730] kmemleak: Cannot insert 0xffffffd808391d80 into the object search tree (overlaps existing)
[  157.718217][  T730] CPU: 1 PID: 730 Comm: bash Tainted: G           OE      6.4.0-10.1.0.20.oe2309.riscv64 #1
[  157.718620][  T730] Hardware name: riscv-virtio,qemu (DT)
[  157.718938][  T730] Call Trace:
[  157.719111][  T730] [<ffffffff80006202>] dump_backtrace+0x28/0x30
[  157.719465][  T730] [<ffffffff80b96734>] show_stack+0x38/0x44
[  157.719699][  T730] [<ffffffff80ba9fe4>] dump_stack_lvl+0x44/0x5c
[  157.719946][  T730] [<ffffffff80baa014>] dump_stack+0x18/0x20
[  157.720172][  T730] [<ffffffff802a7ca8>] __create_object+0x374/0x398
[  157.720425][  T730] [<ffffffff80bacbbc>] kmemleak_alloc+0x48/0x80
[  157.720664][  T730] [<ffffffff80282e16>] __kmem_cache_alloc_node+0x1ca/0x2f8
[  157.720938][  T730] [<ffffffff802131e8>] __kmalloc+0x48/0x1b8
[  157.721162][  T730] [<ffffffff8036e65c>] ext4_htree_store_dirent+0x4c/0x16e
[  157.721432][  T730] [<ffffffff803a19c4>] htree_dirblock_to_tree+0x15c/0x27a
[  157.721694][  T730] [<ffffffff803a2836>] ext4_htree_fill_tree+0x172/0x2e6
[  157.721968][  T730] [<ffffffff8036dd08>] ext4_dx_readdir+0xd2/0x2be
[  157.722240][  T730] [<ffffffff8036e556>] ext4_readdir+0x43e/0x4c8
[  157.722505][  T730] [<ffffffff802d30a6>] iterate_dir+0x124/0x150
[  157.722772][  T730] [<ffffffff802d3330>] __do_sys_getdents64+0x64/0x150
[  157.723059][  T730] [<ffffffff802d3438>] sys_getdents64+0x1c/0x24
[  157.723342][  T730] [<ffffffff80baab12>] do_trap_ecall_u+0xf0/0x104
[  157.723653][  T730] [<ffffffff80003e70>] ret_from_exception+0x0/0x64
[  157.724090][  T730] kmemleak: Kernel memory leak detector disabled
[  157.724386][  T730] kmemleak: Object 0xffffffd808391d80 (size 64):
[  157.724653][  T730] kmemleak:   comm "bash", pid 730, jiffies 4294931765
[  157.724938][  T730] kmemleak:   min_count = 1
[  157.725136][  T730] kmemleak:   count = 0
[  157.725314][  T730] kmemleak:   flags = 0x1
[  157.725482][  T730] kmemleak:   checksum = 0
[  157.725654][  T730] kmemleak:   backtrace:
[  157.725902][  T730]  kmemleak_alloc+0x48/0x80
[  157.726108][  T730]  __kmem_cache_alloc_node+0x1ca/0x2f8
[  157.726322][  T730]  __kmalloc+0x48/0x1b8
[  157.726487][  T730]  ext4_htree_store_dirent+0x4c/0x16e
[  157.726693][  T730]  htree_dirblock_to_tree+0x15c/0x27a
[  157.726898][  T730]  ext4_htree_fill_tree+0x172/0x2e6
[  157.727098][  T730]  ext4_dx_readdir+0xd2/0x2be
[  157.727279][  T730]  ext4_readdir+0x43e/0x4c8
[  157.727455][  T730]  iterate_dir+0x124/0x150
[  157.727630][  T730]  __do_sys_getdents64+0x64/0x150
[  157.727826][  T730]  sys_getdents64+0x1c/0x24
[  157.728004][  T730]  do_trap_ecall_u+0xf0/0x104
[  157.728187][  T730]  ret_from_exception+0x0/0x64
[  157.738800][   T78] kmemleak: Automatic memory scanning thread ended

Similarly for 23.03 followed same steps with replacing openeuler 23.09 with 23.03 and was facing kernel panic as follows:

[ 5190.432458] ------------[ cut here ]------------
[ 5190.432866] WARNING: CPU: 3 PID: 1 at mm/slab_common.c:923 free_large_kmalloc+0x5a/0x90
[ 5190.433355] Modules linked in: drm fuse i2c_core drm_panel_orientation_quirks backlight [last unloaded: penglai(O)]
[ 5190.434170] CPU: 3 PID: 1 Comm: systemd Tainted: G           O       6.1.19-2.oe2303.riscv64 #1
[ 5190.434824] Hardware name: riscv-virtio,qemu (DT)
[ 5190.435223] epc : free_large_kmalloc+0x5a/0x90
[ 5190.435513]  ra : free_large_kmalloc+0x16/0x90
[ 5190.435762] epc : ffffffff8018e6fe ra : ffffffff8018e6ba sp : ff2000000060bb30
[ 5190.436112]  gp : ffffffff815db148 tp : ff60000001b10000 t0 : 0000000000000002
[ 5190.436451]  t1 : 0000000000000001 t2 : 0000000000000040 s0 : ff2000000060bb70
[ 5190.436808]  s1 : ff6000007ea00080 a0 : ff6000007ea00080 a1 : ff60000073636f72
[ 5190.437150]  a2 : ffffffffffffffff a3 : 0080000000000000 a4 : 0000000000000000
[ 5190.437540]  a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000002
[ 5190.437904]  s2 : ff60000073636f72 s3 : ffffffff801830f4 s4 : 0000000000000800
[ 5190.438249]  s5 : ffffffff814c3d40 s6 : ffffffff815de228 s7 : 00000000ffffffff
[ 5190.438629]  s8 : ffffffff80000001 s9 : ff60000003a52410 s10: 0000000000000004
[ 5190.439059]  s11: ffffffff815df1d0 t3 : 0000000000000002 t4 : 0000000000000402
[ 5190.439450]  t5 : ff60000003a52430 t6 : ff6000000276afea
[ 5190.439740] status: 0000000200000120 badaddr: 0000000000000000 cause: 0000000000000003
[ 5190.440272] [<ffffffff8018e6fe>] free_large_kmalloc+0x5a/0x90
[ 5190.440694] [<ffffffff8018e844>] kfree+0x110/0x116
[ 5190.440965] [<ffffffff801830f4>] kfree_const+0x18/0x2e
[ 5190.441260] [<ffffffff80270336>] kernfs_put.part.0+0x6e/0x196
[ 5190.441550] [<ffffffff8027047c>] kernfs_put+0x1e/0x26
[ 5190.441820] [<ffffffff8026f694>] kernfs_evict_inode+0x2a/0x36
[ 5190.442126] [<ffffffff80217afa>] evict+0x94/0x160
[ 5190.442392] [<ffffffff80217f20>] iput+0x142/0x1bc
[ 5190.442687] [<ffffffff80212dfe>] dentry_unlink_inode+0xbe/0x108
[ 5190.442975] [<ffffffff802139fa>] __dentry_kill+0xb6/0x174
[ 5190.443176] [<ffffffff80215150>] shrink_dentry_list+0x4c/0xd6
[ 5190.443379] [<ffffffff8021533e>] shrink_dcache_parent+0xdc/0x12a
[ 5190.443634] [<ffffffff802068d0>] vfs_rmdir.part.0+0xc6/0x160
[ 5190.443954] [<ffffffff8020c564>] do_rmdir+0x170/0x180
[ 5190.444281] [<ffffffff8020c834>] sys_unlinkat+0x48/0x56
[ 5190.444528] [<ffffffff80003a7a>] ret_from_syscall+0x0/0x2
[ 5190.444904] ---[ end trace 0000000000000000 ]---
[ 5190.445400] object pointer: 0x000000003c5e4edc
[ 5190.445905] page:00000000c8b1a57b refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0xf3836
[ 5190.446401] flags: 0x0(zone=0)
[ 5190.447400] raw: 0000000000000000 ff6000007ea00088 ff6000007ea00088 0000000000000000
[ 5190.447880] raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
[ 5190.448619] page dumped because: VM_BUG_ON_PAGE(page_ref_count(page) == 0)
[ 5190.449097] ------------[ cut here ]------------
[ 5190.449359] kernel BUG at include/linux/mm.h:763!
[ 5190.449881] Kernel BUG [#1]
[ 5190.450119] Modules linked in: drm fuse i2c_core drm_panel_orientation_quirks backlight [last unloaded: penglai(O)]
[ 5190.450936] CPU: 3 PID: 1 Comm: systemd Tainted: G        W  O       6.1.19-2.oe2303.riscv64 #1
[ 5190.451455] Hardware name: riscv-virtio,qemu (DT)
[ 5190.451763] epc : __free_pages+0xcc/0xce
[ 5190.452049]  ra : __free_pages+0xcc/0xce
[ 5190.452296] epc : ffffffff801bb74a ra : ffffffff801bb74a sp : ff2000000060baf0
[ 5190.452699]  gp : ffffffff815db148 tp : ff60000001b10000 t0 : 6d75642065676170
[ 5190.453047]  t1 : 0000000000000070 t2 : 706d756420656761 s0 : ff2000000060bb30
[ 5190.453400]  s1 : ff6000007ea00080 a0 : 000000000000003e a1 : 0000000000000001
[ 5190.453824]  a2 : 0000000000000010 a3 : 0000000000000018 a4 : a811eb175061e400
[ 5190.454223]  a5 : a811eb175061e400 a6 : 0000000000000008 a7 : 0000000000000038
[ 5190.454649]  s2 : ff6000007ea00080 s3 : 0000000000000000 s4 : 0000000000000800
[ 5190.455058]  s5 : ffffffff814c3d40 s6 : ffffffff815de228 s7 : 00000000ffffffff
[ 5190.455471]  s8 : ffffffff80000001 s9 : ff60000003a52410 s10: 0000000000000004
[ 5190.455859]  s11: ffffffff815df1d0 t3 : ffffffff815f0717 t4 : ffffffff815f0717
[ 5190.456273]  t5 : ffffffff815f0718 t6 : ff2000000060b8c8
[ 5190.456541] status: 0000000200000120 badaddr: 0000000000000000 cause: 0000000000000003
[ 5190.456932] [<ffffffff801bb74a>] __free_pages+0xcc/0xce
[ 5190.457226] [<ffffffff8018e6f0>] free_large_kmalloc+0x4c/0x90
[ 5190.457581] [<ffffffff8018e844>] kfree+0x110/0x116
[ 5190.457871] [<ffffffff801830f4>] kfree_const+0x18/0x2e
[ 5190.458166] [<ffffffff80270336>] kernfs_put.part.0+0x6e/0x196
[ 5190.458502] [<ffffffff8027047c>] kernfs_put+0x1e/0x26
[ 5190.458838] [<ffffffff8026f694>] kernfs_evict_inode+0x2a/0x36
[ 5190.459132] [<ffffffff80217afa>] evict+0x94/0x160
[ 5190.459419] [<ffffffff80217f20>] iput+0x142/0x1bc
[ 5190.459708] [<ffffffff80212dfe>] dentry_unlink_inode+0xbe/0x108
[ 5190.460052] [<ffffffff802139fa>] __dentry_kill+0xb6/0x174
[ 5190.460358] [<ffffffff80215150>] shrink_dentry_list+0x4c/0xd6
[ 5190.460683] [<ffffffff8021533e>] shrink_dcache_parent+0xdc/0x12a
[ 5190.461019] [<ffffffff802068d0>] vfs_rmdir.part.0+0xc6/0x160
[ 5190.461345] [<ffffffff8020c564>] do_rmdir+0x170/0x180
[ 5190.461631] [<ffffffff8020c834>] sys_unlinkat+0x48/0x56
[ 5190.461927] [<ffffffff80003a7a>] ret_from_syscall+0x0/0x2
[ 5190.462686] ---[ end trace 0000000000000000 ]---
[ 5190.463124] note: systemd[1] exited with irqs disabled
[ 5190.463794] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 5190.464295] SMP: stopping secondary CPUs
[ 5190.465087] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---

openEuler 23.03 uses 6.1.x Linux kernel and openEuler 23.09 uses 6.4.x Linux kernel.

observations:
when booted with openEuler 23.03 it is observed mmu was sv57 and with openEuler 23.09 it was sv39.
Any issue with OpenSBI?

Please let me know your suggestions or comments.

Thanks,
MD Sadiq

For Penglai with OpenSBI-v1.0, pmp0 config for monitor protection.

For Penglai with OpenSBI-v1.0(under directory opensbi-1.0), pmp0 configuration for monitor protection is inaccurate.
It now uses _fw_start and _fw_end to decide pmp0 configuration, which facilitates the migration on dev boards. Although they are set correctly(include the hole firmware) during build time, it seems _fw_start and _fw_end will be changed at boot time, which make this protection method incomplete.

The need to dynamically detect PMP numbers

Currently Penglai's SM (statically) assumes 16 PMPs.
However, there are some platforms support less (e.g., 8 PMPs) or more (e.g., in the future with ePMP we will have upto 64).

We should dynamically detect PMP numbers to satisfy the diverse platforms.

Update to OpenSBI-v1.0

OpenSBI has released its 1.0 version.
We should bump up Penglai to support 1.0 openSBI.

Default qemu version is out of date

I build the qemu binaries from the "riscv-qemu" path, which generate qemu 4.1.1. when I use this qemu to load the image, it hang up at the output as following
[Penglai] Penglai Enclave Preparing

Then I found in the document that the qemu version should >= 5.2.0. Then I installed the required qemu and it worked ok.

In that case why not removing this "riscv-qemu" from the repo to avoid confusion? Or you can upgrade the qemu into the required one.

Unable to run sealdata demo and others of secgear except helloworld

os-openEuler 23.09
kernal-6.4.0
reference document links for demo run
https://github.com/Penglai-Enclave/Penglai-secGear/blob/riscv-penglai-zx-dev/docs/riscv_tee.md
Error which I got during compilation of demos
[root@openeuler-riscv64 debug]# cmake -DENABLE_ENC_KEY=1 -DCMAKE_BUILD_TYPE=Debug -DENCLAVE=PL -DSDK_PATH=/root/dev/sdk -DSSL_PATH=/root/dev/sdk/penglai_sdk_ssl -DPL_SSLLIB_PATH=/opt/penglai/openssl ..
=============cmake help info=======================
Example default cmd: cmake ..
same with default: cmake -DENCLAVE=SGX -DSDK_PATH=/opt/intel/sgxsdk -DSSL_PATH=/opt/intel/sgxssl ..
cmake [-DCMAKE_BUILD_TYPE=val] [-DENCLAVE=val] [-DCC_SIM=ON] [-DSDK_PATH=path] [-DSSL_PATH=path] ..
CMAKE_BUILD_TYPE:[optional] pass Debug if you need file line info in log, default log without file line
ENCLAVE:[optional] valid val: SGX --default, GP --trustzone, PL --Penglai
CC_SIM:[optional] only support by SGX
SDK_PATH:[optional] default SGX:/opt/intel/sgxsdk, GP:/opt/itrustee_sdk, PL:/root/dev/sdk;
pass SDK_PATH if you installed sdk in custom path
SSL_PATH:[optional] pass security ssl installed path when your application use ssl
=============cmake help info=======================
Current Platform: RISC-V, Penglai SDK PATH:/root/dev/sdk
CMake Error at examples/seal_data/enclave/CMakeLists.txt:155 (set_target_properties):
set_target_properties Can not find target to add properties to: seal_data

CMake Error at examples/seal_data/host/CMakeLists.txt:69 (target_link_libraries):
Cannot specify link libraries for target "secgear_seal_data" which is not
built by this project.

-- Configuring incomplete, errors occurred!
See also "/root/dev/secGear/debug/CMakeFiles/CMakeOutput.log".

thanks
shreekant
secgeardemoissue

compile error when Build OpenSBI (with Penglai supports)

I was using the branch opensbi-v0.9. I followed the instructions, but when I arrived at Build OpenSBI (with Penglai supports), I was encountered with the following problem:

/home/penglai/toolchain/bin/../lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin/as: out of memory allocating 9223372036854841443 bytes after a total of 466944 bytes
Makefile:392: recipe for target '/home/penglai/penglai-enclave/opensbi-0.9/build-oe/qemu-virt/platform/generic/firmware/fw_payload.o' failed
make: *** [/home/penglai/penglai-enclave/opensbi-0.9/build-oe/qemu-virt/platform/generic/firmware/fw_payload.o] Error 1

image

sdk make error

demo/gm_test_enclaves、demo/seal_data、demo/evm make error:

make[2]: *** No rule to make target '/home/penglai/penglai-enclave/sdk/lib/gm/libpenglai-enclave-gm.a', needed by 'test_sm2'.  Stop.
make[2]: Leaving directory '/home/penglai/penglai-enclave/sdk/demo/gm_test_enclaves'
make[1]: *** [Makefile:9: all] Error 2
make[1]: Leaving directory '/home/penglai/penglai-enclave/sdk/demo'
make: *** [Makefile:4: all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.