Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto trait leakage can be used to leak arbitrary types #13

Open
lcnr opened this issue Dec 20, 2024 · 0 comments
Open

auto trait leakage can be used to leak arbitrary types #13

lcnr opened this issue Dec 20, 2024 · 0 comments

Comments

@lcnr
Copy link
Owner

lcnr commented Dec 20, 2024

Using auto trait leakage, it's possible to fully leak opaque types outside of their defining scope

struct RequiresEq<T, U>(T, U);
unsafe impl<T: Send> Send for RequiresEq<T, T> {}

trait GetRhs<T> {
    fn get_rhs(self) -> T;
}
impl<T, U> GetRhs<U> for RequiresEq<T, U> {
    fn get_rhs(self) -> U {
        self.1
    }
}

fn define<T, U: Default>() -> impl GetRhs<U> {
    RequiresEq(1u32, Default::default())
}

fn req_send<T: Send>(x: T) -> T { x }

fn main() {
    let opaque = define::<(), _>();
    // Leak through an opaque type.
    let _hidden_ty: u32 = req_send(opaque).get_rhs();
}
#![feature(type_alias_impl_trait)]
#![allow(unused)]
#![crate_type = "rlib"]

fn require_auto<T: Unpin>(x: T) -> T { x }
struct WaddupGamers<T, U>(Option<T>, U);
impl<T: Leak<Assoc = U>, U> Unpin for WaddupGamers<T, U> {}
trait Leak {
    type Assoc;
}
impl<T> Leak for T {
    type Assoc = T;
}
fn define<T>() -> impl Sized {
    WaddupGamers(None::<T>, || ())
}

type NameMe<T> = impl Sized;
fn leak<T>() -> NameMe<T>
where 
    T: Leak<Assoc = NameMe<T>>,
{
    let opaque = require_auto(define::<T>());
    let closure;
    loop {}
    return closure;
    closure();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant