SecBits
A Rust library for secure memory handling with enhanced protection against common vulnerabilities and memory inspection attacks.
Features
- ๐ Secure memory allocation with page alignment
- ๐งน Automatic secure zeroing before deallocation
- ๐ Memory locking to prevent swapping to disk
- ๐ก๏ธ Fork protection (Linux) to wipe memory on fork
- ๐ซ Core dump exclusion to prevent sensitive data leaks
- ๐ Fine-grained access control with read/write guards
Security Properties
- Confidentiality: Memory is locked and wiped on release
- Integrity: Write access is controlled via guards
- Availability: Prevents accidental exposure via core dumps
- Least Privilege: Memory starts as no-access, transitions only when needed
Use Case: Sensitive data handling (cryptographic keys, passwords, PII)
Installation
Add to Cargo.toml:
[]
= "0.3.0"
Quick Start
use SecBytes;
// Memory automatically unlocked and zeroed here
Major Components
1. SecSpace Core
Key Features:
- ๐ Page-Aligned Allocations: Always uses system page size multiples
- ๐ก๏ธ Protection Modes:
ProtectionMode::None- No access (default)ProtectionMode::Read- Read-onlyProtectionMode::ReadWrite- Read-write
- โ ๏ธ Secure Drop:
- Set memory to RW mode
- Zero using platform-secure methods
- Unlock and deallocate
2. SecBytes Buffer
Key Features:
- ๐ Dynamic Resizing: Maintains 2x growth factor
- ๐ Access Views:
SecReadBytes: Shared read access (RO mode)SecWriteBytes: Exclusive write access (RW mode)
- ๐งต Concurrency Safety:
- Multiple readers allowed
- Writers get exclusive access via &mut
Key Tricks
1. Safe Memory Management
// Always use RAII guards
// Auto resets to NOACCESS
2. Secure Data Handling
// Source data gets zeroed automatically
secret.edit?.append?;
๐ Security Considerations
Guarantees
- ๐ก๏ธ Memory never swapped to disk (mlock)
- ๐ซ Sensitive data excluded from core dumps
- ๐ต๏ธ Defeats heap inspection attacks
- ๐ง Prevents compiler optimizations from skipping zeroing
Limitations
- โ ๏ธ Requires CAP_IPC_LOCK on Linux (or root)
- ๐พ Physical memory still potentially recoverable
- ๐ Doesn't protect against hardware attacks