This is an archive of the discontinued LLVM Phabricator instance.

[HWASAN] Update the tag info for X86_64
Needs ReviewPublic

Authored by xiangzhangllvm on May 14 2021, 1:05 AM.

Details

Summary

In LAM model X86_64 will use bits 57-62 (of 0-63) as HWASAN tag.
So here we make sure the tag shift position and tag mask is correct for x86-64.

And support the HWASAN for setjmp longjmp in compiler-rt

Diff Detail

Event Timeline

xiangzhangllvm created this revision.May 14 2021, 1:05 AM
xiangzhangllvm requested review of this revision.May 14 2021, 1:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 14 2021, 1:05 AM
xiangzhangllvm added inline comments.May 14 2021, 1:49 AM
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
188

I add back untag point, (disable it in default), it is useful to test some simple test with HWASAN.

Update clang-format

xiangzhangllvm accepted this revision.May 19 2021, 7:34 PM
This revision is now accepted and ready to land.May 19 2021, 7:34 PM
This revision was landed with ongoing or failed builds.May 19 2021, 8:22 PM
This revision was automatically updated to reflect the committed changes.
pcc reopened this revision.May 19 2021, 8:58 PM
pcc added a subscriber: pcc.

It doesn't look like this was reviewed by anyone. Could you revert this please until it gets reviewed?

This revision is now accepted and ready to land.May 19 2021, 8:58 PM
pcc requested changes to this revision.May 19 2021, 8:59 PM
This revision now requires changes to proceed.May 19 2021, 8:59 PM

It doesn't look like this was reviewed by anyone. Could you revert this please until it gets reviewed?

Done,
revert it at 02f2d739e074782ac47531196739a2e003603e62

Could you help review it ?

Hello @eugenis @vitalybuka @morehouse I see you change the related code at compiler-rt, Could you help review this patch? This patch just limited the tag for x86_64.

xiangzhangllvm requested review of this revision.May 19 2021, 10:25 PM
xiangzhangllvm edited the summary of this revision. (Show Details)
xiangzhangllvm added a project: Restricted Project.May 20 2021, 2:58 AM

Hi Xiang, thanks for the patch.

I haven't looked too close yet, but a couple questions:

  1. There seems to be multiple things going on in this patch: adding stack support on x86, adding a (debug?) flag ClUntagPointer, adding x86_64 assembly to the runtime. Could you break this up into smaller separate patches for independent review?
  2. How are you testing the patch? I am currently setting up a QEMU+LAM buildbot for CI, and I would prefer if we waited to land any more LAM stuff until the buildbot is setup to ensure things don't break.

Hello @morehouse, thanks for your work too:
1 OK, I'll break it up into 2 patches, one focus on changes in compiler, the other focus on changes in compiler-rt.

2 In fact, We can divide it into two steps, Step 1 is "Tag correctness checking", Step 2 is "Hardware supporting point with tag".

 The option "ClUntagPointer" can help us first testing the Step 1.
 For example: we write 7 in to int *p, for HWASAN, we do 2 things:
 Step1:   Checking tag of p :
              call void @__hwasan_store4 (p_tagged)     // Checking tag is correct or not
 Step2:   Write 7 into mem:
              *p_tagged = 7          // Need Hardware supporting.  But if we use "ClUntagPointer" change "*p_tagged = 7" --> "*p = 7", we can run the program, and test Step 1 for HWASAN.

For HWASAN, Most code in compiler and compiler-rt is doing work for Step 1. So we can use "ClUntagPointer" first test it.
After we make sure Step 1 is OK, when the Hardware/OS is ready, we just need to totally/really enable HWASAN by just, I think, updating the system call in InitPrctl.

Hello, @morehouse, I first spilt the change of compiler to https://reviews.llvm.org/D102901
I'll update this link after that small patch in.

2 In fact, We can divide it into two steps, Step 1 is "Tag correctness checking", Step 2 is "Hardware supporting point with tag".

 The option "ClUntagPointer" can help us first testing the Step 1.
 For example: we write 7 in to int *p, for HWASAN, we do 2 things:
 Step1:   Checking tag of p :
              call void @__hwasan_store4 (p_tagged)     // Checking tag is correct or not
 Step2:   Write 7 into mem:
              *p_tagged = 7          // Need Hardware supporting.  But if we use "ClUntagPointer" change "*p_tagged = 7" --> "*p = 7", we can run the program, and test Step 1 for HWASAN.

For HWASAN, Most code in compiler and compiler-rt is doing work for Step 1. So we can use "ClUntagPointer" first test it.
After we make sure Step 1 is OK, when the Hardware/OS is ready, we just need to totally/really enable HWASAN by just, I think, updating the system call in InitPrctl.

I recently removed a bunch of untagging stuff from our tests, and I'd like to avoid adding it back. This is why I'm working on a buildbot to run tests in QEMU with LAM enabled.

I've also been testing locally with LAM in QEMU.

vitalybuka resigned from this revision.Jul 8 2021, 4:18 PM

Hello @morehouse , I saw the change of compiler for X86 ( https://reviews.llvm.org/D102901 ) has been merged.
Do you have plan to support the Set/longjmp on compiler-rt for X86 (the rest of current patch did) ?

Hello @morehouse , I saw the change of compiler for X86 ( https://reviews.llvm.org/D102901 ) has been merged.
Do you have plan to support the Set/longjmp on compiler-rt for X86 (the rest of current patch did) ?

Eventually. The existing tests at the time passed without it, so I haven't done anything with this patch.

Eventually. The existing tests at the time passed without it, so I haven't done anything with this patch.

Does the "existing tests" just means LIT tests about HWASAN in compiler-rt ? thanks.