From patchwork Tue Dec 12 02:32:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 177050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7471045vqy; Mon, 11 Dec 2023 18:33:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IENTXj239z1OJ7rECc5zAFIrPS/NnF4xgkXViy2m5xpKjFahLqvu8MswVt7yB5nXdPWvytP X-Received: by 2002:a05:620a:1b93:b0:77f:8:2b65 with SMTP id dv19-20020a05620a1b9300b0077f00082b65mr7474693qkb.130.1702348408041; Mon, 11 Dec 2023 18:33:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702348408; cv=pass; d=google.com; s=arc-20160816; b=YDKxMb3l2qAJ6+f+NQfVim1/vRMIKQswzeNUadz1HCkUdrsPL4DCFvnQGHP/ns6Bg3 Q1lH1UQkPi9HQGodhF4hYEFwvGCpCoCt3F3ZhGL1YlzbE3oJZFy66vXycs9zsipqIkwc FiEiyead+oXcFQm3XUDJOFD87jmlrQP5q3zoLDqNr/53gC4xNnqJLNp27+0PT10AaHDd d1Hr47q44UZ0yseFix9tnk7qopIMfVU9sH/2e8d+IAaBpu81s7M1YyG5XYb4f/hDddR8 TdFzXci8NFFQzZgx20HXgUHQVetw7OXCDqWzoDHYYwGlcoSsXK3xwttZzF+mf1RkbyV4 13ng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=gRNRMsKb2HNkYyInSBTK83/vwCAwfuxZaW5NO3DeWQU=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=j7gj5bzjcLKXhIhPUN2SkF0MC9NnjOeM1hw3KAGvccMQKF7yzae0CEwfqUoXAqEE0p sU/vN9rtVNqSmwAzvR1RYsVsy6KTYcD8g/BD/DEJyvhogbrZYPooKLDKwVr88BdgfLOr RbQDwMesZPzUmjHEEqy5RzIlZEu5V+r7kvNO6Lh6N/+3xQdFtcOd8YSuvbGGElwawHqI wcVUdsYcVf8fwIXHl7kOVb9DITWsgG63+yIT3DTMJcYX7rxfMch6LsxjA2+7iIOzuH26 LAHtHBqxywWWHubC7eN1PMeQwjlfOPgXfamOhHepX8xHIu5h1+hTtJtdDaLbGqtXjjam hKnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Qf4AdACf; 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 j9-20020a05620a410900b0077f01ebc03csi9746469qko.397.2023.12.11.18.33.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:33:28 -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=Qf4AdACf; 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 CB6973858024 for ; Tue, 12 Dec 2023 02:33:27 +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 112143858C54 for ; Tue, 12 Dec 2023 02:33:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 112143858C54 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 112143858C54 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=1702348385; cv=none; b=PRCUjdcpADGRUQb+jT4dHN0etu8d729o3EqkN9rLjOQeldln4bsnfukbysOZaoxAprQHUa9TPdRDgv6mTPIsrcAzOA2E24kVSGfpNaCYEaQIprMTxSbnKcdqGYmTT7KnBah5Kx1W0yJKj3EF8Cr+6T3ZHjcKpP+CSL6j6SjZ2YY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702348385; c=relaxed/simple; bh=pqZ8Jm+KDedZ6HURnOtF5IeduXvUowDDraGMN+Pk7Eo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=RN1/9dBqe9Wx8yWqy8qAUOE8AOCCvV9NrxG4YtYXVXr+2jjSa1CAz4tvOzWKhxkn4d0y4CwJIHjU5di7/5n23hjrLQlmaK9bx8nOKumT21RoLJSyHwjN6/KoJPvrUKmxyPpwq6mhpgxdOpauSEfNKP+EaD3urmXk1+BtweeM0UY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702348383; 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; bh=gRNRMsKb2HNkYyInSBTK83/vwCAwfuxZaW5NO3DeWQU=; b=Qf4AdACf5h+Nk2j2NCG66Zrnvg0LUHo5m3HWHmOH7Hl4CHtdMZB/tplTndwFg5H0BI8t+4 zeIJa5vsbjPnt1L4siugTQ9MV6MhQS29OxiQs9ugB5KJ1AtQ7x1ZZlluMqN9gNABg/jGBX DZsM7zLKxPhzBl5lwOskAj0GBmjmcE8= 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-1-6tAs-zarPEmE66aQx-oiPQ-1; Mon, 11 Dec 2023 21:33:01 -0500 X-MC-Unique: 6tAs-zarPEmE66aQx-oiPQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 64B3B833A12 for ; Tue, 12 Dec 2023 02:33:01 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.8.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 416A651E3; Tue, 12 Dec 2023 02:33:01 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: add more test coverage for tainted modulus Date: Mon, 11 Dec 2023 21:32:59 -0500 Message-Id: <20231212023259.3053155-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785041684073523626 X-GMAIL-MSGID: 1785041684073523626 Add more test coverage for r14-6349-g0bef72539e585d. Pushed to trunk as r14-6444-g2900a77fe4e7d2. gcc/testsuite/ChangeLog: * gcc.dg/plugin/plugin.exp: Add taint-modulus.c to analyzer_kernel_plugin.c tests. * gcc.dg/plugin/taint-modulus.c: New test. --- gcc/testsuite/gcc.dg/plugin/plugin.exp | 1 + gcc/testsuite/gcc.dg/plugin/taint-modulus.c | 75 +++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/plugin/taint-modulus.c diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index d6cccb269df..eebf96116ef 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -165,6 +165,7 @@ set plugin_test_list [list \ taint-CVE-2011-0521-5-fixed.c \ taint-CVE-2011-0521-6.c \ taint-antipatterns-1.c \ + taint-modulus.c \ taint-pr112850.c \ taint-pr112850-precise.c \ taint-pr112850-too-complex.c \ diff --git a/gcc/testsuite/gcc.dg/plugin/taint-modulus.c b/gcc/testsuite/gcc.dg/plugin/taint-modulus.c new file mode 100644 index 00000000000..81d968864e6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/taint-modulus.c @@ -0,0 +1,75 @@ +/* { dg-do compile } */ +/* { dg-options "-fanalyzer" } */ +/* { dg-require-effective-target analyzer } */ + +/* Reduced from a -Wanalyzer-tainted-array-index false +ve + seen in the Linux kernel's sound/drivers/opl3/opl3_synth.c. */ + +extern unsigned long +copy_from_user(void* to, const void* from, unsigned long n); + +struct sbi_patch +{ + unsigned char prog; + unsigned char bank; +}; +struct fm_patch +{ + unsigned char prog; + unsigned char bank; + struct fm_patch* next; +}; +struct snd_opl3 +{ + struct fm_patch* patch_table[32]; +}; +int +snd_opl3_load_patch(struct snd_opl3* opl3, + int prog, + int bank); +struct fm_patch* +snd_opl3_find_patch(struct snd_opl3* opl3, + int prog, + int bank, + int create_patch); +long +snd_opl3_write(struct snd_opl3* opl3, + const char* buf, + long count) +{ + long result = 0; + int err = 0; + struct sbi_patch inst; + while (count >= sizeof(inst)) { + if (copy_from_user(&inst, buf, sizeof(inst))) + return -14; + err = snd_opl3_load_patch(opl3, inst.prog, inst.bank); + if (err < 0) + break; + result += sizeof(inst); + count -= sizeof(inst); + } + return result > 0 ? result : err; +} +int +snd_opl3_load_patch(struct snd_opl3* opl3, + int prog, + int bank) +{ + struct fm_patch* patch; + patch = snd_opl3_find_patch(opl3, prog, bank, 1); + if (!patch) + return -12; + return 0; +} +struct fm_patch* +snd_opl3_find_patch(struct snd_opl3* opl3, int prog, int bank, int create_patch) +{ + unsigned int key = (prog + bank) % 32; + struct fm_patch* patch; + for (patch = opl3->patch_table[key]; patch; patch = patch->next) { /* { dg-bogus "use of attacker-controlled value in array lookup" } */ + if (patch->prog == prog && patch->bank == bank) + return patch; + } + return ((void*)0); +}