Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4295309imm; Tue, 11 Sep 2018 09:42:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYogZmNEFyxx5D5rVdr0MvC/+Y2brLpG6YZLVvK863zS1GVm092cLNy8VlLLEybGPK0l/aY X-Received: by 2002:a62:da0b:: with SMTP id c11-v6mr30493589pfh.68.1536684167195; Tue, 11 Sep 2018 09:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536684167; cv=none; d=google.com; s=arc-20160816; b=LuxAfN3c2tYSDfolZ+hO2EFF5HEQ+yU6VAp2Gz0/84BpIXboX9SXvuXKxpqJ4V9MvD 6vC1CQIzkFkSJUVBHzrYe/pyCQeh+Q6n4nEZHYdaTk3S+V6pC68GVDBf2S6YQmPqUPJY bf/WHho2sRPwYLR/OaGozi5pUNV3ysTeWbooKSKgDdYFK7WxqjYljLcfrigbyGwO/zSU 2eA5rNl7Q0p/nxCqCu4EPeYTTfcPG6emtfdORKwGsfCoYEpzS3QUGKbkvYDl4Lu20HCD 3hsx5Y3tab+emA8HhYIDRdPzJi6K3ztTTARCk087hzEZgVaJDuJVP7JkkLCnbF05cOO+ 949A== 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=/8ApiPb7VYEuJWErCmQPAQ6X+2Q/cR6QG34NT1q6ciE=; b=I1FlAL1S0qHzbL5H19g5Xvp6vSePex5Ri8N5QlK9CdW/5p+RIc6UQJV/zz45wviaxr ZKuzkEKPYid+WdNSooh1xJCDTMSo1biRNS5rCVeqjakB6MVcHy8YkFX2hYTAMVISxCqD 0r3wTkBmLexXzClTe49jYWSGKQVF9ixvMJGiwx9JCgotToFbojRnXnmY0DkuWSwIlRAl qOtffuzs0F/YtHc7l+Td8F+0zpJMBGUYInYuXq9eEy3FVap3etp7icSa/qlzyeWBEhSC qmh0+JKmoAKrIhbOUw0eClw8/RhgEXf4JGn1suTI9DDv0GG787IlGPVOwsMzE9mLjPQk GTvg== 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 m61-v6si19902932plb.296.2018.09.11.09.42.31; Tue, 11 Sep 2018 09:42:47 -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 S1728080AbeIKVmI (ORCPT + 99 others); Tue, 11 Sep 2018 17:42:08 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:46550 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726800AbeIKVmH (ORCPT ); Tue, 11 Sep 2018 17:42:07 -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 44C227A9; Tue, 11 Sep 2018 09:42:00 -0700 (PDT) Received: from arrakis.emea.arm.com (arrakis.Emea.Arm.com [10.4.12.132]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D13A43F703; Tue, 11 Sep 2018 09:41:55 -0700 (PDT) Date: Tue, 11 Sep 2018 17:41:53 +0100 From: Catalin Marinas To: Linus Torvalds Cc: Mark Rutland , Kate Stewart , "open list:DOCUMENTATION" , Will Deacon , linux-mm , "open list:KERNEL SELFTEST FRAMEWORK" , cpandya@codeaurora.org, Shuah Khan , Ingo Molnar , linux-arch , Jacob Bramley , linux-arm-kernel , Evgenii Stepanov , Kees Cook , Ruben.Ayrapetyan@arm.com, Andrey Konovalov , Lee Smith , Al Viro , Dmitry Vyukov , Kostya Serebryany , Greg Kroah-Hartman , Linux Kernel Mailing List , Ramana Radhakrishnan , Andrew Morton , Robin Murphy , "Kirill A. Shutemov" Subject: Re: [PATCH v6 11/11] arm64: annotate user pointers casts detected by sparse Message-ID: <20180911164152.GA29166@arrakis.emea.arm.com> References: <5d54526e5ff2e5ad63d0dfdd9ab17cf359afa4f2.1535629099.git.andreyknvl@google.com> <20180907152600.myidisza5o4kdmvf@armageddon.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Linus, On Fri, Sep 07, 2018 at 09:30:35AM -0700, Linus Torvalds wrote: > On Fri, Sep 7, 2018 at 8:26 AM Catalin Marinas wrote: > > So it's not about casting to another pointer; it's rather about no > > longer using the value as a user pointer but as an actual (untyped, > > untagged) virtual address. [...] > I actually originally wanted to have sparse not just check types, but > actually do transformations too, in order to check more. [...] > But it sounds like this is exactly what you guys would want for the > tagged pointers. Some functions can take a "wild" pointer, because > they deal with the tag part natively. And others need to be "checked" > and have gone through the cleaning and verification. > > But sparse is sadly not the right tool for this, and having a single > "__user" address space is not sufficient. I guess for the arm64 case, > you really could make up a *new* address space: "__user_untagged", and > then have functions that convert from "void __user *" to "void > __user_untagged *", and then mark the functions that need the tag > removed as taking that new kind of user pointer. Fortunately, most (all) functions taking a __user pointer can cope with tagged pointers since they never dereference the pointer directly but pass it through uaccess functions (which can access tagged pointers without untagging). The problem appears when the pointer is no longer used for access but converted to a long for other uses like rbtree look-up, so not actually dereferenced. Such conversion, in a few cases, needs to lose the tag. Of course, there are lots of void __user * conversions to long where removing the tag is not always the right thing or required (hence the __force annotations in this patchset). As Luc mentioned in this thread, we can consider that __user pointers are always tagged. What I think we'd need is a few annotations where ulong must be an __untagged address (and I guess in smaller numbers than the __force ones proposed here). For example we can allow get_user_pages() to get an (ulong)(void __user *) conversion but find_vma() would only take an (unsigned long __untagged) argument. Such attribute conversion would be handled by an untagged_addr() macro. So we move the detection problem from pointer conversion to an ulong (tagged by default) to ulong __untagged conversion (I'm not sure sparse can do this). That's slightly different than trying to identify all the __user ptr to long conversions but, as you said, it's probably not a complete solution anyway and with lots of __force annotations throughout the kernel. -- Catalin