[BUG] RISC-V: new tasks inherit the previous task's FPU state (fcsr) because initial mstatus.FS is set to Clean
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- c
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Start with the FS setup in pxPortInitialiseStack() and the configENABLE_FPU block in portable/GCC/RISC-V/portASM.S, then trace portcontextSAVE_CONTEXT_INTERNAL and portcontextRESTORE_CONTEXT to see how the saved mstatus is restored. Decide how a new task's initial FS state should be encoded so its FPU state is defined, which the issue notes is a security-relevant design choice. Done means a fresh task reads frm and fflags as zero on RV32GC hardware or an emulator, with the maintainers having agreed on the approach.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When configENABLE_FPU == 1, pxPortInitialiseStack() forces mstatus.FS to MSTATUS_FS_CLEAN in the initial stack frame of every new task:
/* portable/GCC/RISC-V/portASM.S */
#if( configENABLE_FPU == 1 )
/* Mark the FPU as clean in the mstatus value. */
li t1, ~MSTATUS_FS_MASK
and t0, t0, t1
li t1, MSTATUS_FS_CLEAN
or t0, t0, t1
#endif
No FPU context area is reserved in that initial stack frame, and neither fcsr nor f0-f31 is initialised. When a task that used floating point is switched out, portcontexSAVE_FPU_CONTEXT stores the FPU state but only reads the physical registers (it does not clear them), and portcontextSAVE_CONTEXT_INTERNAL writes FS=Clean back to the hardware mstatus. When the new task is restored, portcontextRESTORE_CONTEXT loads the new task's saved mstatus into t3, writes it to mstatus, and then skips portcontextRESTORE_FPU_CONTEXT because the saved FS is not Dirty:
load_x t3, 1 * portWORD_SIZE( sp )
csrw mstatus, t3
...
srl t1, t3, MSTATUS_FS_OFFSET
andi t1, t1, 3
addi t2, x0, 3
bne t1, t2, 6f /* If FPU status is not dirty, do not restore FPU registers. */
portcontextRESTORE_FPU_CONTEXT
6:
Consequently, a task that has never used the FPU starts with mstatus.FS = Clean while the physical fcsr and f0-f31 still hold the previous task's values. This contradicts the Privileged Specification definition of Clean (section 3.1.6.6, RISC-V Privileged Architecture 20211203):
When the status is Clean, the corresponding state is potentially different from the initial value, but matches the last value stored on a context swap.
A newly created task has no "last value stored on a context swap", so the Clean encoding is semantically invalid for it. The same section also states:
Changing the setting of FS has no effect on the contents of the floating-point register state.
If the status is Initial, the context must be set to an initial constant value on context restore to avoid a security hole, but this can be done without accessing memory.
Target
- Development board: hpm6750evk2
- Instruction Set Architecture: RV32GC
- Toolchain and version: GNU GCC V13.2.0
Host
- Host OS: Windows11
- Version: 25H2
** Impact **
- A new task inherits the previous task's
frm(rounding mode) andfflags(accrued exceptions). Its first floating-point operations may silently use a different rounding mode and non-zero exception flags. - This is a cross-task information leak. The spec explicitly describes an uninitialised Initial state as a "security hole"; using Clean without a saved image is at least as problematic.
Steps to reproduce
- Build with
configENABLE_FPU = 1for an RV32/RV64 core with F/D. - Create Task A that sets a non-default rounding mode (for example
frm = RTZviacsrw frm) and performs floating-point arithmetic, somstatus.FSbecomes Dirty. - Force a context switch (tick interrupt or
taskYIELD()) so Task A's FPU context is saved. - Create/start Task B. On its first run, read
frm/fcsr, or perform an FP operation that assumes the default RNE mode. - Observe that Task B sees RTZ and Task A's
fflagsinstead of the expectedfcsr = 0.
- Ngôn ngữ chính
- C
- Star
- 4.6k
- Fork
- 1.6k
- Merge trung bình
- 2 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FreeRTOS/FreeRTOS-Kernel
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
FreeRTOS/FreeRTOS-Kernel#1542 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG] Release asset FreeRTOS-KernelV11.3.2.zip has the files of main, not of the tag V11.3.2Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
FreeRTOS/FreeRTOS-Kernel#1494 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG] event_wait_timed can't return falseCó thể đã có người làm @TedLyngmo đã nhận 39 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của FreeRTOS/FreeRTOS-Kernel
Issue tương tự
-
RecompLauncher supportĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
shinyquagsire23/OpenJKDF2#540 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Life-Framework/Life-Framework#5939 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
autoconf failes to find libsodium even when present due to implicit function declarationCó thể đã có người làm @coderjoe đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 13 ngày
-
SessionInterfaceHandler is throwing a deprecation notice as a warning instead of a deprecationĐang mởBug Status: Needs Triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement_package: a site operand of another JSON type raises TypeError, not a named refusalĐang mởbug python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
Jstar269/nakagawa-recomp#3521 ·
Maintainer thường phản hồi trong vòng 1 ngày