[clang][Obj-C][PAC] Make block descriptor pointer signing configurable (#153700)
Pointer auth protection of the block descriptor pointer is only supported in some constrained environments so we do actually need it to be configurable. We had made it non configurable in the first PR to protect block metadata because we believed that was an option but subsequently realised it does need to remain configurable. This PR revives the flags that permit this.
This commit is contained in:
parent
7575bda7e1
commit
ad7bb1cc45
@ -157,7 +157,7 @@ FEATURE(ptrauth_vtable_pointer_address_discrimination, LangOpts.PointerAuthVTPtr
|
||||
FEATURE(ptrauth_vtable_pointer_type_discrimination, LangOpts.PointerAuthVTPtrTypeDiscrimination)
|
||||
FEATURE(ptrauth_type_info_vtable_pointer_discrimination, LangOpts.PointerAuthTypeInfoVTPtrDiscrimination)
|
||||
FEATURE(ptrauth_member_function_pointer_type_discrimination, LangOpts.PointerAuthCalls)
|
||||
FEATURE(ptrauth_signed_block_descriptors, LangOpts.PointerAuthCalls)
|
||||
FEATURE(ptrauth_signed_block_descriptors, LangOpts.PointerAuthBlockDescriptorPointers)
|
||||
FEATURE(ptrauth_function_pointer_type_discrimination, LangOpts.PointerAuthFunctionTypeDiscrimination)
|
||||
FEATURE(ptrauth_indirect_gotos, LangOpts.PointerAuthIndirectGotos)
|
||||
FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
|
||||
|
@ -138,6 +138,8 @@ LANGOPT(PointerAuthObjcInterfaceSel, 1, 0, NotCompatible, "authentication of SEL
|
||||
LANGOPT(PointerAuthObjcInterfaceSelKey, 16, 0, NotCompatible, "authentication key for SEL fields of ObjC interfaces")
|
||||
LANGOPT(PointerAuthObjcClassROPointers, 1, 0, Benign, "class_ro_t pointer authentication")
|
||||
|
||||
LANGOPT(PointerAuthBlockDescriptorPointers, 1, 0, NotCompatible, "enable signed block descriptors")
|
||||
|
||||
LANGOPT(DoubleSquareBracketAttributes, 1, 0, NotCompatible, "'[[]]' attributes extension for all language standard modes")
|
||||
LANGOPT(ExperimentalLateParseAttributes, 1, 0, NotCompatible, "experimental late parsing of attributes")
|
||||
|
||||
|
@ -4527,6 +4527,7 @@ defm aarch64_jump_table_hardening: OptInCC1FFlag<"aarch64-jump-table-hardening",
|
||||
defm ptrauth_objc_isa : OptInCC1FFlag<"ptrauth-objc-isa", "Enable signing and authentication of Objective-C object's 'isa' field">;
|
||||
defm ptrauth_objc_interface_sel : OptInCC1FFlag<"ptrauth-objc-interface-sel", "Enable signing and authentication of Objective-C object's 'SEL' fields">;
|
||||
defm ptrauth_objc_class_ro : OptInCC1FFlag<"ptrauth-objc-class-ro", "Enable signing and authentication for ObjC class_ro pointers">;
|
||||
defm ptrauth_block_descriptor_pointers : OptInCC1FFlag<"ptrauth-block-descriptor-pointers", "Enable signing and authentication of block descriptors">;
|
||||
}
|
||||
|
||||
def fenable_matrix : Flag<["-"], "fenable-matrix">, Group<f_Group>,
|
||||
|
@ -1548,9 +1548,10 @@ void CompilerInvocation::setDefaultPointerAuthOptions(
|
||||
PointerAuthSchema(Key::ASIA, true, Discrimination::None);
|
||||
Opts.BlockByrefHelperFunctionPointers =
|
||||
PointerAuthSchema(Key::ASIA, true, Discrimination::None);
|
||||
Opts.BlockDescriptorPointers =
|
||||
PointerAuthSchema(Key::ASDA, true, Discrimination::Constant,
|
||||
BlockDescriptorConstantDiscriminator);
|
||||
if (LangOpts.PointerAuthBlockDescriptorPointers)
|
||||
Opts.BlockDescriptorPointers =
|
||||
PointerAuthSchema(Key::ASDA, true, Discrimination::Constant,
|
||||
BlockDescriptorConstantDiscriminator);
|
||||
|
||||
Opts.ObjCMethodListFunctionPointers =
|
||||
PointerAuthSchema(Key::ASIA, true, Discrimination::None);
|
||||
@ -3608,6 +3609,8 @@ static void GeneratePointerAuthArgs(const LangOptions &Opts,
|
||||
GenerateArg(Consumer, OPT_fptrauth_objc_interface_sel);
|
||||
if (Opts.PointerAuthObjcClassROPointers)
|
||||
GenerateArg(Consumer, OPT_fptrauth_objc_class_ro);
|
||||
if (Opts.PointerAuthBlockDescriptorPointers)
|
||||
GenerateArg(Consumer, OPT_fptrauth_block_descriptor_pointers);
|
||||
}
|
||||
|
||||
static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
|
||||
@ -3631,6 +3634,8 @@ static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
|
||||
Opts.PointerAuthELFGOT = Args.hasArg(OPT_fptrauth_elf_got);
|
||||
Opts.AArch64JumpTableHardening =
|
||||
Args.hasArg(OPT_faarch64_jump_table_hardening);
|
||||
Opts.PointerAuthBlockDescriptorPointers =
|
||||
Args.hasArg(OPT_fptrauth_block_descriptor_pointers);
|
||||
Opts.PointerAuthObjcIsa = Args.hasArg(OPT_fptrauth_objc_isa);
|
||||
Opts.PointerAuthObjcClassROPointers = Args.hasArg(OPT_fptrauth_objc_class_ro);
|
||||
Opts.PointerAuthObjcInterfaceSel =
|
||||
|
@ -1,6 +1,11 @@
|
||||
// RUN: %clang_cc1 -fobjc-arc -fblocks -fptrauth-calls -triple arm64e-apple-ios -emit-llvm -o - %s | FileCheck %s
|
||||
// RUN: %clang_cc1 -fobjc-arc -fblocks -fptrauth-calls -fptrauth-block-descriptor-pointers -triple arm64e-apple-ios -emit-llvm -o - %s | FileCheck %s
|
||||
// RUN: %clang_cc1 -fobjc-arc -fblocks -fptrauth-calls -triple arm64e-apple-ios -DNO_BLOCK_DESC_AUTH -emit-llvm -o - %s | FileCheck %s --check-prefix=NODESCRIPTORAUTH
|
||||
|
||||
#ifndef NO_BLOCK_DESC_AUTH
|
||||
_Static_assert(__has_feature(ptrauth_signed_block_descriptors), "-fptrauth-block-descriptor-pointers should set ptrauth_signed_block_descriptors");
|
||||
#else
|
||||
_Static_assert(!__has_feature(ptrauth_signed_block_descriptors), "-fptrauth-block-descriptor-pointers should not be enabled by default");
|
||||
#endif
|
||||
|
||||
void a() {
|
||||
// Test out a global block.
|
||||
@ -8,9 +13,11 @@ void a() {
|
||||
}
|
||||
|
||||
// CHECK: [[BLOCK_DESCRIPTOR_NAME:@"__block_descriptor_.*"]] = linkonce_odr hidden unnamed_addr constant { i64, i64, ptr, ptr } { i64 0, i64 32, ptr @.str, ptr null }
|
||||
// CHECK: @__block_literal_global = internal constant { ptr, i32, i32, ptr, ptr } { ptr @_NSConcreteGlobalBlock, i32 1342177280, i32 0, ptr ptrauth (ptr @__a_block_invoke, i32 0, i64 0, ptr getelementptr inbounds ({ ptr, i32, i32, ptr, ptr }, ptr @__block_literal_global, i32 0, i32 3)), ptr ptrauth (ptr [[BLOCK_DESCRIPTOR_NAME]], i32 2, i64 49339, ptr getelementptr inbounds ({ ptr, i32, i32, ptr, ptr }, ptr @__block_literal_global, i32 0, i32 4)) }
|
||||
|
||||
// NODESCRIPTORAUTH: [[BLOCK_DESCRIPTOR_NAME:@"__block_descriptor_.*"]] = linkonce_odr hidden unnamed_addr constant { i64, i64, ptr, ptr } { i64 0, i64 32, ptr @.str, ptr null }
|
||||
// NODESCRIPTORAUTH: @__block_literal_global = internal constant { ptr, i32, i32, ptr, ptr } { ptr @_NSConcreteGlobalBlock, i32 1342177280, i32 0, ptr ptrauth (ptr @__a_block_invoke, i32 0, i64 0, ptr getelementptr inbounds ({ ptr, i32, i32, ptr, ptr }, ptr @__block_literal_global, i32 0, i32 3)), ptr [[BLOCK_DESCRIPTOR_NAME]] }
|
||||
|
||||
// CHECK: @__block_literal_global = internal constant { ptr, i32, i32, ptr, ptr } { ptr @_NSConcreteGlobalBlock, i32 1342177280, i32 0, ptr ptrauth (ptr @__a_block_invoke, i32 0, i64 0, ptr getelementptr inbounds ({ ptr, i32, i32, ptr, ptr }, ptr @__block_literal_global, i32 0, i32 3)), ptr ptrauth (ptr @"__block_descriptor_32_e5_v8\01?0l", i32 2, i64 49339, ptr getelementptr inbounds ({ ptr, i32, i32, ptr, ptr }, ptr @__block_literal_global, i32 0, i32 4)) }
|
||||
|
||||
void b(int p) {
|
||||
// CHECK-LABEL: define void @b
|
||||
@ -25,4 +32,8 @@ void b(int p) {
|
||||
// CHECK: [[SIGNED_REF:%.*]] = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr @"__block_descriptor_36_e5_v8\01?0l" to i64), i32 2, i64 [[BLENDED]])
|
||||
// CHECK: [[SIGNED_REF_PTR:%.*]] = inttoptr i64 [[SIGNED_REF]] to ptr
|
||||
// CHECK: store ptr [[SIGNED_REF_PTR]], ptr [[BLOCK_DESCRIPTOR_REF]]
|
||||
|
||||
// NODESCRIPTORAUTH: [[BLOCK:%.*]] = alloca <{ ptr, i32, i32, ptr, ptr, i32 }>
|
||||
// NODESCRIPTORAUTH: [[BLOCK_DESCRIPTOR_REF:%.*]] = getelementptr inbounds nuw <{ {{.*}} }>, ptr [[BLOCK]], i32 0, i32 4
|
||||
// NODESCRIPTORAUTH: store ptr @"__block_descriptor_36_e5_v8\01?0l", ptr [[BLOCK_DESCRIPTOR_REF]]
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
void (^globalblock)(void) = ^{};
|
||||
// CHECK: [[BLOCK_DESCRIPTOR_NAME:@"__block_descriptor_.*"]] = linkonce_odr hidden unnamed_addr constant { i64, i64, ptr, ptr } { i64 0, i64 32, ptr @.str, ptr null }, comdat, align 8
|
||||
// CHECK: @__block_literal_global = internal constant { ptr, i32, i32, ptr, ptr } { ptr ptrauth (ptr @_NSConcreteGlobalBlock, i32 2, i64 27361, ptr @__block_literal_global), i32 1342177280, i32 0, ptr ptrauth (ptr @globalblock_block_invoke, i32 0, i64 0, ptr getelementptr inbounds ({ ptr, i32, i32, ptr, ptr }, ptr @__block_literal_global, i32 0, i32 3)), ptr ptrauth (ptr [[BLOCK_DESCRIPTOR_NAME]], i32 2, i64 49339, ptr getelementptr inbounds ({ ptr, i32, i32, ptr, ptr }, ptr @__block_literal_global, i32 0, i32 4)) }
|
||||
// CHECK: @__block_literal_global = internal constant { ptr, i32, i32, ptr, ptr } { ptr ptrauth (ptr @_NSConcreteGlobalBlock, i32 2, i64 27361, ptr @__block_literal_global), i32 1342177280, i32 0, ptr ptrauth (ptr @globalblock_block_invoke, i32 0, i64 0, ptr getelementptr inbounds ({ ptr, i32, i32, ptr, ptr }, ptr @__block_literal_global, i32 0, i32 3)), ptr [[BLOCK_DESCRIPTOR_NAME]] }
|
||||
|
||||
@interface A
|
||||
- (int) count;
|
||||
|
Loading…
x
Reference in New Issue
Block a user