From patchwork Wed Nov 15 11:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 165280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2459824vqg; Wed, 15 Nov 2023 03:03:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEs7opyy3fT++V9DUVDwf5anOJ4T8GcojyPsEgzKxjwgVQuRjLunpgldt/eGeM5sh5u/QWg X-Received: by 2002:a05:6214:17c6:b0:66d:3f8b:fd93 with SMTP id cu6-20020a05621417c600b0066d3f8bfd93mr5441710qvb.2.1700046187412; Wed, 15 Nov 2023 03:03:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700046187; cv=pass; d=google.com; s=arc-20160816; b=bgixGOkDQzvq3H77pUYSQ893L3eLeW7TV+nqBUhLwdgiFZ4p4R3ujJ/lrGgzyugOQY c+2VtaPFLTe8G2JGfUuRfX4Ii6H4nGwp3i0GM0RMIFb9V2c0b4LFqCGKClpFl6T01lFo FIEiyaVY+2/0JVIOfKsxsFqdJtxHo+0TU1JRNJMZRprUs0JJ/mzjmxTiVNcXKDUxL8KY Rd8462A84IfLorVxmUJgWoxIxWByMO/Ee7kvJU9F0HVh9gLzTV4iv2TV09dt/GX9KIQW iHy9D7a6x255Kk2kgkD2MP1A7h5XGZRU5GPuLawuo6CUwttsjhHgEVtIm89yCVonKV2Y bKgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=JO1HF1FzV0JQL82smmjEupE4F56H0jIluQd+g0vn6Jc=; fh=gQl4idKbq/nX3us5twaqDssuTOMIFQPDS+MWz3jC+os=; b=0txWTR6B6n6DaOBOCL6UJ0eU4/AcgFX3earb+F0hGnNZoWbBYsmWYnEwI4fN0Blgbd uuoxVPJEiWNUGR5GHuQGzk5pK4Y7PifRmBzzbLTCT872GQv7AroS8l6D8mYGycAahntA 3l5E6h7ef2s5fzPpaf/o1B75sx/6TMP+Q+8qn0CLd8naGQTKqOoGx2MuxliGLQYSDJuA sOGEz5mWzSr19GdnJ0cw7jDf95QUw4ywFWvaulanA67jhYUtS3NY/dL8HDCkBSyf1nqo vrr3nRFFQerwfQxzaQDJtoE4ClakRFIktA/ebcrcqT+FN967+BqmLTaIUbPWfAy3cncI VJFw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XZ1O6+L4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id eu18-20020ad44f52000000b00670b3a82416si8720795qvb.343.2023.11.15.03.03.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 03:03:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XZ1O6+L4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B704385783E for ; Wed, 15 Nov 2023 11:02:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B0BB43858C30 for ; Wed, 15 Nov 2023 11:02:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0BB43858C30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B0BB43858C30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700046154; cv=none; b=SBhhDLDloXmc2T4x6lS1kV9KLb24ASHWeowLvlON+EEsP04gA3OKbrDsRHjQcHhEVEkrrYXMctkaJ8sQCrcJC8MfJpXXJz357/moh4Y6C8nISj0umVyXVu4hAuh6xIF70iMwK0uj0cQzlQOn8ZfbUpDwUcQd0JVigBhpJT3nmvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700046154; c=relaxed/simple; bh=WzxxdN036MGZCpHPbqCdoJrWxYf7JDGEFkKgMytwrYM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=oNslNeuhuxP4AeMqrtLSd/xM1qyzmCrevyFUV8aOE2PHT+Qk4d2KMz52VGhtUM+0HG/CVYjHMCRsCS2S8pGs7v1fpeFwSlvog44AbWh9mqodxjH5BVVZkoZwd2Xib4LUT9L3bDtma5po1nO9NL6/gGevkOGxTWtxfLsPL4jTKfo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700046151; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=JO1HF1FzV0JQL82smmjEupE4F56H0jIluQd+g0vn6Jc=; b=XZ1O6+L4No42DUjqID/TDuRQYsMO+FOvd/l8SwWQF/UCqEmeA2TDfDBxRSB9laFxs66QvR bgyRjb4IB0+ftGnVKpBW6aAu8W9zBMk2e0+JLLGC0YLpvXfRV+Szv5xjBPRKZIRA1bUJQc yaXZn9f20hS6nUYQ1o5Aieb5a1cI+ac= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-2vNRZKQrMBijex_ZB-bkTQ-1; Wed, 15 Nov 2023 06:02:28 -0500 X-MC-Unique: 2vNRZKQrMBijex_ZB-bkTQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 47D85811003; Wed, 15 Nov 2023 11:02:28 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC2FA2166B29; Wed, 15 Nov 2023 11:02:27 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AFB2O1Y285879 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 12:02:25 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AFB2NZJ285878; Wed, 15 Nov 2023 12:02:23 +0100 Date: Wed, 15 Nov 2023 12:02:23 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org, Iain Sandoe , Jeff Law Subject: [PATCH 4/4] libsanitizer: Readd __ubsan_handle_function_type_mismatch_v1{,_abort} Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782627630616786067 X-GMAIL-MSGID: 1782627630616786067 Hi! So that we don't have to bump libubsan.so.1 SONAME, the following patch reverts part of the changes which removed two handlers. While we don't actually use them from GCC, we shouldn't remove supported entrypoints unless SONAME is changed (removal of __interceptor_* or ___interceptor_* is fine). This is the only removal, other libraries just added some symbols. 2023-11-15 Jakub Jelinek * ubsan/ubsan_handlers_cxx.h (FunctionTypeMismatchData): Forward declare. (__ubsan_handle_function_type_mismatch_v1, __ubsan_handle_function_type_mismatch_v1_abort): Declare. * ubsan/ubsan_handlers_cxx.cpp (handleFunctionTypeMismatch, __ubsan_handle_function_type_mismatch_v1, __ubsan_handle_function_type_mismatch_v1_abort): New functions readded for backwards compatibility from older ubsan. * ubsan/ubsan_interface.inc (__ubsan_handle_function_type_mismatch_v1, __ubsan_handle_function_type_mismatch_v1_abort): Readd. Jakub --- libsanitizer/ubsan/ubsan_handlers_cxx.h.jj 2023-11-14 23:52:59.417503473 +0100 +++ libsanitizer/ubsan/ubsan_handlers_cxx.h 2023-11-15 11:36:34.961739772 +0100 @@ -33,6 +33,19 @@ void __ubsan_handle_dynamic_type_cache_m extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __ubsan_handle_dynamic_type_cache_miss_abort( DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash); + +struct FunctionTypeMismatchData; + +extern "C" SANITIZER_INTERFACE_ATTRIBUTE void +__ubsan_handle_function_type_mismatch_v1(FunctionTypeMismatchData *Data, + ValueHandle Val, + ValueHandle calleeRTTI, + ValueHandle fnRTTI); +extern "C" SANITIZER_INTERFACE_ATTRIBUTE void +__ubsan_handle_function_type_mismatch_v1_abort(FunctionTypeMismatchData *Data, + ValueHandle Val, + ValueHandle calleeRTTI, + ValueHandle fnRTTI); } #endif // UBSAN_HANDLERS_CXX_H --- libsanitizer/ubsan/ubsan_handlers_cxx.cpp.jj 2023-11-14 23:52:59.417503473 +0100 +++ libsanitizer/ubsan/ubsan_handlers_cxx.cpp 2023-11-15 11:31:56.241672876 +0100 @@ -156,6 +156,50 @@ void __ubsan_handle_cfi_bad_type(CFIChec Diag(Loc, DL_Note, ET, "check failed in %0, vtable located in %1") << SrcModule << DstModule; } + +static bool handleFunctionTypeMismatch(FunctionTypeMismatchData *Data, + ValueHandle Function, + ValueHandle calleeRTTI, + ValueHandle fnRTTI, ReportOptions Opts) { + if (checkTypeInfoEquality(reinterpret_cast(calleeRTTI), + reinterpret_cast(fnRTTI))) + return false; + + SourceLocation CallLoc = Data->Loc.acquire(); + ErrorType ET = ErrorType::FunctionTypeMismatch; + + if (ignoreReport(CallLoc, Opts, ET)) + return true; + + ScopedReport R(Opts, CallLoc, ET); + + SymbolizedStackHolder FLoc(getSymbolizedLocation(Function)); + const char *FName = FLoc.get()->info.function; + if (!FName) + FName = "(unknown)"; + + Diag(CallLoc, DL_Error, ET, + "call to function %0 through pointer to incorrect function type %1") + << FName << Data->Type; + Diag(FLoc, DL_Note, ET, "%0 defined here") << FName; + return true; +} + +void __ubsan_handle_function_type_mismatch_v1(FunctionTypeMismatchData *Data, + ValueHandle Function, + ValueHandle calleeRTTI, + ValueHandle fnRTTI) { + GET_REPORT_OPTIONS(false); + handleFunctionTypeMismatch(Data, Function, calleeRTTI, fnRTTI, Opts); +} + +void __ubsan_handle_function_type_mismatch_v1_abort( + FunctionTypeMismatchData *Data, ValueHandle Function, + ValueHandle calleeRTTI, ValueHandle fnRTTI) { + GET_REPORT_OPTIONS(true); + if (handleFunctionTypeMismatch(Data, Function, calleeRTTI, fnRTTI, Opts)) + Die(); +} } // namespace __ubsan #endif // CAN_SANITIZE_UB --- libsanitizer/ubsan/ubsan_interface.inc.jj 2023-11-14 23:52:59.417503473 +0100 +++ libsanitizer/ubsan/ubsan_interface.inc 2023-11-15 11:32:57.430809418 +0100 @@ -21,6 +21,8 @@ INTERFACE_FUNCTION(__ubsan_handle_dynami INTERFACE_FUNCTION(__ubsan_handle_dynamic_type_cache_miss_abort) INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow) INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow_abort) +INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1) +INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1_abort) INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch) INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_abort) INTERFACE_FUNCTION(__ubsan_handle_implicit_conversion)