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

Casts should be excluded from checked region? #480

Open
Arslan8 opened this issue Mar 18, 2022 · 2 comments
Open

Casts should be excluded from checked region? #480

Arslan8 opened this issue Mar 18, 2022 · 2 comments

Comments

@Arslan8
Copy link

Arslan8 commented Mar 18, 2022

Hi,
I have the following code:

typedef struct {
        ptr<int> a;
        ptr<int> b;
} STRUCT;

void break(void) {
    char temp checked[1000];
    ptr<STRUCT> s  = NULL;
    s  = dynamic_bounds_cast<ptr<STRUCT>> (&temp[20]);
    int a;
    s->a = (ptr<int>)&a;
    temp[20] = 0xAB;
    temp[21] = 0xCD;
    temp[22] = 0xEF;
}

As you can figure that *s->a can be used to access any memory in the system breaking spatial memory safety. Moreover, this entire code can be written in a checked scope, prompting whether we should exclude casts from checked regions?
Thanks,
Arslan

@mwhicks1
Copy link
Collaborator

I'm not sure why the dynamic bounds cast to ptr<STRUCT> is allowed. We can tell that ptr<STRUCT> and ptr<char> (the type of &temp[20]) are not compatible. If it fails at run-time, then this code is fine, but I don't see why it shouldn't fail at compile-time.

@Arslan8
Copy link
Author

Arslan8 commented Mar 18, 2022

@mwhicks1 I agree with you, the cast should fail at compile-time... however, just to add on this, the code doesn't fail on run-time as well even after I add the line before returning from the function:
*(s->a) = 100;

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

2 participants