Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • L linux
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Kirill Smelkov
  • linux
  • Repository
  • linux
  • rust
  • kernel
  • alloc
  • vec_ext.rs
Find file BlameHistoryPermalink
  • Danilo Krummrich's avatar
    rust: alloc: fix dangling pointer in VecExt<T>::reserve() · 97ab3e8e
    Danilo Krummrich authored May 01, 2024
    Currently, a Vec<T>'s ptr value, after calling Vec<T>::new(), is
    initialized to Unique::dangling(). Hence, in VecExt<T>::reserve(), we're
    passing a dangling pointer (instead of NULL) to krealloc() whenever a new
    Vec<T>'s backing storage is allocated through VecExt<T> extension
    functions.
    
    This only works as long as align_of::<T>(), used by Unique::dangling() to
    derive the dangling pointer, resolves to a value between 0x0 and
    ZERO_SIZE_PTR (0x10) and krealloc() hence treats it the same as a NULL
    pointer however.
    
    This isn't a case we should rely on, since there may be types whose
    alignment may exceed the range still covered by krealloc(), plus other
    kernel allocators are not as tolerant either.
    
    Instead, pass a real NULL pointer to krealloc_aligned() if Vec<T>'s
    capacity is zero.
    
    Fixes: 5ab560ce
    
     ("rust: alloc: update `VecExt` to take allocation flags")
    Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
    Reviewed-by: default avatarBoqun Feng <boqun.feng@gmail.com>
    Reviewed-by: default avatarBenno Lossin <benno.lossin@proton.me>
    Signed-off-by: default avatarDanilo Krummrich <dakr@redhat.com>
    Reviewed-by: default avatarWedson Almeida Filho <walmeida@microsoft.com>
    Link: https://lore.kernel.org/r/20240501134834.22323-1-dakr@redhat.com
    
    
    [ Solved `use` conflict and applied the `if`-instead-of-`match` change
      discussed in the list. - Miguel ]
    Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
    97ab3e8e
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7