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

Compiler attributes for improved security #201

Open
siddhesh opened this issue Jul 11, 2023 · 6 comments
Open

Compiler attributes for improved security #201

siddhesh opened this issue Jul 11, 2023 · 6 comments

Comments

@siddhesh
Copy link
Contributor

A number of compiler attributes (e.g. alloc_size, malloc, access, nonnull) provide additional information to the compiler to allow it to (1) detect potentially undefined behaviour and (2) optimize code. These often end up in the win-win category where the compiler is able to improve performance as well as security. I had documented a couple of them in an article in the past in a narrow scope, but there's scope for a more comprehensive document. There are some caveats to their usage though, so it's likely not a matter of simply listing them.

Would a new document describing these attributes and how OSS developers could use them with best effect be a useful addition to this project?

@david-a-wheeler
Copy link
Contributor

The Linux kernel has set up a set of conventions to prevent buffer overwrites in many circumstances, that might be a useful source.

We currently have a project for compiler options, but that's a different thing.

The issue would be that some people would need to dedicate real time for this. If that can be done, I imagine it could be really helpful.

@siddhesh
Copy link
Contributor Author

I don't want to promise (because this is largely going to be free time work for me and it's summer!) but I can take a stab at it at some point. I just wanted to put this issue out here to (1) get a sense for whether this would be interesting for this WG and (2) remind myself of it later whenever I have some free time to tackle it.

@thomasnyman
Copy link
Contributor

Fully supporting this! A new document seems to be a sensible approach in my opinion, although there's potentially some overlap with the existing guide too, e.g. this recent RFC for Clang proposes a combination of option flag + annotations.

@david-a-wheeler
Copy link
Contributor

@siddhesh - could you take a quick stab at a starting document? I think there's general agreement that this is useful, but probably needs to be a separate document. The big difference, as I understand it, is that this involves changes to the source code itself. Feel free to focus on just C (or just C++); I suspect that it may need to be more specific about the language.

I encourage looking at:

@siddhesh
Copy link
Contributor Author

I can't attend tomorrow's call due to a conflict, but I wanted to share that I've started working on this, here's a preview: siddhesh@fc1dce2

I'll send a PR once I do the due diligence, i.e. figure out minimum compiler versions, etc. and write some detail for each of those attributes with notes on their usage. There may be more attributes to add in there, but that could be done incrementally.

@SecurityCRob
Copy link
Contributor

Has this been addressed by the C/C++ Compiler Hardening options guide? @gkunz @thomasnyman @david-a-wheeler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants