From patchwork Sat Nov 13 20:37:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 47623 X-Patchwork-Delegate: dmalcolm@redhat.com 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 83CC03858034 for ; Sat, 13 Nov 2021 20:42:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83CC03858034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636836132; bh=HZIiCx8ER1sk7j0VzxqjwHljZWuSHPOvv9JoO+KrwJQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fiamnMJgFw90PRnyBCgKYZ88Ksic/E1kMBHP1YqaKLjtxjEec+JujdwOcnEOg/Si2 bTGaOegPqdy1u8PKGsw2pN6JWs3dyNCjlmIvR2K5GGtQfab5oVOo9N+tMCqQk2bgFS oawC9HLfphWSwtGZLSiZhARj4HDMqKjpbwyVmONM= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 2D8A43857C44 for ; Sat, 13 Nov 2021 20:37:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2D8A43857C44 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-531-VuIzoXGnOkKXxTv71nLdAg-1; Sat, 13 Nov 2021 15:37:44 -0500 X-MC-Unique: VuIzoXGnOkKXxTv71nLdAg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 700981006AA1; Sat, 13 Nov 2021 20:37:43 +0000 (UTC) Received: from t14s.localdomain.com (ovpn-113-54.phx2.redhat.com [10.3.113.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 038C619D9D; Sat, 13 Nov 2021 20:37:42 +0000 (UTC) To: gcc-patches@gcc.gnu.org, linux-toolchains@vger.kernel.org Subject: [PATCH 4b/6] analyzer: implement region::untrusted_p in terms of __attribute__((untrusted)) Date: Sat, 13 Nov 2021 15:37:30 -0500 Message-Id: <20211113203732.2098220-7-dmalcolm@redhat.com> In-Reply-To: <20211113203732.2098220-1-dmalcolm@redhat.com> References: <20211113203732.2098220-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" gcc/analyzer/ChangeLog: * region.cc (region::untrusted_p): Implement in terms of __attribute__((untrusted)). gcc/testsuite/ChangeLog: * gcc.dg/analyzer/test-uaccess.h: Change from custom_address_space pragma to __attribute__((untrusted)). Signed-off-by: David Malcolm --- gcc/analyzer/region.cc | 19 +++++++++++++++---- gcc/testsuite/gcc.dg/analyzer/test-uaccess.h | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc index b84504dbe42..52e9fa2d1e6 100644 --- a/gcc/analyzer/region.cc +++ b/gcc/analyzer/region.cc @@ -672,10 +672,21 @@ region::symbolic_for_unknown_ptr_p () const bool region::untrusted_p () const { - addr_space_t as = get_addr_space (); - /* FIXME: treat all non-generic address spaces as untrusted for now. */ - if (!ADDR_SPACE_GENERIC_P (as)) - return true; + const region *iter = this; + while (iter) + { + if (iter->get_type ()) + return TYPE_UNTRUSTED (iter->get_type ()); + switch (iter->get_kind ()) + { + default: + iter = iter->get_parent_region (); + continue; + case RK_CAST: + iter = iter->dyn_cast_cast_region ()->get_original_region (); + continue; + } + } return false; } diff --git a/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h b/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h index 0500e20b22b..280f4045418 100644 --- a/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h +++ b/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h @@ -2,7 +2,7 @@ /* Adapted from include/linux/compiler.h */ -#pragma GCC custom_address_space(__user) +#define __user __attribute__((untrusted)) /* Adapted from include/asm-generic/uaccess.h */