Skip to content

Add option to allow exploiting intprcast alignment #1074

Closed
@Aaron1011

Description

@Aaron1011

Currently, we have a test that asserts that code is not allowed to rely on any 'extra' information provided by the intprcast (e.g. a [u16; 2] array that happens to have alignment '4').

However, this is a perfectly legitimate thing for code to do. I propose that we add a intprcast-alignment option which enables the following behavior:

When we check the alignment for a memory access, we see if we have a recorded base address for the allocation (i.e. if a pointer within the allocation was ever cast to an integer).

If we do not have a base address, we use the current alignment checking behavior (i.e. check the static alignment of the type). This will catch cases where the code is definitely wrong - if the pointer was never cast to an integer, the code cannot possibly know that it happened to have 'extra' alignment.

If we do have a base address, then we do the alignment check based on the actual base address. This will allow some incorrect code, like:

let mut my_arr: [u8; 100]`
my_arr.as_ptr() as usuze; // Dummy cast
unsafe { *(my_arr.as_mut_ptr() as *mut u16) = 25 }

Depending on what alignment we pick for the base address of my_addr, this may or may not work. This means that whether or not this program passes now depends on the random seed.

While this isn't ideal, I don't see a way of allowing the intptrcast_alignment_check to pass without also causing 'spurious passes' (code which really should fail, but doesn't).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intptrcastArea: affects int2ptr and ptr2int castsC-enhancementCategory: a PR with an enhancement or an issue tracking an accepted enhancementI-false-UBImpact: makes Miri falsely report UB, i.e., a false positive (with default settings)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions