Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2012481ybm; Thu, 23 May 2019 09:58:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrqpiQpt02QKdnWYYff0fxy8O1Uku260Y4UmHl9r74aihL2FHs0fNdAFTK2jplZkj4eZ9I X-Received: by 2002:a62:7793:: with SMTP id s141mr39671660pfc.21.1558630737751; Thu, 23 May 2019 09:58:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558630737; cv=none; d=google.com; s=arc-20160816; b=Pm/fAtT7MS+x+sdelyL3jR8gjSXTpE9J/fm4jBWqYwy6YYiGAWkznqSTsSiqQrArJO FnJMIojlfAVA+gkDsl09+HWCslBObeGt/NFZHzSF8obhmW60aVUWwVt3Ga6VTTu+KxYB cc/xK9G/P2dyrxGZN74HZFbREwOjCA45Xl+CVGYs9txCmrb/6kXmOjiMYgx5zeZB3IAD e31wzskURkAt++LpOCkbDwM4wN6UyuAD00ZdxQtRDy4HYUw201u/6r3ZaxQ3hoeBIuU4 dkMAXicNgDDxu6Tq5erCYuVonZH0qz/Nr0wOQ2Dk9cJSgQzezCmnjIiFsAyDp2d8hSAR BJtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Ld+lKZgiu6J6JVmIcVy93cFCEPN8unt8vL7/8dYr5Ns=; b=W6Hw3soat4zvzbNRJ2IzCPBnbTPRmWeVpd7G3PpAPdj9UXtNyDHxqDLlAZ3hgNse6I 6VePJQgrojvg+qWfbCrvglMrfQAcyBjelv/9yjc7o42uP9xoeglDVEmwTmA8Gs7wtA1B XxUUxTmZAdHPq6OeFz99sXQm7pJ3Y7heAbnIV7HDYKeq6tC2PmGbb+h4VcfKEK33qv91 F/O6ZEpXI2rzzGY53Btg80ucqxK7TRuuEf3Q8FB6vUpYVvDPmHzUV3VVUhdKSIQu7JRA o9itHOazwO5Q+eqipyt0sM/I8iljSx/m8JiaRQILXWJnEaUKgC15dodYaNV1q8lbwyun xz3w== 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 bx7si1305749pjb.93.2019.05.23.09.58.42; Thu, 23 May 2019 09:58:57 -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 S1731375AbfEWQ5Y (ORCPT + 99 others); Thu, 23 May 2019 12:57:24 -0400 Received: from foss.arm.com ([217.140.101.70]:50904 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730899AbfEWQ5W (ORCPT ); Thu, 23 May 2019 12:57:22 -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 0774C374; Thu, 23 May 2019 09:57:22 -0700 (PDT) Received: from mbp (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1B06C3F5AF; Thu, 23 May 2019 09:57:15 -0700 (PDT) Date: Thu, 23 May 2019 17:57:09 +0100 From: Catalin Marinas To: Dave Martin Cc: Jason Gunthorpe , Mark Rutland , kvm@vger.kernel.org, Christian Koenig , Szabolcs Nagy , Will Deacon , dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Lee Smith , linux-kselftest@vger.kernel.org, Vincenzo Frascino , Jacob Bramley , Leon Romanovsky , linux-rdma@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, Evgeniy Stepanov , linux-media@vger.kernel.org, Kees Cook , Ruben Ayrapetyan , Andrey Konovalov , Kevin Brodsky , Alex Williamson , Mauro Carvalho Chehab , Dmitry Vyukov , Kostya Serebryany , Greg Kroah-Hartman , Felix Kuehling , linux-kernel@vger.kernel.org, Jens Wiklander , Ramana Radhakrishnan , Alexander Deucher , Andrew Morton , Robin Murphy , Yishai Hadas , Luc Van Oostenryck Subject: Re: [PATCH v15 00/17] arm64: untag user pointers passed to the kernel Message-ID: <20190523165708.q6ru7xg45aqfjzpr@mbp> References: <20190517144931.GA56186@arrakis.emea.arm.com> <20190521184856.GC2922@ziepe.ca> <20190522134925.GV28398@e103592.cambridge.arm.com> <20190523002052.GF15389@ziepe.ca> <20190523104256.GX28398@e103592.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190523104256.GX28398@e103592.cambridge.arm.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 11:42:57AM +0100, Dave P Martin wrote: > On Wed, May 22, 2019 at 09:20:52PM -0300, Jason Gunthorpe wrote: > > On Wed, May 22, 2019 at 02:49:28PM +0100, Dave Martin wrote: > > > If multiple people will care about this, perhaps we should try to > > > annotate types more explicitly in SYSCALL_DEFINEx() and ABI data > > > structures. > > > > > > For example, we could have a couple of mutually exclusive modifiers > > > > > > T __object * > > > T __vaddr * (or U __vaddr) > > > > > > In the first case the pointer points to an object (in the C sense) > > > that the call may dereference but not use for any other purpose. > > > > How would you use these two differently? > > > > So far the kernel has worked that __user should tag any pointer that > > is from userspace and then you can't do anything with it until you > > transform it into a kernel something > > Ultimately it would be good to disallow casting __object pointers execpt > to compatible __object pointer types, and to make get_user etc. demand > __object. > > __vaddr pointers / addresses would be freely castable, but not to > __object and so would not be dereferenceable even indirectly. I think it gets too complicated and there are ambiguous cases that we may not be able to distinguish. For example copy_from_user() may be used to copy a user data structure into the kernel, hence __object would work, while the same function may be used to copy opaque data to a file, so __vaddr may be a better option (unless I misunderstood your proposal). We currently have T __user * and I think it's a good starting point. The prior attempt [1] was shut down because it was just hiding the cast using __force. We'd need to work through those cases again and rather start changing the function prototypes to avoid unnecessary casting in the callers (e.g. get_user_pages(void __user *) or come up with a new type) while changing the explicit casting to a macro where it needs to be obvious that we are converting a user pointer, potentially typed (tagged), to an untyped address range. We may need a user_ptr_to_ulong() macro or similar (it seems that we have a u64_to_user_ptr, wasn't aware of it). It may actually not be far from what you suggested but I'd keep the current T __user * to denote possible dereference. [1] https://lore.kernel.org/lkml/5d54526e5ff2e5ad63d0dfdd9ab17cf359afa4f2.1535629099.git.andreyknvl@google.com/ -- Catalin