Skip to content

Commit ec44937

Browse files
Update translated documentation (#1396)
1 parent 7100b83 commit ec44937

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

docs/.translation_cache.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
"hash": "71c15cea87dffe58f5d70da38390a083"
307307
},
308308
"en:kernel/memory_management/extable_safe_copy_design.md": {
309-
"hash": "b337bca913e9e0de881ed5f81dcb5210"
309+
"hash": "fabf6a20ce3a3d1974d678f039fa32b5"
310310
},
311311
"en:community/ChangeLog/V0.3.x/V0.3.0.md": {
312312
"hash": "a3b5ae01c7a5f3ad9d26f71b54d01790"

docs/locales/en/kernel/memory_management/extable_safe_copy_design.md

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ This document was automatically translated by `hunyuan-turbos-latest` model, for
55

66
- Source document: kernel/memory_management/extable_safe_copy_design.md
77

8-
- Translation time: 2025-11-18 13:03:29
8+
- Translation time: 2025-11-21 06:28:18
99

1010
- Translation model: `hunyuan-turbos-latest`
1111

1212
Please report issues via [Community Channel](https://github.com/DragonOS-Community/DragonOS/issues)
1313

1414
:::
1515

16-
# Design of Secure Memory Copy Scheme Based on Exception Table
16+
# Secure Memory Copy Scheme Based on Exception Table
1717

1818
:::{note}
1919

@@ -23,13 +23,13 @@ Author: Long Jin <[email protected]>
2323

2424
## Overview
2525

26-
This document describes the core design concept of a secure memory copy scheme in DragonOS based on the Exception Table mechanism. This solution addresses the issue of safely accessing user-space memory in system call contexts, preventing kernel panics caused by accessing invalid user addresses.
26+
This document describes the core design of a secure memory copy scheme in DragonOS based on the Exception Table mechanism. This solution addresses the issue of safely accessing user-space memory in system call contexts, preventing kernel panics caused by accessing invalid user addresses.
2727

2828
## Design Background and Motivation
2929

3030
### Problem Definition
3131

32-
During system call processing, the kernel needs to access pointers passed from user space (such as path strings, parameter structures, etc.). These accesses may fail due to:
32+
During system call processing, the kernel needs to access pointers passed from user space (such as path strings, parameter structures, etc.). These accesses may fail:
3333

3434
1. **Unmapped address**: The user-provided address has no corresponding VMA (Virtual Memory Area)
3535
2. **Insufficient permissions**: The page exists but lacks required permissions
@@ -38,22 +38,22 @@ During system call processing, the kernel needs to access pointers passed from u
3838
### Limitations of Traditional Solutions
3939

4040
**TOCTTOU issues with pre-checking solutions:**
41-
- Addresses may be valid during check but modified by other threads when used
42-
- Race condition windows exist
41+
- An address may be valid during check but modified by other threads when used
42+
- Race condition window exists
4343

44-
**Dilemma of direct access:**
44+
**Challenges with direct access:**
4545
- Cannot distinguish between "normal page fault" and "illegal access"
46-
- Page fault handlers cannot determine whether it's a kernel bug or user error
46+
- Page fault handler cannot determine whether it's a kernel bug or user error
4747

48-
## Principles of Exception Table Mechanism
48+
## Exception Table Mechanism Principles
4949

5050
### Core Idea
5151

52-
The Exception Table mechanism achieves secure user-space access through **compile-time marking + runtime lookup**:
52+
The exception table mechanism achieves secure user-space access through **compile-time marking + runtime lookup**:
5353

54-
1. **Compile-time**: Generate exception table entries at instructions that may trigger page faults
54+
1. **Compile-time**: Generate exception table entries for instructions that may trigger page faults
5555
2. **Runtime**: When a page fault occurs, search the exception table and jump to fix-up code
56-
3. **Zero overhead**: No performance loss on normal paths
56+
3. **Zero overhead**: No performance loss on the normal path
5757

5858
### Architectural Diagram
5959

@@ -76,7 +76,7 @@ The Exception Table mechanism achieves secure user-space access through **compil
7676
│ │ 4. 修改指令指针(RIP) │ │
7777
│ │ ↓ │ │
7878
│ │ 5. 执行修复代码 │ │
79-
│ │ └─ 设置错误码(-1) │ │
79+
│ │ └─ 返回剩余未拷贝字节数 │ │
8080
│ │ ↓ │ │
8181
│ │ 6. 返回EFAULT给用户 │ │
8282
│ └──────────────────────────────┘ │
@@ -85,15 +85,15 @@ The Exception Table mechanism achieves secure user-space access through **compil
8585

8686
### Core Data Structures
8787

88-
**Exception Table Entry (8-byte aligned):**
88+
**Exception table entry (8-byte aligned):**
8989
```
9090
┌─────────────────┬──────────────────┐
9191
│ 指令相对偏移 │ 修复代码相对偏移 │
9292
│ (4 bytes) │ (4 bytes) │
9393
└─────────────────┴──────────────────┘
9494
```
9595

96-
**Design Highlights:**
96+
**Design highlights:**
9797
- Uses relative offsets to support ASLR (Address Space Layout Randomization)
9898
- 8-byte alignment improves cache performance
9999
- Stored in read-only segments to prevent tampering
@@ -114,14 +114,14 @@ The Exception Table mechanism achieves secure user-space access through **compil
114114
115115
116116
117-
修改RIP到修复代码 ──→ 返回错误码
117+
修改RIP到修复代码 ──→ 返回剩余未拷贝字节数
118118
```
119119

120120
## Typical Execution Scenarios
121121

122-
### Scenario: System Call with Invalid Address
122+
### Scenario: System call with invalid address
123123

124-
Taking the `open()` system call as an example, demonstrating the operation of the exception table:
124+
Taking the `open()` system call as an example, demonstrating the exception table's operation:
125125

126126
```
127127
用户程序: open(0x1000, O_RDONLY) // 0x1000未映射
@@ -150,7 +150,7 @@ Taking the `open()` system call as an example, demonstrating the operation of th
150150
151151
┌────────────────────────────────┐
152152
│ 4. 修改指令指针到修复代码 │
153-
│ └─ 设置返回值为错误码
153+
│ └─ 设置返回值为剩余未拷贝字节数
154154
└────────────────────────────────┘
155155
156156
@@ -162,42 +162,42 @@ Taking the `open()` system call as an example, demonstrating the operation of th
162162
用户程序: fd = -1, errno = EFAULT
163163
```
164164

165-
**Key Points:**
165+
**Key points:**
166166
- No need for pre-checking address validity
167-
- Page faults are automatically converted to error codes
168-
- Kernel won't panic, user programs receive clear error information
167+
- Page faults are automatically converted to returning the number of remaining uncopied bytes
168+
- The kernel won't panic, and user programs receive clear error information
169169

170170
## Usage Scenario Analysis
171171

172-
### Suitable Scenarios for Exception Table Protection
172+
### ✅ Scenarios Suitable for Exception Table Protection
173173

174-
#### 1. Small Data System Call Parameters
174+
#### 1. Small system call parameter data
175175

176176
**Characteristics:**
177177
- Small data volume (typically < 4KB)
178-
- Single copy operation
178+
- One-time copy
179179
- Unknown data length (e.g., strings)
180180

181-
**Typical Applications:**
181+
**Typical applications:**
182182
- Path strings: `open()`, `stat()`, `execve()`, etc.
183183
- Fixed-size structures: `sigaction`, `timespec`, `stat`, etc.
184184
- Small arrays: `iovec[]`, `pollfd[]`, etc.
185185

186186
**Advantages:**
187187
- **Avoids TOCTTOU races**: No pre-checking needed
188188
- **High robustness**: User errors won't cause kernel panics
189-
- **Acceptable performance**: Small data volume, minimal impact even with extra copies
189+
- **Acceptable performance**: Small data volume; even multiple copies have minimal impact
190190

191-
#### 2. Scenarios with Uncertain Address Validity
191+
#### 2. Scenarios with uncertain address validity
192192

193193
When address validity cannot be verified by other means, the exception table is the safest choice:
194194
- Raw pointers directly provided by users
195195
- Addresses that may be concurrently modified in multi-threaded environments
196196
- Operations requiring atomicity guarantees
197197

198-
### Unsuitable Scenarios for Exception Table Protection
198+
### ❌ Scenarios Unsuitable for Exception Table Protection
199199

200-
#### 1. Large Data Transfers
200+
#### 1. Large data transfers
201201

202202
**Anti-pattern: Double buffering in read/write system calls**
203203
```
@@ -207,43 +207,43 @@ When address validity cannot be verified by other means, the exception table is
207207
**Issues:**
208208
- Memory waste: Requires additional kernel buffers
209209
- Double copying: Data is copied twice
210-
- OOM risk: Concurrent large reads/writes may exhaust memory
210+
- OOM risk: Large concurrent reads/writes exhaust memory
211211

212-
**Correct Approach: Zero-copy**
212+
**Correct approach: Zero-copy**
213213
- Pre-validate addresses within valid VMAs
214214
- Operate directly on user buffers
215215
- Page faults trigger normal page fault handling (not errors)
216216

217-
#### 2. Addresses Already Validated in VMAs
217+
#### 2. Addresses already validated within VMAs
218218

219-
If addresses have been validated through VMA checks, the exception table is redundant:
219+
If addresses have been verified through VMA checks, the exception table is redundant:
220220
- Immediate access after `mmap()`
221221
- DMA buffers
222222
- Shared memory regions
223223

224-
In these scenarios, page faults are **normal page fault handling** (like COW), not errors.
224+
In these scenarios, page faults are **normal page fault handling** (e.g., COW), not errors.
225225

226-
#### 3. Performance-Critical Hot Paths
226+
#### 3. Performance-critical hot paths
227227

228228
Avoid frequently calling functions protected by exception tables in loops:
229-
- **Batch processing**: Copy entire arrays at once rather than element-by-element
230-
- **Pre-validation**: Validate addresses outside loops, direct access inside loops
229+
- **Batch processing**: Copy entire arrays at once rather than element by element
230+
- **Pre-validation**: Validate addresses outside loops and access directly within loops
231231

232232
### Decision Matrix
233233

234-
| Scenario Characteristics | Data Volume | Recommended Solution | Key Considerations |
235-
|--------------------------|-------------|----------------------|--------------------|
234+
| Scenario Characteristics | Data Volume | Recommended Solution | Core Considerations |
235+
|--------------------------|-------------|----------------------|---------------------|
236236
| Small system call parameters | < 4KB | Exception table protection | Avoid TOCTTOU, improve robustness |
237-
| File I/O | Variable (MB-level) | Zero-copy | Performance priority, avoid double buffering |
238-
| Access after mmap | Any | Direct access | VMA already validated, normal page fault |
237+
| File read/write | Variable (MB-level) | Zero-copy | Performance priority, avoid double buffering |
238+
| Access after mmap | Arbitrary | Direct access | VMA already validated, normal page fault |
239239
| Batch small data | Cumulative KB-level | Batch copy | Reduce system call count |
240240
| String parsing | Unknown | Exception table protection | Byte-by-byte scanning, requires robustness |
241241

242242
## Security Analysis
243243

244244
### Defensive Capabilities
245245

246-
The Exception Table mechanism can defend against:
246+
The exception table mechanism can defend against:
247247

248248
1. **Null pointer dereferencing**: Returns EFAULT instead of segmentation fault
249249
2. **Kernel address injection**: User-provided kernel addresses are safely rejected
@@ -252,15 +252,15 @@ The Exception Table mechanism can defend against:
252252

253253
### Security Boundaries
254254

255-
The Exception Table **cannot** defend against:
255+
The exception table **cannot** defend against:
256256

257257
1. **Kernel bugs**: Such as wild pointer dereferencing
258258
2. **Hardware failures**: Physical memory damage
259259
3. **Other exception types**: Only handles page faults
260260

261261
### Multi-layer Defense
262262

263-
The Exception Table is part of defense in depth:
263+
The exception table is part of defense in depth:
264264

265265
```
266266
┌─────────────────────────────────────┐
@@ -280,15 +280,15 @@ The Exception Table is part of defense in depth:
280280

281281
1. **Relative offset encoding**: Supports address randomization (ASLR)
282282
2. **Binary search**: O(log n) time complexity for fast location
283-
3. **Inline assembly**: Precise control over instruction generation and exception table creation
284-
4. **Zero-overhead abstraction**: No performance loss on normal paths
283+
3. **Inline assembly**: Precise control over instruction and exception table generation
284+
4. **Zero-overhead abstraction**: No performance loss on the normal path
285285

286286
### Architecture Portability
287287

288-
The Exception Table mechanism can be ported to other architectures:
288+
The exception table mechanism can be ported to other architectures:
289289

290290
- **x86_64**: Uses `rep movsb` instruction
291291
- **ARM64**: Uses `ldp/stp` instruction sequence
292292
- **RISC-V**: Uses `ld/sd` instruction sequence
293293

294-
The core concept remains unchanged, only assembly syntax needs adjustment.
294+
The core idea remains unchanged, requiring only adjustments to assembly syntax.

0 commit comments

Comments
 (0)