
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.
AlignedF32::zeros(len) computes the allocation size as len * size_of::<f32>() with a plain multiplication. This is in frink-core 0.63.0 and on main (55f122a85132). In a release build a very large len wraps to a small size, one page is allocated, and Deref then hands out a &[f32] of the original len over that page. Safe code can reach it, but only with a len above 2^62, and a debug build panics on the multiplication instead.
Affected code:
AlignedF32::zeros: https://github.com/antonellof/frink/blob/55f122a85132d7d22f9e4f0e6496968a50b4f353/crates/frink-core/src/recurrent_state.rs#L111-L119Deref / DerefMut: https://github.com/antonellof/frink/blob/55f122a85132d7d22f9e4f0e6496968a50b4f353/crates/frink-core/src/recurrent_state.rs#L143-L156pub fn zeros(len: usize) -> Self {
let bytes = (len * std::mem::size_of::<f32>()).max(1).div_ceil(PAGE) * PAGE; // wraps without overflow checks
let layout = std::alloc::Layout::from_size_align(bytes, PAGE).expect("page layout");
let raw = unsafe { std::alloc::alloc_zeroed(layout) } as *mut f32;
let ptr = std::ptr::NonNull::new(raw).expect("allocation failed");
Self { ptr, len, bytes } // len is stored as given
}fn deref(&self) -> &[f32] {
// SAFETY: `len` floats were allocated and zeroed by `zeros`.
unsafe { std::slice::from_raw_parts(self.ptr.as_ptr(), self.len) }
}With len = 2^62 + 4 the product is 2^64 + 16, which wraps to 16 when overflow checks are off. That rounds up to one 16 KiB page, so Layout::from_size_align is happy. The stored len is still 2^62 + 4, so the SAFETY comment in deref no longer holds and every index from 4096 up is outside the allocation. deref_mut builds the same slice.
RecurrentState::zeros(conv_len, ssm_len) passes its arguments straight through. I have not looked for a way to reach such a length from a model file, and I think the sizes there are tied to tensors that have to exist, so this is about the public API and not about a crafted GGUF.
A new cargo project with frink-core = "=0.63.0" as its only dependency, and this src/main.rs:
use frink_core::recurrent_state::AlignedF32;
use std::hint::black_box;
fn main() {
let len = black_box((1usize << 62) + 4); // len * 4 wraps to 16
let a = AlignedF32::zeros(len); // allocates one 16 KiB page, keeps len
println!("alloc_bytes = {}", a.alloc_bytes());
let s: &[f32] = &a; // slice of 2^62 + 4 floats over 16 KiB
let i = black_box(4096); // first float past the page
println!("a[{i}] = {}", s[i]);
}Miri (cargo +nightly miri run --release, where --release only turns the overflow checks off):
alloc_bytes = 16384
error: Undefined Behavior: constructing invalid value of type &[f32]: encountered invalid reference metadata: slice is bigger than largest supported object
--> src/recurrent_state.rs:147:18
|
147 | unsafe { std::slice::from_raw_parts(self.ptr.as_ptr(), self.len) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
0: <frink_core::recurrent_state::AlignedF32 as std::ops::Deref>::deref src/recurrent_state.rs:147
1: main src/main.rs:8A normal release build prints this and exits normally:
alloc_bytes = 16384
a[4096] = 0ASan does not report that read. If I write instead (a[1 << 40] = 1.0 through DerefMut), the release build dies with SIGSEGV. A debug build panics at recurrent_state.rs:112 with attempt to multiply with overflow, so this only matters when overflow checks are off. It also reproduces with 0.26.0 and 0.50.0.
An out-of-bounds read, and a write through DerefMut, from safe Rust code in a release build. It needs a len above 2^62 passed to the public API, so I would call it a soundness issue (RustSec informational = "unsound") with low severity.
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."