Skip to content

JIT: Add IBT support #8774

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

Merged
merged 1 commit into from
Jun 28, 2022
Merged

JIT: Add IBT support #8774

merged 1 commit into from
Jun 28, 2022

Conversation

chen-hu-97
Copy link
Contributor

Indirect Branch Tracking (IBT) is part of Intel's Control-Flow
Enforcement Technology (CET). IBT is hardware based, forward edge
Control-Flow-Integrity mechanism where any indirect CALL/JMP must target
an ENDBR instruction or suffer #CP.

This commit adds IBT support for JIT:

  1. Add endbr32/64 instruction in Dynasm.
  2. Insert endbr32/64 in indirect branch target for jitted code.

gcc support CET since v8.1 and set it to default since gcc 11. With this
commit, endbr is inserted in jitted code if PHP is compiled with "gcc
-fcf-protection=full/branch".

Signed-off-by: Chen, Hu hu1.chen@intel.com

@chen-hu-97 chen-hu-97 changed the title JIT: Add IBT support (#8636) JIT: Add IBT support Jun 14, 2022
@chen-hu-97
Copy link
Contributor Author

Hi @iluuu1994 @dstogov,
Tovilo found test failure in #8636 if PHP is compiled with -fsanitize=address. This reveals an issue: if we insert any instructions in zend_jit_prologue (especially before sub $0x10,%rsp), we need change the prologue_size in zend_jit_trace_link_to_root. Otherwise, it will jump to wrong address when trace_exit.

Let's see if this PR can pass such test. (it passed in my personal repo thanks for Tovilo's tips)

@dstogov
Copy link
Member

dstogov commented Jun 14, 2022

Hi @iluuu1994 @dstogov, Tovilo found test failure in #8636 if PHP is compiled with -fsanitize=address. This reveals an issue: if we insert any instructions in zend_jit_prologue (especially before sub $0x10,%rsp), we need change the prologue_size in zend_jit_trace_link_to_root. Otherwise, it will jump to wrong address when trace_exit.

Let's see if this PR can pass such test. (it passed in my personal repo thanks for Tovilo's tips)

This looks right.

Indirect Branch Tracking (IBT) is part of Intel's Control-Flow
Enforcement Technology (CET). IBT is hardware based, forward edge
Control-Flow-Integrity mechanism where any indirect CALL/JMP must target
an ENDBR instruction or suffer #CP.

This commit adds IBT support for JIT:
1. Add endbr32/64 instruction in Dynasm.
2. Insert endbr32/64 in indirect branch target for jitted code.

gcc support CET since v8.1 and set it to default since gcc 11. With this
commit, endbr is inserted in jitted code if PHP is compiled with "gcc
-fcf-protection=full/branch".

Signed-off-by: Chen, Hu <hu1.chen@intel.com>
@chen-hu-97
Copy link
Contributor Author

Saw AppVeyor failures in yesterday's push. @cmb69 said it's already fixed in another commit.
Trigger other check and it pass now.

@dstogov dstogov merged commit d8de067 into php:master Jun 28, 2022
PeterYang12 added a commit to PeterYang12/php-src that referenced this pull request Feb 13, 2023
PR php#8774 added IBT support for jitted code and passed all built-in tests in
"ext/opcache/tests/jit". However, we found several "missing ENDBR" issues
recently when running some real world workloads.

Such workloads introduce new code path and thus more "indirect branch target"
are in jited code. This fix adds missing endbr correspondingly.

Signed-off-by: PeterYang12 <yuhan.yang@intel.com>
Reviewed-by:   chen-hu-97  <hu1.chen@intel.com>
Reviewed-by:   bjzhjing    <cathy.zhang@intel.com>
PeterYang12 added a commit to PeterYang12/php-src that referenced this pull request Feb 13, 2023
PR php#8774 added IBT support for jitted code and passed all built-in tests in
"ext/opcache/tests/jit". However, we found several "missing ENDBR" issues
recently when running some real world workloads.

Such workloads introduce new code path and thus more "indirect branch target"
are in jited code. This fix adds missing endbr correspondingly.

Signed-off-by: PeterYang12 <yuhan.yang@intel.com>
Reviewed-by:   chen-hu-97  <hu1.chen@intel.com>
Reviewed-by:   bjzhjing    <cathy.zhang@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants