
Cloud Vulnerability DB
A community-led vulnerabilities database
Version: frink-core 0.63.0 from crates.io. It is triggered through the Rust API of frink-core, not through the frink command or a server request.
ExpertStore::with_slots takes a Box<dyn SlotMemory> and later builds &[u8] slices over the pointers that slot_ptr returned, without checking them. This is in frink-core 0.63.0 and on main (55f122a85132). SlotMemory is a safe trait, so an implementation written in safe code can return a pointer to a smaller buffer and the store reads past it. It needs a custom SlotMemory impl. The two impls in the crate are fine.
Affected code:
SlotMemory trait: https://github.com/antonellof/frink/blob/55f122a85132d7d22f9e4f0e6496968a50b4f353/crates/frink-core/src/expert_slab.rs#L54-L63SlotPool::new: https://github.com/antonellof/frink/blob/55f122a85132d7d22f9e4f0e6496968a50b4f353/crates/frink-core/src/expert_store/bytes.rs#L29-L41ExpertBytes::as_slice: https://github.com/antonellof/frink/blob/55f122a85132d7d22f9e4f0e6496968a50b4f353/crates/frink-core/src/expert_store/bytes.rs#L81-L95
The length requirement on slot_ptr is only a doc comment:pub trait SlotMemory: SlotDevice + Send + Sync {
fn geometry(&self) -> &SlotGeometry;
fn kind(&self) -> &'static str;
/// First byte of `slot`, valid for `geometry().row_bytes[0]` bytes
/// for as long as this value lives. Panics on an out-of-range slot.
fn slot_ptr(&self, slot: u32) -> NonNull<u8>; // safe trait, safe method
}SlotPool::new caches one pointer per slot, and ExpertBytes::as_slice turns it into a slice:
let base = pool.slot_addrs[*slot as usize];
// SAFETY: `base` is valid for `slot_bytes >= len` bytes
// while `pool` lives, and this value holds the pool. ...
unsafe { std::slice::from_raw_parts(base.as_ptr(), *len) } // nothing checked thisThe SAFETY comment relies on what the trait impl promised. Since the trait is not unsafe, an impl can break that promise without writing any unsafe, and the unsafe block in as_slice is the one that ends up wrong. len is checked against slot_bytes, but slot_bytes comes from the same impl's geometry().
I think SlabRegion has the same shape: SlotSlab trusts base() and len() in write_slot, copy_slot and slot_ptr, and it is also a safe trait. I did not run that one.
A new cargo project with frink-core = "=0.63.0" as its only dependency, and this src/main.rs:
use frink_core::expert_slab::SlotMemory;
use frink_core::expert_slots::{SlotDevice, SlotGeometry};
use frink_core::expert_store::{ExpertKey, ExpertSource, ExpertStore};
use std::ptr::NonNull;
struct Small {
geo: SlotGeometry,
buf: Box<[u8; 1]>, // one byte of real memory
}
impl SlotDevice for Small {
fn write_slot(&mut self, _bank: usize, _slot: u32, _src: &[u8]) -> Result<(), String> {
Ok(())
}
fn copy_slot(&mut self, _bank: usize, _dst: u32, _src: u32) -> Result<(), String> {
Ok(())
}
}
impl SlotMemory for Small {
fn geometry(&self) -> &SlotGeometry {
&self.geo // says a slot is 64 bytes
}
fn kind(&self) -> &'static str {
"small"
}
fn slot_ptr(&self, _slot: u32) -> NonNull<u8> {
NonNull::from(&self.buf[0]) // valid for 1 byte only
}
}
struct Src;
impl ExpertSource for Src {
fn expert_len(&self, _key: ExpertKey) -> Option<usize> {
Some(64)
}
fn read_expert(&self, _key: ExpertKey) -> std::io::Result<Vec<u8>> {
Ok(vec![7u8; 64])
}
}
fn main() {
let mem = Small {
geo: SlotGeometry { num_layers: 1, slots: 1, row_bytes: vec![64] },
buf: Box::new([0u8]),
};
let store = ExpertStore::with_slots(Src, Box::new(mem));
let lease = store.acquire(ExpertKey { layer: 0, expert: 0 }).unwrap();
let bytes = lease.bytes(); // &[u8] of 64 bytes over the 1-byte box
let sum: u64 = bytes.iter().map(|&b| b as u64).sum();
println!("len = {} sum = {}", bytes.len(), sum);
}Miri (cargo +nightly miri run):
error: Undefined Behavior: constructing invalid value of type &[u8]: encountered a dangling reference (going beyond the bounds of its allocation)
--> src/expert_store/bytes.rs:92:26
|
92 | unsafe { std::slice::from_raw_parts(base.as_ptr(), *len) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
0: frink_core::expert_store::ExpertBytes::as_slice src/expert_store/bytes.rs:92
1: <frink_core::expert_store::ExpertBytes as std::ops::Deref>::deref src/expert_store/bytes.rs:110
2: frink_core::expert_store::ExpertLease::bytes src/expert_store.rs:113
3: main src/main.rs:50The error is the same with -Zmiri-disable-stacked-borrows and with -Zmiri-tree-borrows.
AddressSanitizer (RUSTFLAGS="-Zsanitizer=address -g" cargo +nightly run --release --target x86_64-unknown-linux-gnu):
ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 1
#0 frink_slot_memory_ptr::main
0x6ce73c9e0031 is located 0 bytes after 1-byte region [0x6ce73c9e0030,0x6ce73c9e0031)A normal release build exits normally and prints len = 64 sum = 796, which is the sum of whatever sits after the box. It also reproduces with 0.51.0 and 0.57.0. 0.50.0 does not have with_slots.
An out-of-bounds read from safe Rust code, with no unsafe in the caller. It only happens with a custom SlotMemory implementation, so I would call it a soundness issue (RustSec informational = "unsound") with low severity. I am sending it through this form because SECURITY.md asks not to open a public issue for a security problem. It is about the library API of frink-core, not about the server or a crafted model file, so it may be outside the scope list there. If you see it as an ordinary bug, I can open a public issue instead.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."