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

Add proper CET support #1290

Closed
wants to merge 1 commit into from
Closed

Add proper CET support #1290

wants to merge 1 commit into from

Conversation

siddhesh
Copy link
Contributor

Use cet.h if available and use _CET_ENDBR to make all the functions IBT-safe. This is not directly testable yet, but the instruction is in the nop space for processors that don't support it, so it's a harmless addition.

cet.h also includes the SHSTK and IBT GNU properties in ELF, so remove the manually added ones.


Sorry, I missed this in my previous patch because there's no Linux kernel support for IBT yet. This is a more complete fix to making libsodium properly CET-enabled.

@jedisct1
Copy link
Owner

Thanks!

I think we don't need a specific header for that; it could fit into private/common.h.

Do functions from fe51_mul et al need to have this as well? Considering the fact that they are called only from assembly code?

The previous PR only added IBT prologues to entry points. Shouldn't that be enough?

@jedisct1
Copy link
Owner

fatal error: 'cet.h' file not found

CI doesn't like it. We can have clang >= 11 without that header.

@jedisct1
Copy link
Owner

And OpenBSD has support for IBT, has <cet.h>, but not. _CET_ENDBR:

test.c:5:5: error: use of undeclared identifier '_CET_ENDBR'
    _CET_ENDBR;
    ^
1 error generated.

@jedisct1
Copy link
Owner

Well, OpenBSD does, but only when __CET__ is defined. The PR should check for __CET__ definition, or else it breaks compilation when -fcf-protection is not used.

@jedisct1
Copy link
Owner

Actually, <cet.h> has:

#ifdef __ASSEMBLER__

#ifndef __CET__
# define _CET_ENDBR
#endif

So, could the reason it is failing on OpenBSD be that __ASSEMBLER__ is not defined?

@jedisct1
Copy link
Owner

... or just that I was dumb and didn't use it in a .S file :)

jedisct1 added a commit that referenced this pull request Jul 19, 2023
jedisct1 added a commit that referenced this pull request Jul 19, 2023
@siddhesh
Copy link
Contributor Author

Thanks!

I think we don't need a specific header for that; it could fit into private/common.h.

Ack, I'll fix this.

Do functions from fe51_mul et al need to have this as well? Considering the fact that they are called only from assembly code?

Since it's internal-only, it's not strictly needed right now, but I added it in as a precaution in case there's ever an indirect call in future.

The previous PR only added IBT prologues to entry points. Shouldn't that be enough?

The previous PR added property notes, no IBT prologues, or maybe I misunderstand your comment?

Use cet.h if available and use _CET_ENDBR to make all the functions
IBT-safe.  This is not directly testable yet, but the instruction is in
the nop space for processors that don't support it, so it's a harmless
addition.

cet.h also includes the SHSTK and IBT GNU properties in ELF, so remove
the manually added ones.
@jedisct1
Copy link
Owner

Actually zig cc does ship with cet.h, and it perfectly works in C files (where it's useless). But the path to clang headers is not set when compiling .S files.

The joy of compiler diversity :)

@siddhesh
Copy link
Contributor Author

OK, if this is too painful across compilers then maybe it makes sense to just drop it, especially if these functions are always going to be internal-only and will likely never be called through an indirect branch. The property notes I had added in the earlier PR are sufficient to get support working.

@jedisct1
Copy link
Owner

Yes, these functions are always going to be internal, and the symbols are all private.

CET is not a Linux-only thing. It's already enforced everywhere by default in OpenBSD.

Is what you previously sent guaranteed to be compatible with all operating systems and linkers? Sorry, I'm not too familiar with this, and don't fully understand where these values come from. Is this also compatible both with _LP32 and _LP64?

@jedisct1
Copy link
Owner

Including <cet.h> still seems like the safest way to go.

I think we should just check for its existence, that is actually contains _CET_ENDBR in case of name collision, and verify that everything's fine on a bunch of compilers.

@siddhesh
Copy link
Contributor Author

Including <cet.h> still seems like the safest way to go.

I think we should just check for its existence, that is actually contains _CET_ENDBR in case of name collision, and verify that everything's fine on a bunch of compilers.

Agreed, I tested #1291 and it works well. Closing this one, thanks!

@siddhesh siddhesh closed this Jul 19, 2023
Repository owner locked and limited conversation to collaborators Oct 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants