From patchwork Thu Apr 4 16:42:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 88049 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B4B8D384640C for ; Thu, 4 Apr 2024 16:45:22 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 54F463858402 for ; Thu, 4 Apr 2024 16:42:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54F463858402 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 54F463858402 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712248936; cv=none; b=wPGTZm/eRWXI1MOefs6sHosi/A0xBfFGyad4t1mcGqxfmq5gp38Ab4Ajwi4mkb7VMIvWizSNS8xdoIN3kb/yIvuQT5z4/wM5HGty3VxCwvJCz1OczOvVXGo9pxiW3vDMvbK1R2LhGdp7maGYFVRaGMPboQaGMrwhB4UhZq7jAHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712248936; c=relaxed/simple; bh=XQVFlsgScQkhhkyxxBhLTioNnbZupPZhHkh/S+V8Z+E=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=a2EcG5FNnDVFcB5QNESjBjAwzjgda8art11Iaf8z7YwCrm/eZ44cK/x+jglLhlDT327UavcRgCF4bpQiJcLEE7mPgONzqmnucTyoQtSDoJnmF50isowDGfAb07YlzDaAWjNN9ygQZ4OOSL1ouofDhnNt52QplqWa0R7gRSih0Yg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712248933; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sbI8K/Z2twiH6ACkuQ1zl0PPLYvu+wwvgN2OuEnqeQg=; b=H8qRMkZRK4ZqwE+4eewKYTkIcVLiwZhIZ3MmXVCta8onMOjjmSX+idVwU4yCfEbppOT838 rgBMgX6RUGaT9DrRtsjlixNGczHJZtl1gwRm8bF+dP7Y1FKe93TdqaUQnoQmGVolO1jga0 ytfXL7fLDuZFvkDrBZYYmkgys5XmxII= 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-504-4YqTZxu8NuKHY336r1btdw-1; Thu, 04 Apr 2024 12:42:11 -0400 X-MC-Unique: 4YqTZxu8NuKHY336r1btdw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 1ED53185A787 for ; Thu, 4 Apr 2024 16:42:11 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.32.209]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED88A1C060CE; Thu, 4 Apr 2024 16:42:10 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 8/9] wwwdocs: gcc-14: analyzer improvements Date: Thu, 4 Apr 2024 12:42:07 -0400 Message-Id: <20240404164208.2437213-9-dmalcolm@redhat.com> In-Reply-To: <20240404164208.2437213-1-dmalcolm@redhat.com> References: <20240404164208.2437213-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Signed-off-by: David Malcolm --- htdocs/gcc-14/changes.html | 162 +++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/htdocs/gcc-14/changes.html b/htdocs/gcc-14/changes.html index 8b72bc20..d782c334 100644 --- a/htdocs/gcc-14/changes.html +++ b/htdocs/gcc-14/changes.html @@ -760,6 +760,168 @@ __asm (".global __flmap_lock" "\n\t" + +

Improvements to Static Analyzer

+
    +
  • + New warnings: + +
  • +
  • + + Previously, the analyzer's "taint" tracking to be explicitly enabled via + -fanalyzer-checker=taint + (along with + -fanalyzer). + This is now enabled by default when + -fanalyzer + is selected, thus also enabling the 6 taint-based warnings: + +
  • +
  • + + The analyzer will now simulate API calls that expect null-terminated + string arguments, and will warn about code paths in which such a call + is made with a buffer that isn't properly terminated, either due to + a read of an uninitialized byte or an out-of-range accesses seen + before any zero byte is seen. + This applies to functions that use the new + null_terminated_string_arg(PARAM_IDX) + attribute, + functions that use the + format + attribute, + and to the library functions + error (parameter 3), + error_at_line (parameter 5), + putenv, + strchr (parameter 1), and + strcpy (parameter 2). +
  • +
  • + + The analyzer now makes use of the function attribute + alloc_size + allowing + -fanalyzer + to emit + -Wanalyzer-allocation-size, + -Wanalyzer-out-of-bounds, + and + -Wanalyzer-tainted-allocation-size + on execution paths involving allocations using such functions. +
  • +
  • + The analyzer's knowledge about the behavior of the standard library has been extended to cover + fopen, + strcat, + strncpy, and + strstr. + The analyzer will also more precisely model the behavior of + memcpy, + memmove, + strcpy, + strdup, + strlen, + and of various atomic built-in functions. +
  • +
  • + +

    The warning + -Wanalyzer-out-of-bounds + has been extended so that, where possible, it will emit a text-based + diagram visualizing the spatial relationship between +

      +
    1. the memory region that the analyzer predicts would be + accessed, versus
    2. +
    3. the range of memory that is valid to access
    4. +
    + whether they overlap, are touching, are close or far apart; + which one is before or after in memory, the relative sizes involved, + the direction of the access (read vs write), and, in some cases, + the values of data involved.

    +

    Such "text art" diagrams can be controlled (or suppressed) via a new + -fdiagnostics-text-art-charset= option. +

    For example, given the out-of-bounds write in strcat in: + +

    +void test (void)
    +{
    +   char buf[10];
    +   strcpy (buf, "hello");
    +   strcat (buf, " world!");
    +}
    +
    +it emits: +
    +                                 ┌────┬────┬────┬────┬────┐┌─────┬─────┬─────┐
    +                                 │[0] │[1] │[2] │[3] │[4] ││ [5] │ [6] │ [7] │
    +                                 ├────┼────┼────┼────┼────┤├─────┼─────┼─────┤
    +                                 │' ' │'w' │'o' │'r' │'l' ││ 'd' │ '!' │ NUL │
    +                                 ├────┴────┴────┴────┴────┴┴─────┴─────┴─────┤
    +                                 │     string literal (type: 'char[8]')      │
    +                                 └───────────────────────────────────────────┘
    +                                   │    │    │    │    │      │     │     │
    +                                   │    │    │    │    │      │     │     │
    +                                   v    v    v    v    v      v     v     v
    +      ┌─────┬────────────────────┬────┬──────────────┬────┐┌─────────────────┐
    +      │ [0] │        ...         │[5] │     ...      │[9] ││                 │
    +      ├─────┼────┬────┬────┬────┬┼────┼──────────────┴────┘│                 │
    +      │ 'h' │'e' │'l' │'l' │'o' ││NUL │                    │after valid range│
    +      ├─────┴────┴────┴────┴────┴┴────┴───────────────────┐│                 │
    +      │             'buf' (type: 'char[10]')              ││                 │
    +      └───────────────────────────────────────────────────┘└─────────────────┘
    +      ├─────────────────────────┬─────────────────────────┤├────────┬────────┤
    +                                │                                   │
    +                      ╭─────────┴────────╮                ╭─────────┴─────────╮
    +                      │capacity: 10 bytes│                │overflow of 3 bytes│
    +                      ╰──────────────────╯                ╰───────────────────╯
    +
    + showing that the overflow occurs partway through the second string + fragment. +
  • +
  • + + The analyzer will now attempt to track execution paths involving + computed gotos, whereas previously it gave up on such paths. +
  • +
+

Improvements for plugin authors