Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1592056ybm; Thu, 23 May 2019 03:45:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTvBwsPNZdrpyWJjltF63Bf6D52TAw6ZmTyfyAdDt+W2TOz1kt33RMouJyLZ4tnULhK3uG X-Received: by 2002:a62:5e42:: with SMTP id s63mr100256030pfb.78.1558608348150; Thu, 23 May 2019 03:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558608348; cv=none; d=google.com; s=arc-20160816; b=XlCQevzGq51PJFS7/ULerjQbCFcSNsk9BjwwwrdGN/eyU28ReH+RgzfEOujXLR8pSB mUFq9xqTYxRsPhWq6JJmK8Wy8tzJ+HfcFClvp4Mt1AEXFvrbVdPhUxROZ6uEKT1Lo1i0 i36pqAlL/KWSJguG5/WKKBzo5qagiYxSXc9VuVjD4zu9VylkdpFv+8pS0eIEmXKEKYUM OFLgRsNhPCCHRV0kHQ2z+6YyOeTxgYzRVy3/FywHlfWMU3MZ9is9LIA8ahPLAB1Zs0Aq JaUBEDbd4Ea7TiLZSkkRjvLtFoWnhyjfks0Q24kjH38a2o83uRIK2Z6k4aOY2PMm2iGm wiww== 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=gU+3lqsoWF7Hzm+RBc+ukiaSDRZZ3u+etuBmqyigeJ4=; b=Mv3Cdv4WDPLMImVD7p6dWS3uc2DufbUxgvph/dKYFFPPpYVxcDRHfF3791gKjy6M2e GIV/QYp9Qo/Azj2HoUwUBkUyQHmkdXWiS4vlkxN0EE9ZdLMQsw+ZtdaF11ql7w+TzC9f OvCOtPTzh5TiCRjHotJHC3DBOKa+hF3yxe72pG0odf78mUoHGnjATvOIMveUtH1Eb0+F xvCP61AH89r129WpEhm7oKYIRBuHdinT2EjyFtFXsKfqcQ4W2qDK8caupblKNFDYbfdS 0q6Gmx+vagztlDxN+P/IDYiK2c9DmHr4IuUE3vb5U3hkWTGpHnNxDqnEgPmql2sxN0fu TBZw== 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 i38si30320679plb.132.2019.05.23.03.45.33; Thu, 23 May 2019 03:45:48 -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 S1730513AbfEWKnG (ORCPT + 99 others); Thu, 23 May 2019 06:43:06 -0400 Received: from foss.arm.com ([217.140.101.70]:43642 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727434AbfEWKnG (ORCPT ); Thu, 23 May 2019 06:43:06 -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 84A77341; Thu, 23 May 2019 03:43:05 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C9A023F718; Thu, 23 May 2019 03:42:59 -0700 (PDT) Date: Thu, 23 May 2019 11:42:57 +0100 From: Dave Martin To: Jason Gunthorpe Cc: Mark Rutland , kvm@vger.kernel.org, Christian Koenig , Szabolcs Nagy , Catalin Marinas , 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: <20190523104256.GX28398@e103592.cambridge.arm.com> References: <20190517144931.GA56186@arrakis.emea.arm.com> <20190521184856.GC2922@ziepe.ca> <20190522134925.GV28398@e103592.cambridge.arm.com> <20190523002052.GF15389@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190523002052.GF15389@ziepe.ca> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: > > On Tue, May 21, 2019 at 03:48:56PM -0300, Jason Gunthorpe wrote: > > > On Fri, May 17, 2019 at 03:49:31PM +0100, Catalin Marinas wrote: > > > > > > > The tagged pointers (whether hwasan or MTE) should ideally be a > > > > transparent feature for the application writer but I don't think we can > > > > solve it entirely and make it seamless for the multitude of ioctls(). > > > > I'd say you only opt in to such feature if you know what you are doing > > > > and the user code takes care of specific cases like ioctl(), hence the > > > > prctl() proposal even for the hwasan. > > > > > > I'm not sure such a dire view is warrented.. > > > > > > The ioctl situation is not so bad, other than a few special cases, > > > most drivers just take a 'void __user *' and pass it as an argument to > > > some function that accepts a 'void __user *'. sparse et al verify > > > this. > > > > > > As long as the core functions do the right thing the drivers will be > > > OK. > > > > > > The only place things get dicy is if someone casts to unsigned long > > > (ie for vma work) but I think that reflects that our driver facing > > > APIs for VMAs are compatible with static analysis (ie I have no > > > earthly idea why get_user_pages() accepts an unsigned long), not that > > > this is too hard. > > > > 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. Or that's the general idea. Figuring out a sane set of rules that we could actually check / enforce would require a bit of work. (Whether the __vaddr base type is a pointer or an integer type is probably moot, due to the restrictions we would place on the use of these anyway.) > > to tell static analysers the real type of pointers smuggled through > > UAPI disguised as other types (*cough* KVM, etc.) > > Yes, that would help alot, we often have to pass pointers through a > u64 in the uAPI, and there is no static checker support to make sure > they are run through the u64_to_user_ptr() helper. Agreed. Cheers ---Dave