rustsec / rustsec/advisory-db

Unsoundness in scaly

Open
#2,594 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
1.2k
Forks
544
Avg merge
1d 10h
Merged PRs (30d)
45

Description

I discovered an unsoundness in scaly, but I couldn't locate its repository, so I'm submitting it here. Implementation of Index::index did not check the bound.

  82 | impl<T: Copy> Index<usize> for Array<T> {
  83 |     type Output = T;
  84 |     fn index(&self, offset: usize) -> &Self::Output {
  85 |         unsafe { &*self.vector.data.offset(offset as isize) }
  86 |     }
  87 | }

reproduce case:

use scaly::Array;

fn main() {
    let mut a: Array<u8> = Array::new();
    a.add(1);

    // Safe API OOB: Index<usize> does unchecked pointer offset
    // This should be UB (Miri will flag).
    let v = a[1];
    std::hint::black_box(v);
}

miri reports:

error: Undefined Behavior: pointer not dereferenceable: pointer must be dereferenceable for 16 bytes, but got 0x20000[noalloc] which is a dangling pointer (it has no provenance)
  --> /home/test/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/scaly-0.0.37/src/containers/array.rs:58:38
   |
58 |                 let exclusive_page = (*_own_page).allocate_exclusive_page();
   |                                      ^^^^^^^^^^^^ Undefined Behavior occurred here
   |
...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the reported Index implementation in scaly's src/containers/array.rs and reproduce the out-of-bounds access with the supplied example under Miri. Confirm the affected scaly version and determine the appropriate advisory-db change; done means the vulnerability details and remediation status are verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.