Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp311281ybm; Mon, 20 May 2019 16:55:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5DT7B965PXUmmL6aroFZZOrwy+u/J0mpqlSV6DDJuD8OwCMyeSvxj4eAxMLLNNRCVCocV X-Received: by 2002:a17:902:704c:: with SMTP id h12mr23932290plt.65.1558396519165; Mon, 20 May 2019 16:55:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558396519; cv=none; d=google.com; s=arc-20160816; b=x5ceEJyS/XCC02DMU8iY1K5UbffcGXe3uQyF71aRcwqjdWaAg9p85jDrW3GhFhPQGm yX/kVruxUh4tVGCzv5RpnSjzuLtntqc6VjRY/CVqDJg4t03wYJAjH+c8bgRVZWbj5Sco ylm5q2w/ymWAlf9PIBVj3dJEYzFutzRxtpKIpNIFY4zidakCrsL/0KDgvFzFEYlTPOSV TKsuKV+bJ68OXXL+qSI5sbbCS3OPwnuur0lNJjiSMAHFB+BzPLlo1+HSqPBUE4jjeAo1 9H/fmNVdh0d+qGFv6oJ0Vi2OyUMR65QvnpscdpQ8XRdoFP/Gkwr4yDcwxSap9LydAJ9s +DcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=DOow0La3W2Essx5H031uTOWFbAnDcBGJlXVfamcoL3w=; b=E8oDUEcxD7gUsEtrQxeR15MFcAgK+oyYZ4dDwCwBg4NA9QAUqpwZm9Z8Bi3APy8cB5 4eBXFsc/kJwlucA4DvYgOsEaJ87OLtql4riNs/yJxncPNQawOKtZ3iU25pkp6nCdSOd0 o5WJMnts5rNysPBdlcXtypPwvVItueBA+p1cgHLiFygYO3gV1ck7XNEUb+5SsozyQ4tc elpwugJVvxhjnNhzvQltLOCGxcjJ4nRViqcycCkTjC119LgUhYH84dvrsTL47/q6GVkE Zru6qi0e8s0vN97cPlvsKO3+nidoluaUgpFaEYWFVrrFJMDjKFEPs6kjwuNEOt1boesh 5jOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Dx4+lU9j; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p91si17853478plb.165.2019.05.20.16.55.03; Mon, 20 May 2019 16:55:19 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=Dx4+lU9j; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727685AbfETXxb (ORCPT + 99 others); Mon, 20 May 2019 19:53:31 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:43661 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727414AbfETXxU (ORCPT ); Mon, 20 May 2019 19:53:20 -0400 Received: by mail-vs1-f67.google.com with SMTP id d128so10039184vsc.10 for ; Mon, 20 May 2019 16:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DOow0La3W2Essx5H031uTOWFbAnDcBGJlXVfamcoL3w=; b=Dx4+lU9jqXDtln/17Mrd8EV4Dxp/5zASL+1Y8Niio9Pqb06rC0aI8wedP3ohgziyEW jppEZzDyXiAo/njLuzUnS0cZqB4tlCDf5SInO7A6W3spDccr9FtwpNa39rs9vTjn9Pol gFjx66w14oqATAsCg/4xevDnAIAQo2Q0YzZMa3Njt5yFKOelm+SuxVUsWhk4woonxC/+ 9D5FC/UAWBXCau72ARfrLZBFx2zGvzGs/3QYXrUb8NFYR9FnDOYRxbwkdocqirkPGsSw AxoIYh3MeUP070fRiIy388VcetefsVsnX0FjFahzGTgGe2zBg5LkCE8dqpCaiB/D65kK 79Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DOow0La3W2Essx5H031uTOWFbAnDcBGJlXVfamcoL3w=; b=tPlH4TmljhrNeGmnfpyeEDiCcfTMWVz8tRDJAZ2QEo+ppeEwg0YvJXr8rfyd5top95 h5y4rQLkZXHJmyYHjWyd+lC0MG85+nnBIox9ZsfxDix6GNiqGuFCV7uttWqmvSqn17p5 7wHwQkf5ejpuZ3lA0W7KByL++0UBabosYbOL1TqObpU+O84UjtT9jEMuhBG2qp5myqzi rA+qXH3UeYg2MI6QcTzfmGIEiCHh75P5yhGYIEv5n3lGt1YLkLdjeS4TQ65ibSPuVqB+ PWioQ9aNd6f/UP7xK6RIZ86PjqrPfADYTWxyETRECCCc9kqFjDwgrO9mGmYT+Kdsb8uS J/ag== X-Gm-Message-State: APjAAAUfWOm0z94zZj3//SRTcH9jcifjqmvbw1C3AVqrdiCOkKgdq3V2 MKKIM8NE2w30afkj9akgsI5XafOKqGu+yEt40sL1Ximf/YIj2Q== X-Received: by 2002:a67:be17:: with SMTP id x23mr26047761vsq.173.1558396399029; Mon, 20 May 2019 16:53:19 -0700 (PDT) MIME-Version: 1.0 References: <20190517144931.GA56186@arrakis.emea.arm.com> In-Reply-To: <20190517144931.GA56186@arrakis.emea.arm.com> From: Evgenii Stepanov Date: Mon, 20 May 2019 16:53:07 -0700 Message-ID: Subject: Re: [PATCH v15 00/17] arm64: untag user pointers passed to the kernel To: Catalin Marinas Cc: Andrey Konovalov , Linux ARM , Linux Memory Management List , LKML , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, kvm@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" , Vincenzo Frascino , Will Deacon , Mark Rutland , Andrew Morton , Greg Kroah-Hartman , Kees Cook , Yishai Hadas , Felix Kuehling , Alexander Deucher , Christian Koenig , Mauro Carvalho Chehab , Jens Wiklander , Alex Williamson , Leon Romanovsky , Dmitry Vyukov , Kostya Serebryany , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Robin Murphy , Luc Van Oostenryck , Dave Martin , Kevin Brodsky , Szabolcs Nagy , Elliott Hughes Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 17, 2019 at 7:49 AM Catalin Marinas wrote: > > Hi Andrey, > > On Mon, May 06, 2019 at 06:30:46PM +0200, Andrey Konovalov wrote: > > One of the alternative approaches to untagging that was considered is to > > completely strip the pointer tag as the pointer enters the kernel with > > some kind of a syscall wrapper, but that won't work with the countless > > number of different ioctl calls. With this approach we would need a custom > > wrapper for each ioctl variation, which doesn't seem practical. > > The more I look at this problem, the less convinced I am that we can > solve it in a way that results in a stable ABI covering ioctls(). While > for the Android kernel codebase it could be simpler as you don't upgrade > the kernel version every 2.5 months, for the mainline kernel this > doesn't scale. Any run-time checks are relatively limited in terms of > drivers covered. Better static checking would be nice as a long term > solution but we didn't get anywhere with the discussion last year. > > IMO (RFC for now), I see two ways forward: > > 1. Make this a user space problem and do not allow tagged pointers into > the syscall ABI. A libc wrapper would have to convert structures, > parameters before passing them into the kernel. Note that we can > still support the hardware MTE in the kernel by enabling tagged > memory ranges, saving/restoring tags etc. but not allowing tagged > addresses at the syscall boundary. > > 2. Similar shim to the above libc wrapper but inside the kernel > (arch/arm64 only; most pointer arguments could be covered with an > __SC_CAST similar to the s390 one). There are two differences from > what we've discussed in the past: > > a) this is an opt-in by the user which would have to explicitly call > prctl(). If it returns -ENOTSUPP etc., the user won't be allowed > to pass tagged pointers to the kernel. This would probably be the > responsibility of the C lib to make sure it doesn't tag heap > allocations. If the user did not opt-in, the syscalls are routed > through the normal path (no untagging address shim). > > b) ioctl() and other blacklisted syscalls (prctl) will not accept > tagged pointers (to be documented in Vicenzo's ABI patches). > > It doesn't solve the problems we are trying to address but 2.a saves us > from blindly relaxing the ABI without knowing how to easily assess new > code being merged (over 500K lines between kernel versions). Existing > applications (who don't opt-in) won't inadvertently start using the new > ABI which could risk becoming de-facto ABI that we need to support on > the long run. > > Option 1 wouldn't solve the ioctl() problem either and while it makes > things simpler for the kernel, I am aware that it's slightly more > complicated in user space (but I really don't mind if you prefer option > 1 ;)). > > 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. > > Comments welcomed. Any userspace shim approach is problematic for Android because of the apps that use raw system calls. AFAIK, all apps written in Go are in that camp - I'm not sure how common they are, but getting them all recompiled is probably not realistic. The way I see it, a patch that breaks handling of tagged pointers is not that different from, say, a patch that adds a wild pointer dereference. Both are bugs; the difference is that (a) the former breaks a relatively uncommon target and (b) it's arguably an easier mistake to make. If MTE adoption goes well, (a) will not be the case for long. This is a bit of a chicken-and-egg problem. In a world where memory allocators on one or several popular platforms generate pointers with non-zero tags, any such breakage will be caught in testing. Unfortunately to reach that state we need the kernel to start accepting tagged pointers first, and then hold on for a couple of years until userspace catches up. Perhaps we can start by whitelisting ioctls by driver?