From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B05F7C433EF for ; Sat, 13 Nov 2021 20:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83E6F60C49 for ; Sat, 13 Nov 2021 20:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233898AbhKMUki (ORCPT ); Sat, 13 Nov 2021 15:40:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37862 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233346AbhKMUkh (ORCPT ); Sat, 13 Nov 2021 15:40:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636835864; 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=7Jc4vTFEauI0fg4rb+yUh8Oa0FeV0Ap+TCd+JueEUPM=; b=Rm/ZuEjhdG3WrWQ+uWdJ81CT+UlT9wGGk5ZmHsZt9D2jbu0qZ7571UC8lCQCXSSDmKjCFB o3h0Cx0j2puRX0O2ftguLqK1T+X2njG9DjO5yYOiamULf9Ub7EkHdwoVZMw9U8FwEBweMf eaZZN1EHijv0v8N9n7FGV4lfAXXD91s= 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-48-zXbd1EhlNZCIj21MvjUnVw-1; Sat, 13 Nov 2021 15:37:43 -0500 X-MC-Unique: zXbd1EhlNZCIj21MvjUnVw-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 D1DF9875048; Sat, 13 Nov 2021 20:37:42 +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 65D5919D9D; Sat, 13 Nov 2021 20:37:42 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org, linux-toolchains@vger.kernel.org Cc: David Malcolm Subject: [PATCH 4a/6] analyzer: implement region::untrusted_p in terms of custom address spaces Date: Sat, 13 Nov 2021 15:37:29 -0500 Message-Id: <20211113203732.2098220-6-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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmalcolm@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org gcc/analyzer/ChangeLog: (region::untrusted_p): New. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/test-uaccess.h: New header. Signed-off-by: David Malcolm --- gcc/analyzer/region.cc | 13 +++++++++++++ gcc/testsuite/gcc.dg/analyzer/test-uaccess.h | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/analyzer/test-uaccess.h diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc index bb4f53b8802..b84504dbe42 100644 --- a/gcc/analyzer/region.cc +++ b/gcc/analyzer/region.cc @@ -666,6 +666,19 @@ region::symbolic_for_unknown_ptr_p () const return false; } +/* Return true if accessing this region crosses a trust boundary + e.g. user-space memory as seen by an OS kernel. */ + +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; + return false; +} + /* region's ctor. */ region::region (complexity c, unsigned id, const region *parent, tree type) diff --git a/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h b/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h new file mode 100644 index 00000000000..0500e20b22b --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h @@ -0,0 +1,19 @@ +/* Shared header for testcases for copy_from_user/copy_to_user. */ + +/* Adapted from include/linux/compiler.h */ + +#pragma GCC custom_address_space(__user) + +/* Adapted from include/asm-generic/uaccess.h */ + +extern int copy_from_user(void *to, const void __user *from, long n) + __attribute__((access (write_only, 1, 3), + access (read_only, 2, 3), + returns_zero_on_success + )); + +extern long copy_to_user(void __user *to, const void *from, unsigned long n) + __attribute__((access (write_only, 1, 3), + access (read_only, 2, 3), + returns_zero_on_success + )); -- 2.26.3