-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang][ptrauth] Warn about the use of a weak signing schema #157779
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
8fe991f
bc4d0a7
1d90050
5be722d
5ff3d60
b623b0e
7abb90c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1046,6 +1046,11 @@ def err_ptrauth_address_discrimination_invalid : Error< | |
| def err_ptrauth_extra_discriminator_invalid : Error< | ||
| "invalid extra discriminator flag '%0'; '__ptrauth' requires a value between " | ||
| "'0' and '%1'">; | ||
| def warn_ptrauth_weak_schema | ||
|
||
| : Warning<"%0 has internal linkage with a %select{|default }1" | ||
| "pointer authentication schema that should be overridden by " | ||
| "%select{a|an explicit}1 schema with unique diversifiers">, | ||
| InGroup<DiagGroup<"ptrauth-weak-schema">>; | ||
|
|
||
| /// main() | ||
| // static main() is not an error in C, just in C++. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8357,6 +8357,16 @@ NamedDecl *Sema::ActOnVariableDeclarator( | |
| D.isFunctionDefinition()); | ||
| } | ||
|
|
||
| // Warn about the use of a weak pointer authentication schema on a variable | ||
|
||
| // with internal linkage. | ||
| if (Context.isPointerAuthenticationAvailable() && | ||
| NewVD->isFunctionPointerType() && !NewVD->isExternallyVisible()) { | ||
| PointerAuthQualifier Q = NewVD->getType().getQualifiers().getPointerAuth(); | ||
| if (!Q || (!Q.isAddressDiscriminated() && Q.getExtraDiscriminator() == 0)) { | ||
| Diag(NewVD->getLocation(), diag::warn_ptrauth_weak_schema) << NewVD << !Q; | ||
| } | ||
| } | ||
|
|
||
| if (NewTemplate) { | ||
| if (NewVD->isInvalidDecl()) | ||
| NewTemplate->setInvalidDecl(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // RUN: %clang_cc1 -triple arm64e-apple-ios -fptrauth-calls -fptrauth-intrinsics -fsyntax-only -Wno-unused-variable -verify %s | ||
| // RUN: %clang_cc1 -triple arm64e-apple-ios -DNO_PTRAUTH -fsyntax-only -Wno-unused-variable -verify=noptrauth %s | ||
|
|
||
| // noptrauth-no-diagnostics | ||
|
|
||
| #include <ptrauth.h> | ||
|
|
||
| #if defined(__PTRAUTH__) == defined(NO_PTRAUTH) | ||
| #error expected pointer authentication state does not match actual | ||
| #endif | ||
|
|
||
| #if defined(NO_PTRAUTH) | ||
| #define FN_PTR_AUTH(address_diversity, constant_discriminator) | ||
| #else | ||
| #define FN_PTR_AUTH(address_diversity, constant_discriminator) \ | ||
| __ptrauth(ptrauth_key_function_pointer, address_diversity, constant_discriminator) | ||
| #endif | ||
|
|
||
| // Global variables with external linkage and weak pointer authentication should | ||
| // not raise any warning. | ||
| extern void(* g1_external_weak)(void); | ||
| void(* FN_PTR_AUTH(0, 0) g2_external_weak)(void); | ||
|
|
||
| // Global variables with internal linkage and strong pointer authentication | ||
| // should not raise any warning. | ||
| static void(* FN_PTR_AUTH(1, 65535) g1_internal_strong)(void); | ||
| static void(* FN_PTR_AUTH(0, 65535) g2_internal_strong)(void); | ||
| static void(* FN_PTR_AUTH(1, 0) g3_internal_strong)(void); | ||
|
|
||
| #if !defined(NO_PTRAUTH) | ||
| // Global variables with internal linkage and weak pointer authentication should | ||
| // raise a warning. | ||
| static void(* g1_internal_weak)(void); | ||
| // expected-warning@-1 {{'g1_internal_weak' has internal linkage with a default pointer authentication schema that should be overridden by an explicit schema with unique diversifiers}} | ||
| static void(* FN_PTR_AUTH(0, 0) g2_internal_weak)(void); | ||
| // expected-warning@-1 {{'g2_internal_weak' has internal linkage with a pointer authentication schema that should be overridden by a schema with unique diversifiers}} | ||
|
|
||
| // Assert that -Wptrauth-weak-schema silences warnings. | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wptrauth-weak-schema" | ||
| static void(* g3_internal_weak)(void); | ||
| #pragma clang diagnostic pop | ||
| #endif | ||
|
|
||
| void test_local_variables(void) { | ||
| #if !defined(NO_PTRAUTH) | ||
|
||
| // Local variables (internal linkage) with weak pointer authentication | ||
| // should raise a warning. | ||
| static void(* l1_internal_weak)(void); | ||
| // expected-warning@-1 {{'l1_internal_weak' has internal linkage with a default pointer authentication schema that should be overridden by an explicit schema with unique diversifiers}} | ||
| static void(* FN_PTR_AUTH(0, 0) l2_internal_weak)(void); | ||
| // expected-warning@-1 {{'l2_internal_weak' has internal linkage with a pointer authentication schema that should be overridden by a schema with unique diversifiers}} | ||
| #endif | ||
|
|
||
| // Local variables (internal linkage) with strong pointer authentication | ||
| // should not raise any warning. | ||
| void(* FN_PTR_AUTH(1, 65535) l1_internal_strong)(void); | ||
|
||
| void(* FN_PTR_AUTH(0, 65535) l2_internal_strong)(void); | ||
| void(* FN_PTR_AUTH(1, 0) l3_internal_strong)(void); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍