From patchwork Fri Nov 11 15:32:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Ostapenko X-Patchwork-Id: 81851 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1326189qge; Fri, 11 Nov 2016 07:33:22 -0800 (PST) X-Received: by 10.107.182.70 with SMTP id g67mr14673008iof.120.1478878402149; Fri, 11 Nov 2016 07:33:22 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id vu7si8985713pab.213.2016.11.11.07.33.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Nov 2016 07:33:22 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-441117-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-441117-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-441117-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type :references; q=dns; s=default; b=a4AWuYLXP/gZXOsW3RXJCJFc8RYqwu4 GwyqEPHVol9s+8z/FzFKOKjJbxttJ0tEO8TjGaLeebit/73hz7r3QrqmJpbi/kZS dMxSe8npzVNtT9Okr6EVwY9fUaIUis6zJ+mvXfLwQbY1OrRE7ZVn++yXLerY5TCL BmhOhZbdcnnM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type :references; s=default; bh=QVEA86fKw77Qdt2prC7Ndwti6k0=; b=Xmi/x vREPSiSOnNpaqHGVweIU3zKImt1oZ9n09z+ZOveQ4oNLfbCIcdaRdgk/R5APbmWQ AqUnNhNMSvBjf4+wZYatOc/gxdACE5U0R2KBgX1X4hHYKZr30rTaZ8izHLuFgz8K rg6BZA1MK0xWvHkjIMwuu1rCdIdU5yk5W72NfY= Received: (qmail 64273 invoked by alias); 11 Nov 2016 15:33:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 64240 invoked by uid 89); 11 Nov 2016 15:32:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=HContent-type:mixed, integrity, reveal, revisions X-HELO: mailout4.w1.samsung.com Received: from mailout4.w1.samsung.com (HELO mailout4.w1.samsung.com) (210.118.77.14) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Nov 2016 15:32:49 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OGH007VMHULKD30@mailout4.w1.samsung.com> for gcc-patches@gcc.gnu.org; Fri, 11 Nov 2016 15:32:45 +0000 (GMT) Received: from eusmges1.samsung.com (unknown [203.254.199.239]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20161111153244eucas1p1388344e49e1100f8f288c1f4e5d9aa66~GCAmZi_JA0991809918eucas1p16; Fri, 11 Nov 2016 15:32:44 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1.samsung.com (EUCPMTA) with SMTP id 6A.FB.23383.D94E5285; Fri, 11 Nov 2016 15:32:45 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20161111153244eucas1p1b96bd587fa752e080f6908c35f77882e~GCAlxzxLS3071330713eucas1p1Z; Fri, 11 Nov 2016 15:32:44 +0000 (GMT) Received: from eusync2.samsung.com ( [203.254.199.212]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DB.74.10494.F74E5285; Fri, 11 Nov 2016 15:32:15 +0000 (GMT) Received: from [106.109.129.18] by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OGH00CW7HUJ9C50@eusync2.samsung.com>; Fri, 11 Nov 2016 15:32:43 +0000 (GMT) To: GCC Patches Cc: Jakub Jelinek , doko@ubuntu.com From: Maxim Ostapenko Subject: [PATCH][PR sanitizer/78307] Fix missing symbols in libubsan after recent merge. Message-id: <5825E49B.10701@samsung.com> Date: Fri, 11 Nov 2016 18:32:43 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-version: 1.0 Content-type: multipart/mixed; boundary=------------060704080902050906010109 X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161111153244eucas1p1b96bd587fa752e080f6908c35f77882e X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?TWFrc2ltIE9zdGFwZW5rbxtTUlItU1cgVG9vbHMgTGFiGw==?= =?UTF-8?B?7IK87ISx7KCE7J6QG0VuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?TWF4aW0gT3N0YXBlbmtvG1NSUi1TVyBUb29scyBMYWIbU2Ft?= =?UTF-8?B?c3VuZ8KgRWxlY3Ryb25pY3MbRW5naW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG0NJU0hRG0MxMEdEMDFHRDAxMDE1Nw==?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161111153244eucas1p1b96bd587fa752e080f6908c35f77882e X-RootMTR: 20161111153244eucas1p1b96bd587fa752e080f6908c35f77882e References: X-IsSubscribed: yes Hi, this patch fixes PR sanitizer/78307 by adding removed by last merge (although unused in GCC) interface functions: __ubsan_handle_cfi_bad_icall __ubsan_handle_cfi_bad_icall_abort __ubsan_handle_cfi_bad_type __ubsan_handle_cfi_bad_type_abort Just added missed stubs via corresponding arguments translation logic. I've also added new libsanitizer/LOCAL_PATCHES file to track GCC local changes in libsanitizer. The abidiff output now looks like this: Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 7 Added functions Variables changes summary: 0 Removed, 0 Changed, 0 Added variable Function symbols changes summary: 0 Removed, 10 Added function symbols not referenced by debug info Variable symbols changes summary: 0 Removed, 0 Added variable symbol not referenced by debug info 7 Added functions: 'function void __sanitizer_cov_trace_pc_guard_init()' {__sanitizer_cov_trace_pc_guard_init} 'function int __sanitizer_install_malloc_and_free_hooks(void (typedef __sanitizer::uptr)*, void ()*)' {__sanitizer_install_malloc_and_free_hooks} 'function void __sanitizer_set_report_fd(void*)' {__sanitizer_set_report_fd} 'function void __sanitizer_symbolize_global(__sanitizer::uptr, const char*, char*, __sanitizer::uptr)' {__sanitizer_symbolize_global} 'function void __sanitizer_symbolize_pc(__sanitizer::uptr, const char*, char*, __sanitizer::uptr)' {__sanitizer_symbolize_pc} 'function void __ubsan::__ubsan_handle_cfi_check_fail(__ubsan::CFICheckFailData*, __ubsan::ValueHandle, __sanitizer::uptr)' {__ubsan_handle_cfi_check_fail} 'function void __ubsan::__ubsan_handle_cfi_check_fail_abort(__ubsan::CFICheckFailData*, __ubsan::ValueHandle, __sanitizer::uptr)' {__ubsan_handle_cfi_check_fail_abort} 10 Added function symbols not referenced by debug info: __sanitizer_cov_trace_cmp1 __sanitizer_cov_trace_cmp2 __sanitizer_cov_trace_cmp4 __sanitizer_cov_trace_cmp8 __sanitizer_cov_trace_div4 __sanitizer_cov_trace_div8 __sanitizer_cov_trace_gep __sanitizer_cov_trace_pc_guard __sanitizer_cov_trace_pc_indir internal_sigreturn Tested on x86_64-unknown-linux-gnu. OK for mainline? -Maxim libsanitizer/ChangeLog: 2016-11-11 Maxim Ostapenko PR sanitizer/78307 * ubsan/ubsan_handlers.cc (__ubsan_handle_cfi_bad_icall): New function. ( __ubsan_handle_cfi_bad_icall_abort): Likewise. * ubsan/ubsan_handlers.h (struct CFIBadIcallData): New type. * ubsan/ubsan_handlers_cxx.cc (__ubsan_handle_cfi_bad_type): New function. (__ubsan_handle_cfi_bad_type_abort): Likewise. * ubsan/ubsan_handlers_cxx.h (struct CFIBadTypeData): New type. (__ubsan_handle_cfi_bad_type): Export function. (__ubsan_handle_cfi_bad_type_abort): Likewise. * LOCAL_PATCHES: New file. * HOWTO_MERGE: Update documentation. diff --git a/libsanitizer/HOWTO_MERGE b/libsanitizer/HOWTO_MERGE index d0eca40..81121aa 100644 --- a/libsanitizer/HOWTO_MERGE +++ b/libsanitizer/HOWTO_MERGE @@ -11,7 +11,8 @@ general list of actions required to perform the merge: in corresponding CMakeLists.txt and config-ix.cmake files from compiler-rt source directory. * Apply all needed GCC-specific patches to libsanitizer (note that some of - them might be already included to upstream). + them might be already included to upstream). The list of these patches is stored + into LOCAL_PATCHES file. * Apply all necessary compiler changes. Be especially careful here, you must not break ABI between compiler and library. You can reveal these changes by inspecting the history of AddressSanitizer.cpp and ThreadSanitizer.cpp files @@ -37,3 +38,4 @@ general list of actions required to perform the merge: in libasan, configure/Makefile changes). The review process has O(N^2) complexity, so you would simplify and probably speed up the review process by doing this. * Send your patches for review to GCC Patches Mailing List (gcc-patches@gcc.gnu.org). +* Update LOCAL_PATCHES file when you've committed the whole patch set with new revisions numbers. diff --git a/libsanitizer/ubsan/ubsan_handlers.cc b/libsanitizer/ubsan/ubsan_handlers.cc index 0e343d3..5631e45 100644 --- a/libsanitizer/ubsan/ubsan_handlers.cc +++ b/libsanitizer/ubsan/ubsan_handlers.cc @@ -558,6 +558,21 @@ static void HandleCFIBadType(CFICheckFailData *Data, ValueHandle Vtable, #endif } // namespace __ubsan +void __ubsan::__ubsan_handle_cfi_bad_icall(CFIBadIcallData *CallData, + ValueHandle Function) { + GET_REPORT_OPTIONS(false); + CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type}; + handleCFIBadIcall(&Data, Function, Opts); +} + +void __ubsan::__ubsan_handle_cfi_bad_icall_abort(CFIBadIcallData *CallData, + ValueHandle Function) { + GET_REPORT_OPTIONS(true); + CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type}; + handleCFIBadIcall(&Data, Function, Opts); + Die(); +} + void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data, ValueHandle Value, uptr ValidVtable) { diff --git a/libsanitizer/ubsan/ubsan_handlers.h b/libsanitizer/ubsan/ubsan_handlers.h index ef741ca..394c9ea 100644 --- a/libsanitizer/ubsan/ubsan_handlers.h +++ b/libsanitizer/ubsan/ubsan_handlers.h @@ -156,12 +156,20 @@ enum CFITypeCheckKind : unsigned char { CFITCK_ICall, }; +struct CFIBadIcallData { + SourceLocation Loc; + const TypeDescriptor &Type; +}; + struct CFICheckFailData { CFITypeCheckKind CheckKind; SourceLocation Loc; const TypeDescriptor &Type; }; +/// \brief Handle control flow integrity failure for indirect function calls. +RECOVERABLE(cfi_bad_icall, CFIBadIcallData *Data, ValueHandle Function) + /// \brief Handle control flow integrity failures. RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function, uptr VtableIsValid) diff --git a/libsanitizer/ubsan/ubsan_handlers_cxx.cc b/libsanitizer/ubsan/ubsan_handlers_cxx.cc index 015a9ff..007a1d6 100644 --- a/libsanitizer/ubsan/ubsan_handlers_cxx.cc +++ b/libsanitizer/ubsan/ubsan_handlers_cxx.cc @@ -142,4 +142,22 @@ void HandleCFIBadType(CFICheckFailData *Data, ValueHandle Vtable, } } // namespace __ubsan +void __ubsan::__ubsan_handle_cfi_bad_type(CFIBadTypeData *TypeData, + ValueHandle Vtable) { + GET_REPORT_OPTIONS(false); + CFITypeCheckKind TypeCheckKind + = static_cast (TypeData->TypeCheckKind); + CFICheckFailData Data = {TypeCheckKind, TypeData->Loc, TypeData->Type}; + HandleCFIBadType(&Data, Vtable, false, Opts); +} + +void __ubsan::__ubsan_handle_cfi_bad_type_abort(CFIBadTypeData *TypeData, + ValueHandle Vtable) { + GET_REPORT_OPTIONS(true); + CFITypeCheckKind TypeCheckKind + = static_cast (TypeData->TypeCheckKind); + CFICheckFailData Data = {TypeCheckKind, TypeData->Loc, TypeData->Type}; + HandleCFIBadType(&Data, Vtable, false, Opts); +} + #endif // CAN_SANITIZE_UB diff --git a/libsanitizer/ubsan/ubsan_handlers_cxx.h b/libsanitizer/ubsan/ubsan_handlers_cxx.h index 3738235..6ace2b3 100644 --- a/libsanitizer/ubsan/ubsan_handlers_cxx.h +++ b/libsanitizer/ubsan/ubsan_handlers_cxx.h @@ -23,6 +23,12 @@ struct DynamicTypeCacheMissData { unsigned char TypeCheckKind; }; +struct CFIBadTypeData { + SourceLocation Loc; + const TypeDescriptor &Type; + unsigned char TypeCheckKind; +}; + /// \brief Handle a runtime type check failure, caused by an incorrect vptr. /// When this handler is called, all we know is that the type was not in the /// cache; this does not necessarily imply the existence of a bug. @@ -32,6 +38,13 @@ void __ubsan_handle_dynamic_type_cache_miss( extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __ubsan_handle_dynamic_type_cache_miss_abort( DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash); + +/// \brief Handle a control flow integrity check failure by printing a +/// diagnostic. +extern "C" SANITIZER_INTERFACE_ATTRIBUTE void +__ubsan_handle_cfi_bad_type(CFIBadTypeData *Data, ValueHandle Vtable); +extern "C" SANITIZER_INTERFACE_ATTRIBUTE void +__ubsan_handle_cfi_bad_type_abort(CFIBadTypeData *Data, ValueHandle Vtable); } #endif // UBSAN_HANDLERS_H