Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp707040imm; Wed, 17 Oct 2018 07:07:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV620lms8JTTJvytme2zfvZyzf8DpRHfOJYGC+KvTu9/UrYvWK44gFCLnM9pRYMQDhWN+e4od X-Received: by 2002:a63:fc46:: with SMTP id r6-v6mr24865786pgk.345.1539785272607; Wed, 17 Oct 2018 07:07:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539785272; cv=none; d=google.com; s=arc-20160816; b=RMuzkmZMw9Y0JftHx7wRmaIhigPpFZeiyOuhVCm3kGQO+s6sFi5UkxFBNfOXEXE6Ko qg2CkVx9Td4dAODECCVzOdguICeeQUuomI10wjTcDCd09QfwzKCDT2q3BX2CTUi6rdR6 V6e7jp9/ApYMRU7pa37RZxwTi22moJigSwXzKTYjVGFgqsibJ00OLt7AOU90P14HkKtH Qljp7ku4SfER6aCytDOAR9vORQnMqx9dKAwrzgCT1kzHDWpNPAg0GcEDmq22sfUVBWOr /GYl04YcRlnjdMMW7yo3TiA2OdLQYoiTrDEzL0tdC8RNdGfsIePPF1pSrGFPvB3Xxba1 Gz+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=UPBT+PSxQNtZBIOL0K4RqCrwHjXELgm/LJz5r1NfwJY=; b=aL0UYWJBy7BZ75JyLoVh0KETmz1u4uDv1M0uxmpRhgdtItEY3zKR2ykrEf9ryxR+ha dezvU1lbWtiCKEfRFC1RlaBoOPtCKGAuhaihOvKE11K6G/Sz8pHcIG9+Ul9JYpYgGprA OsVQHVJ24BfyC664xBFWZSf5aRjVlKdv/s/CTf4jOAaRJoqek1PbrzR2bZAzvJ2vFh1P 3JN5YORLxW7QcB6hBSfMheYOrKzl8qhmeeCV4OzdnPvm5qoi6Utii0M8N15JVINrI1rb wmBEZZAlCzPo79PCAmj5VpTVpOf49Fza3v/IKgEEhkmJH5xcvSivWyNhiHTWNYnx/uQr kcAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n33-v6si17654780pgm.510.2018.10.17.07.07.36; Wed, 17 Oct 2018 07:07:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbeJQWCv (ORCPT + 99 others); Wed, 17 Oct 2018 18:02:51 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:52344 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727013AbeJQWCv (ORCPT ); Wed, 17 Oct 2018 18:02:51 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E51AC80D; Wed, 17 Oct 2018 07:06:58 -0700 (PDT) Received: from [10.1.196.72] (unknown [10.1.196.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D16493F71A; Wed, 17 Oct 2018 07:06:54 -0700 (PDT) Subject: Re: [PATCH v7 0/8] arm64: untag user pointers passed to the kernel To: Andrey Konovalov , Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Chintan Pandya , Jacob Bramley , Ruben Ayrapetyan , Lee Smith , Kostya Serebryany , Dmitry Vyukov , Ramana Radhakrishnan , Luc Van Oostenryck , Evgeniy Stepanov References: From: Vincenzo Frascino Message-ID: Date: Wed, 17 Oct 2018 15:06:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrey, On 02/10/2018 14:12, Andrey Konovalov wrote: > arm64 has a feature called Top Byte Ignore, which allows to embed pointer > tags into the top byte of each pointer. Userspace programs (such as > HWASan, a memory debugging tool [1]) might use this feature and pass > tagged user pointers to the kernel through syscalls or other interfaces. > > Right now the kernel is already able to handle user faults with tagged > pointers, due to these patches: > > 1. 81cddd65 ("arm64: traps: fix userspace cache maintenance emulation on a > tagged pointer") > 2. 7dcd9dd8 ("arm64: hw_breakpoint: fix watchpoint matching for tagged > pointers") > 3. 276e9327 ("arm64: entry: improve data abort handling of tagged > pointers") > > When passing tagged pointers to syscalls, there's a special case of such a > pointer being passed to one of the memory syscalls (mmap, mprotect, etc.). > These syscalls don't do memory accesses but rather deal with memory > ranges, hence an untagged pointer is better suited. > > This patchset extends tagged pointer support to non-memory syscalls. This > is done by reusing the untagged_addr macro to untag user pointers when the > kernel performs pointer checking to find out whether the pointer comes > from userspace (most notably in access_ok). > > The following testing approaches has been taken to find potential issues > with user pointer untagging: > > 1. Static testing (with sparse [2] and separately with a custom static > analyzer based on Clang) to track casts of __user pointers to integer > types to find places where untagging needs to be done. > > 2. Dynamic testing: adding BUG_ON(has_tag(addr)) to find_vma() and running > a modified syzkaller version that passes tagged pointers to the kernel. > ... I have been thinking a bit lately on how to address the problem of user tagged pointers passed to the kernel through syscalls, and IMHO probably the best way we have to catch them all and make sure that the approach is maintainable in the long term is to introduce shims that tag/untag the pointers passed to the kernel. In details, what I am proposing can live either in userspace (preferred solution so that we do not have to relax the ABI) or in kernel space and can be summarized as follows: - A shim is specific to a syscall and is called by the libc when it needs to invoke the respective syscall. - It is required only if the syscall accepts pointers. - It saves the tags of a pointers passed to the syscall in memory (same approach if the we are passing a struct that contains pointers to the kernel, with the difference that all the tags of the pointers in the struct need to be saved singularly) - Untags the pointers - Invokes the syscall - Retags the pointers with the tags stored in memory - Returns What do you think? -- Regards, Vincenzo