Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hwasan] Fix kernel instrumentation of stack.
Summary: Kernel addresses have 0xFF in the most significant byte. A tag can not be pushed there with OR (tag << 56); use AND ((tag << 56) | 0x00FF..FF) instead. Reviewers: kcc, andreyknvl Subscribers: srhines, llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D42941 llvm-svn: 324691
- Loading branch information
Showing
2 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
llvm/test/Instrumentation/HWAddressSanitizer/kernel-alloca.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
; Test basic address sanitizer instrumentation. | ||
; | ||
; RUN: opt < %s -hwasan -hwasan-kernel=1 -S | FileCheck %s | ||
|
||
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" | ||
target triple = "aarch64--linux-android" | ||
|
||
declare void @use32(i32*) | ||
|
||
define void @test_alloca() sanitize_hwaddress { | ||
; CHECK-LABEL: @test_alloca( | ||
; CHECK: %[[FP:[^ ]*]] = call i8* @llvm.frameaddress(i32 0) | ||
; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %[[FP]] to i64 | ||
; CHECK: %[[B:[^ ]*]] = lshr i64 %[[A]], 20 | ||
; CHECK: %[[BASE_TAG:[^ ]*]] = xor i64 %[[A]], %[[B]] | ||
|
||
; CHECK: %[[X:[^ ]*]] = alloca i32, align 16 | ||
; CHECK: %[[X_TAG:[^ ]*]] = xor i64 %[[BASE_TAG]], 0 | ||
; CHECK: %[[X1:[^ ]*]] = ptrtoint i32* %[[X]] to i64 | ||
; CHECK: %[[C:[^ ]*]] = shl i64 %[[X_TAG]], 56 | ||
; CHECK: %[[D:[^ ]*]] = or i64 %[[C]], 72057594037927935 | ||
; CHECK: %[[E:[^ ]*]] = and i64 %[[X1]], %[[D]] | ||
; CHECK: %[[X_HWASAN:[^ ]*]] = inttoptr i64 %[[E]] to i32* | ||
|
||
entry: | ||
%x = alloca i32, align 4 | ||
call void @use32(i32* nonnull %x) | ||
ret void | ||
} |