-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[Clang][attr] Add 'cfi_salt' attribute #141846
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
Changes from 10 commits
bfdf16c
04d2c0b
94d10c5
bbce666
e36bc7c
b0c8a2e
9e164e5
eef5f43
46d0edd
f4a54d9
e9aaaf5
0b13d3a
cec156a
44950cc
514523b
f74c5ea
527297f
2df94a9
66cb83b
516aa05
1b1d3ab
6d00a7e
2e9022d
7f2de1c
44c179d
029ee8e
06e43bd
132995f
cd975ea
abe3bde
c2dba02
95698c2
09a446a
ae91164
9bd2c95
9700cac
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 |
---|---|---|
|
@@ -3643,6 +3643,64 @@ make the function's CFI jump table canonical. See :ref:`the CFI documentation | |
}]; | ||
} | ||
|
||
def KCFISaltDocs : Documentation { | ||
let Category = DocCatFunction; | ||
let Content = [{ | ||
bwendling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Use ``__attribute__((kcfi_salt("<salt>")))`` on a function declaration, function | ||
definition, or typedef to help distinguish CFI hashes between functions with | ||
the same type signature. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like in the kernel patch, it would be nice to summarize the use case, i.e. in what cases we would want to apply this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some of Sami's examples to the docs. Let me know what you think. |
||
|
||
Example use: | ||
|
||
.. code-block:: c | ||
|
||
// .h file: | ||
#define __kcfi_salt __attribute__((kcfi_salt("vogon"))) | ||
|
||
// Convenient typedefs to avoid nested declarator syntax. | ||
typedef int (*fptr_t)(void); // Non-salted function call. | ||
typedef int (*fptr_salted_t)(void) __kcfi_salt; | ||
|
||
struct widget_generator { | ||
fptr_t init; | ||
fptr_salted_t exec; | ||
fptr_t teardown; | ||
}; | ||
|
||
// 1st .c file: | ||
static int internal_init(void) { /* ... */ } | ||
static int internal_salted_exec(void) __kcfi_salt { /* ... */ } | ||
static int internal_teardown(void) { /* ... */ } | ||
|
||
static struct widget_generator _generator = { | ||
.init = internal_init, | ||
.exec = internal_salted_exec, | ||
.teardown = internal_teardown, | ||
} | ||
bwendling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
struct widget_generator *widget_gen = _generator; | ||
bwendling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 2nd .c file: | ||
int generate_a_widget(void) { | ||
int ret; | ||
|
||
// Called with non-salted CFI. | ||
ret = widget_gen.init(); | ||
if (ret) | ||
return ret; | ||
|
||
// Called with salted CFI. | ||
ret = widget_gen.exec(); | ||
if (ret) | ||
return ret; | ||
|
||
// Called with non-salted CFI. | ||
return widget_gen.teardown(); | ||
} | ||
|
||
}]; | ||
} | ||
|
||
def DocCatTypeSafety : DocumentationCategory<"Type Safety Checking"> { | ||
let Content = [{ | ||
Clang supports additional attributes to enable checking type safety properties | ||
|
Uh oh!
There was an error while loading. Please reload this page.