Skip to content

[strict provenance] add lints for evil pointer casts #95488

Closed
@Gankra

Description

@Gankra

This issue is part of the Strict Provenance Experiment - #95228

We should make it easier for people to detect places where they are using casts instead of the "blessed" strict_provenance APIs.

@eddyb and I prototyped this out here: 93f7f06

The patch needs some cleanups, though. Quoting from elsewhere:


All lints should be made allow by default, meaning they're opt-in.

At least in the bootstrap, the compiler will complain if you allow() a lint in your code that doesn't exist. This potentially just means:

  • We need to keep the experimental lint around forever even when the experiment is over
  • Users can only "safely" invoke it from the command line manually, which is slightly unfortunate for anything like what I did where I used it as a FIXME/WONTFIX marker for the file.

Also due to the "Opaque Function Pointers" / "Harvard Architecture" / "AVR is cursed" issue

// HACK: The intermediate cast as usize is required for AVR
// so that the address space of the source function pointer
// is preserved in the final function pointer.
//
// https://github.com/avr-rust/rust/issues/143
fmt::Pointer::fmt(&(*self as usize as *const ()), f)

I think we want the lint broken up into parts:

  • #[fuzzy_provenance_casts] - int-to-ptr, totally evil
  • #[lossy_provencance_casts] - ptr-to-int, sketchy but valid as long as you actually want .addr() semantics
  • #[oxford_casts] - casts that make harvard architectures sad -- fn<->ptr (name is a joke... unless...)

I can't justify discouraging fn <-> int, absent better ways to talk about fn ptrs properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-strict-provenanceArea: Strict provenance for raw pointersC-future-incompatibilityCategory: Future-incompatibility lints

    Type

    No type

    Projects

    Status

    Idea

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions