dropbox / dropbox/rust-alloc-no-stdlib

Soundness/documentation issue: CallocBackingStore::new is not safety documented and potentially unsound

Ouverte
#20 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Rust
Étoiles
180
Forks
21
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

The unsafe function CallocBackingStore::new does not have documentation for its safety invariants - and neither does the `define_allocator_memory_pool` macro calling it.
https://github.com/dropbox/rust-alloc-no-stdlib/blob/6032b6a9b20e03737135c55a0270ccffcc1438ef/src/lib.rs#L41

I believe the safety contract should mention that:
- the caller must guarantee that the allocator passed in can be safely called (including the corner-case of having a 0 argument for size), and returns buffers of the appropriate size.
- the correct relationship between `alloc` and `free` is upheld (free must be a valid function to free the memory allocated by `alloc`)
- computing `num_elements * sizeof(T)` must not overflow -- unless that is checked in the body of the function.

Moreover, using the macro with `malloc` is *always* unsound unless `T` is `MaybeUninit<_>`: `new` will end up creating a reference to a slice of uninitialized data, which is UB.
Even using the function with `calloc` might be unsound if `0` is not a valid bit pattern for `T`.
Similarly, when using a custom allocator, the bitpatterns returned by the custom allocator should be valid for `T`.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez dans src/lib.rs, autour de CallocBackingStore::new et de la macro define_allocator_memory_pool. Examinez comment les callbacks de l’allocator et le slice sont utilisés, puis documentez les invariants de sécurité identifiés dans l’issue, notamment la compatibilité entre l’allocation et la libération ainsi que les motifs de bits valides. Le travail est terminé lorsque les deux points d’entrée unsafe indiquent clairement les garanties requises de la part de l’appelant.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
rust
Domaine
operating-systems
Type d'issue
Documentation
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.