Skip to content

[CHERI CSA Report] Bad pointer alignment cast in sdk/core/allocator/alloc.h #562

@resistor

Description

@resistor

The new CHERI clang-static-analyzer checkers are producing the following warning. This could very well be a false positive.

---
MainSourceFile:  '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
Diagnostics:
  - DiagnosticName:  clang-analyzer-optin.portability.PointerAlignment
    DiagnosticMessage:
      Message:         'Pointer value aligned to a 4 byte boundary cast to type ''uintptr_t * __capability'' with 8-byte capability alignment'
      FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
      FileOffset:      20291
      Replacements:    []
    Notes:
      - Message:         'Original allocation of type ''class ds::linked_list::cell::PtrAddr'' has an alignment requirement 4 bytes'
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      19128
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      19128
            Length:          4
      - Message:         Assuming the condition is false
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
        FileOffset:      25918
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
            FileOffset:      25918
            Length:          31
      - Message:         Taking false branch
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
        FileOffset:      25914
        Replacements:    []
      - Message:         Taking true branch
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
        FileOffset:      25977
        Replacements:    []
      - Message:         '''IsAsynchronous'' is false'
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
        FileOffset:      26335
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
            FileOffset:      26335
            Length:          35
      - Message:         Taking false branch
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
        FileOffset:      26321
        Replacements:    []
      - Message:         'Calling ''MState::quarantine_dequeue'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
        FileOffset:      26575
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/main.cc'
            FileOffset:      26575
            Length:          24
      - Message:         'Calling ''MState::mspace_qtbin_deqn'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      44611
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      44611
            Length:          20
      - Message:         'Calling ''MState::quarantine_finished_get'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      72572
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      72572
            Length:          25
      - Message:         'Calling ''MState::rederive'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      27067
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      27067
            Length:          85
      - Message:         'Calling ''AddressProxy::operator='''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      28382
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      28382
            Length:          19
      - Message:         'Calling ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'void * __capability argument may be a pointer to capability'
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      13396
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      13396
            Length:          6
      - Message:         'Returning from ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'Returning from ''AddressProxy::operator='''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      28382
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      28382
            Length:          19
      - Message:         'Returning from ''MState::rederive'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      27067
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      27067
            Length:          85
      - Message:         'Returning from ''MState::quarantine_finished_get'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      72572
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      72572
            Length:          25
      - Message:         Loop condition is true.  Entering loop body
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      72602
        Replacements:    []
      - Message:         Taking false branch
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      72755
        Replacements:    []
      - Message:         'Calling ''Sentinel::first'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      72936
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      72936
            Length:          19
      - Message:         'Calling ''PtrAddr::operator ds::linked_list::cell::PtrAddr *'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      11901
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      11901
            Length:          20
      - Message:         'Calling ''AddressProxy::operator='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3434
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3434
            Length:          17
      - Message:         'Calling ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'void * __capability argument may be a pointer to capability'
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      13396
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      13396
            Length:          6
      - Message:         'Returning from ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'Returning from ''AddressProxy::operator='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3434
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3434
            Length:          17
      - Message:         'Returning from ''PtrAddr::operator ds::linked_list::cell::PtrAddr *'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      11901
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      11901
            Length:          20
      - Message:         'Returning from ''Sentinel::first'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      72936
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      72936
            Length:          19
      - Message:         'Calling ''MChunkHeader::from_body'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      72988
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      72988
            Length:          29
      - Message:         'Calling ''offset<MChunkHeader, void, unsigned int>'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      10697
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      10697
            Length:          62
      - Message:         'Calling ''AddressProxy::operator+='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      584
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      584
            Length:          21
      - Message:         'Calling ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14717
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14717
            Length:          58
      - Message:         'void * __capability argument may be a pointer to capability'
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      13396
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      13396
            Length:          6
      - Message:         'Returning from ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14717
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14717
            Length:          58
      - Message:         'Returning from ''AddressProxy::operator+='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      584
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      584
            Length:          21
      - Message:         'Calling ''Capability::cast'''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      616
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      616
            Length:          23
      - Message:         'Calling constructor for ''Capability<void, false>'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      29849
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      29849
            Length:          86
      - Message:         'decltype(ptr) argument may be a pointer to capability'
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      21839
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      21839
            Length:          1
      - Message:         'Returning from constructor for ''Capability<void, false>'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      29849
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      29849
            Length:          86
      - Message:         'Returning from ''Capability::cast'''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      616
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      616
            Length:          23
      - Message:         'Returning from ''offset<MChunkHeader, void, unsigned int>'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      10697
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      10697
            Length:          62
      - Message:         'Returning from ''MChunkHeader::from_body'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      72988
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      72988
            Length:          29
      - Message:         'Calling ''unsafe_remove<ds::linked_list::cell::PtrAddr>'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      73482
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      73482
            Length:          43
      - Message:         'Calling ''unsafe_remove<ds::linked_list::cell::PtrAddr>'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      7767
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      7767
            Length:          19
      - Message:         'Calling ''PtrAddr::operator->'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      7611
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      7611
            Length:          3
      - Message:         'Calling ''PtrAddr::operator ds::linked_list::cell::PtrAddr *'''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3540
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3540
            Length:          5
      - Message:         'Calling ''AddressProxy::operator='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3434
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3434
            Length:          17
      - Message:         'Calling ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'void * __capability argument may be a pointer to capability'
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      13396
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      13396
            Length:          6
      - Message:         'Returning from ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'Returning from ''AddressProxy::operator='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3434
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3434
            Length:          17
      - Message:         'Returning from ''PtrAddr::operator ds::linked_list::cell::PtrAddr *'''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3540
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3540
            Length:          5
      - Message:         'Returning from ''PtrAddr::operator->'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      7611
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      7611
            Length:          3
      - Message:         'Calling ''PtrAddr::operator->'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      7633
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      7633
            Length:          3
      - Message:         'Calling ''PtrAddr::operator ds::linked_list::cell::PtrAddr *'''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3540
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3540
            Length:          5
      - Message:         'Calling ''AddressProxy::operator='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3434
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3434
            Length:          17
      - Message:         'Calling ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'void * __capability argument may be a pointer to capability'
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      13396
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      13396
            Length:          6
      - Message:         'Returning from ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'Returning from ''AddressProxy::operator='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3434
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3434
            Length:          17
      - Message:         'Returning from ''PtrAddr::operator ds::linked_list::cell::PtrAddr *'''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3540
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3540
            Length:          5
      - Message:         'Returning from ''PtrAddr::operator->'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      7633
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      7633
            Length:          3
      - Message:         'Calling ''PtrAddr::operator ds::linked_list::cell::PtrAddr *'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      7662
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      7662
            Length:          1
      - Message:         'Calling ''AddressProxy::operator='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3434
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3434
            Length:          17
      - Message:         'Calling ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'void * __capability argument may be a pointer to capability'
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      13396
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      13396
            Length:          6
      - Message:         'Returning from ''PropertyProxyBase::set'''
        FilePath:        'sdk/include/cheri.hh'
        FileOffset:      14291
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/cheri.hh'
            FileOffset:      14291
            Length:          45
      - Message:         'Returning from ''AddressProxy::operator='''
        FilePath:        'sdk/include/ds/pointer.h'
        FileOffset:      3434
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/pointer.h'
            FileOffset:      3434
            Length:          17
      - Message:         'Returning from ''PtrAddr::operator ds::linked_list::cell::PtrAddr *'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      7662
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      7662
            Length:          1
      - Message:         'Returning from ''unsafe_remove<ds::linked_list::cell::PtrAddr>'''
        FilePath:        'sdk/include/ds/linked_list.h'
        FileOffset:      7767
        Replacements:    []
        Ranges:
          - FilePath:        'sdk/include/ds/linked_list.h'
            FileOffset:      7767
            Length:          19
      - Message:         'Returning from ''unsafe_remove<ds::linked_list::cell::PtrAddr>'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      73482
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      73482
            Length:          43
      - Message:         'Calling ''MChunk::metadata_clear'''
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      73530
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      73530
            Length:          22
      - Message:         'Pointer value aligned to a 4 byte boundary cast to type ''uintptr_t * __capability'' with 8-byte capability alignment'
        FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
        FileOffset:      20291
        Replacements:    []
        Ranges:
          - FilePath:        '/workspaces/cheriot-rtos/sdk/core/allocator/alloc.h'
            FileOffset:      20291
            Length:          42
    Level:           Warning
    BuildDirectory:  '/workspaces/cheriot-rtos'
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions