From patchwork Wed Jul 5 19:17:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 784825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x2rHd4Lycz9s7F for ; Thu, 6 Jul 2017 05:18:04 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="VZhhtb4z"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=DyCTT4jCXS5v6/h0R Hm+K0e04JAZwm+BFQn+pLkaoq7HG8sAZ0aWIGmqrlnpDGw0PUlt0xcBg3++yZx6q obIiZtlcIrw1UBFrkh8MltySORgy0u6x5WJfkrZonlLEw3Rm2EnnziIe5w8Eu1DS cr0WPthRVnnncmpfPg+9d/yvX4= 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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=5A+BHBm8IIaebOCK8I/zPmI e81g=; b=VZhhtb4zW0rH7zT7neMSZaStTNf8gpf+/E1WXkKoXKvo1lglyDyYFpb FICRFHk/0fCIjqcwmqEKVMqkdql2bJ9zgZsmpBDyps2tGy8vbdkskkP9eC+Xw7Fy SCkDQ1emzABKCAgdPrjk8YIUz9aukIlDdp8UiP+MnfjySRj2veAc= Received: (qmail 115761 invoked by alias); 5 Jul 2017 19:17:54 -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 115722 invoked by uid 89); 5 Jul 2017 19:17:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=thinks X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Jul 2017 19:17:51 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48FC4A0218; Wed, 5 Jul 2017 19:17:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 48FC4A0218 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jwakely@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 48FC4A0218 Received: from localhost (unknown [10.33.36.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id B63001710C; Wed, 5 Jul 2017 19:17:49 +0000 (UTC) Date: Wed, 5 Jul 2017 20:17:48 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Martin =?utf-8?B?TGnFoWth?= , Jakub Jelinek Subject: Re: [PATCH] Add AddressSanitizer annotations to std::vector Message-ID: <20170705191748.GF15340@redhat.com> References: <20170705190010.GA19143@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170705190010.GA19143@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.8.0 (2017-02-23) On 05/07/17 20:00 +0100, Jonathan Wakely wrote: >We can probably do similar annotations for std::deque, so that >partially filled pages are annotated. I also have a patch for >shared_ptr so that objects created by make_shared can be marked as >invalid after they're destroyed. This is the make_shared annotation patch. This allows ASan to give an error for: auto p = std::make_shared(); std::weak_ptr w = p; int* pi = p.get(); p = nullptr; return *pi; The error isn't ideal, because ASan thinks we're using a container, because that's what the annotations are intended for: ==4525==ERROR: AddressSanitizer: container-overflow commit d0478d9fbd17b9e9d165b4893f784ae897531713 Author: Jonathan Wakely Date: Tue Jun 27 13:31:12 2017 +0100 Add AddressSanitizer annotations to std::make_shared * include/bits/shared_ptr_base.h [_GLIBCXX_SANITIZE_STD_ALLOCATOR] (__asan_annotate): Add. (_Sp_counted_ptr_inplace::_M_dispose): Call __asan_annotate. diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 7e6766b..a720018 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -57,6 +57,12 @@ #include #include +#if _GLIBCXX_SANITIZE_STD_ALLOCATOR +extern "C" void +__sanitizer_annotate_contiguous_container(const void*, const void*, + const void*, const void*); +#endif + namespace std _GLIBCXX_VISIBILITY(default) { #if !__cpp_rtti @@ -522,6 +528,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif }; +#if _GLIBCXX_SANITIZE_STD_ALLOCATOR + template + inline void + __asan_annotate(const void* __beg, const void* __mid, const void* __end, + const allocator<_Tp>&) + { __sanitizer_annotate_contiguous_container(__beg, __end, __end, __mid); } + + template + inline void + __asan_annotate(const void*, const void*, const void*, const _Alloc&) + { } +#endif + template class _Sp_counted_ptr_inplace final : public _Sp_counted_base<_Lp> { @@ -556,6 +575,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_dispose() noexcept { allocator_traits<_Alloc>::destroy(_M_impl._M_alloc(), _M_ptr()); +#if _GLIBCXX_SANITIZE_STD_ALLOCATOR + __asan_annotate(this, &_M_impl._M_storage, this + 1, _M_impl._M_alloc()); +#endif } // Override because the allocator needs to know the dynamic type