Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rCore-Tutorial-Book-v3/chapter2/6answer #116

Open
utterances-bot opened this issue Feb 28, 2022 · 11 comments
Open

rCore-Tutorial-Book-v3/chapter2/6answer #116

utterances-bot opened this issue Feb 28, 2022 · 11 comments
Labels
comments An area where readers can discuss related topics after every article.

Comments

@utterances-bot
Copy link

练习参考答案 — rCore-Tutorial-Book-v3 3.6.0-alpha.1 文档

https://rcore-os.github.io/rCore-Tutorial-Book-v3/chapter2/6answer.html

Copy link

Yui5427 commented Feb 28, 2022

编程题答案有吗

Copy link

请问 print_stack_trace() 在最后打印出的地址是 ra = 0x00000000802007a0, fp = 0x0000000000000001,导致了 Panicked at src/trap/mod.rs:45 Unsupported trap: Exception(LoadFault), stval = 0xfffffffffffffff9! 这个问题,请问应该怎么解决呢?

Copy link

我发现在我的程序中 fp 指向的地址已经是 null 了,这里是不是应该把判断 fp != ptr::null() 换为 !(*fp as *const usize).is_null() 呢?

fp = 0000000080205cb0, *fp = 0000000000000001, fp.sub(2) = 0000000080205ca0, *fp.sub(2) = 0000000080205d60
fp = 0000000080205d60, *fp = 0000000080208f28, fp.sub(2) = 0000000080205d50, *fp.sub(2) = 0000000080205e00
fp = 0000000080205e00, *fp = 0000000080205e60, fp.sub(2) = 0000000080205df0, *fp.sub(2) = 0000000080205e60
fp = 0000000080205e60, *fp = 0000000000000000, fp.sub(2) = 0000000080205e50, *fp.sub(2) = 0000000080205ef0
fp = 0000000080205ef0, *fp = 0000000000000000, fp.sub(2) = 0000000080205ee0, *fp.sub(2) = 0000000000000001
fp = 0000000000000001, *fp = Panicked at src/trap/mod.rs:45 Unsupported trap: Exception(LoadFault), stval = 0x1!

Copy link

编程第一题答案似乎有 bug,__alltraps 里面没有设置 fp
所以在调用 trap_handler 之后, trap_handler 会误把用户程序的 fp 当作 __alltrapsfp 来保存,回溯到这里的时候会出问题
其他汇编代码可能也有类似的问题

Copy link

编程题有答案吗

@wyfcyx wyfcyx added the comments An area where readers can discuss related topics after every article. label Jun 2, 2023
Copy link

建议编程题延后完成,除了第一个题目,后面四个都和后续内容相关

更可恶的是第二个题目就是第三章的lab。浪费了大量的时间只能完成部分题目然后到下一章的时候感觉自己被坑了。

Copy link

ASLR(地址空间布局随机化):ASLR 是CPU的一种随机化进程地址空间布局的安全功能,其能够随机生成进程地址空间,例如栈、共享库等关键部分的起始地址,使攻击者预测特定数据或代码的位置。

应该修改为:使攻击者无法预测特定数据或代码的位置。

@zjp-CN
Copy link
Contributor

zjp-CN commented May 2, 2024

第 6 题:RISC-V处理器在用户态执行特权指令后的硬件层面的处理过程是什么?

CPU 执行完一条指令(如 ecall )并准备从用户特权级 陷入( Trap )到 S 特权级的时候,硬件会自动完成如下这些事情:

  • sstatus 的 SPP 字段会被修改为 CPU 当前的特权级(U/S)。

这个 当前 是错的吧,应该是 陷入 S 之前,在规范里面,原文是

The SPP bit indicates the privilege level at which a hart was executing before entering supervisor
mode. When a trap is taken, SPP is set to 0 if the trap originated from user mode, or 1 otherwise.

(注意 before 和 originated )

不过虽然说“准备”已经意味着“当前"为 U 模式,但写得更清楚可以减少歧义。

Copy link

yuyi2439 commented Jul 1, 2024

sys_write的安全检查可以看看我写的 https://github.com/yuyi2439/rCore-Tutorial-v3/tree/ch2-my (可能有点丑

Copy link

“如果不进行Trap的上下文保存与恢复,CPU就无法在处理完成之后,返回原特权级。”这一句真的是对的吗,我的理解是使用sretmre·可以回到原来的特权级,但是因为通用寄存器被修改了所以会错乱。

Copy link

sys_write的安全检查可以看看我这篇博客,折腾了挺久的第二章作业

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comments An area where readers can discuss related topics after every article.
Projects
None yet
Development

No branches or pull requests