Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1583628ybm; Tue, 21 May 2019 17:07:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjMm0xwY3gi23D3ay00E+VwUezOjBhwD1OOhqq3u0MgwRaafi+wft5S9CQgPjN0R7/sJf6 X-Received: by 2002:aa7:9afc:: with SMTP id y28mr91899457pfp.101.1558483624088; Tue, 21 May 2019 17:07:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558483624; cv=none; d=google.com; s=arc-20160816; b=EMbuCcB6IFK28bpM/6mBsgtWrsytS2iIFqz8SsC+hcDnrKvSgM2GzbCmOWJdCT/IiA n1o9Fn0f2tEjj8yAZWUozZnxsDlMKMxSJrBhqvFgYJWAN/AQjxC4W1ymbt++riKGlk37 g8H652e5/dNrb6klpCAIN1oXSmILDU1V32t1L2IjxmPfS+BeCM+1EZ8DURFFrz27FIcr nYMO9DNRHfrdlVNCHrOUSImddyeZ3LMZRYonpiCT1GU1fTxgYmcQzVBIunNgSod0eiJY GoBEy8eZ3mMELO3Gscs556x4y3muhKCykVZT/GIKT7lUNdVpq66Z6m7CfncO142aqQy5 QQNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=h+HMpjJbOByDkcgcmqTFcjwM/Zjfkc20s8NGwt76Mr8=; b=wA0e4nn2D4DgE3b7O0UlKTVWln9FNpnKjzm4LvP5kIPznaozcOK69lUjnGYwdSSP4O 6j3dCozkfr6PS5DR8l2rhTZj6SmdZ4ExacmKp326/boqduBmN1kZgxEu14ewvuaXBIE4 1Wwlp+Fwg8GE7XUjDN2NHAWo7jRdlXFGn4M/JGCzzPwdVtIaS30Y5QziK7BV48kHa9+E JafMOsj5KVIHj5Fggd2hJYnrBBcX1ymPIjZzqY7gp/Hm3EYCuOl9s46BsnFNMD9wEoWY RpRnaQDvrT3huU7bVVN/jPD7430XsT6Zy84dcUtZIsOEVyYaBEQYHHMymlfPq6S0kntO iyEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Zf9QLE33; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10si25809494pfc.55.2019.05.21.17.06.35; Tue, 21 May 2019 17:07:04 -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=@chromium.org header.s=google header.b=Zf9QLE33; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727816AbfEVAEn (ORCPT + 99 others); Tue, 21 May 2019 20:04:43 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41138 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726271AbfEVAEn (ORCPT ); Tue, 21 May 2019 20:04:43 -0400 Received: by mail-pf1-f196.google.com with SMTP id q17so286792pfq.8 for ; Tue, 21 May 2019 17:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=h+HMpjJbOByDkcgcmqTFcjwM/Zjfkc20s8NGwt76Mr8=; b=Zf9QLE33qmPluiR2OGF4dL2quucaUAVgN4YPizfJiTzAzfLxxGI5FlE9xizVc831A4 PZROfhtKhT/R7pMFQlHGrknlILzZeG3LHD5gyBNKzIo1iuXRcoC6OuM/wsNOYEBlL6Lp KGXm5hniO64celTxThJARG41BLIiM0pmyycsI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=h+HMpjJbOByDkcgcmqTFcjwM/Zjfkc20s8NGwt76Mr8=; b=gLBBKCMqjvZkTyccW35IkIT+/4DkMSXpYmUiIdtCHm6tKGsFEv4kyP67A+rJIvNsHs zLMKJ+wNULdeKXLqyYHkRzn1/6Chg2wETqUqK3nR794gRgXHCuaTza+531PaJPbGl/MM 4HlJOmzejjWmuwVPxH8f1TofX8QfVrVlmUGVpZKsLxMCGrdeUJyfHmNTIBTu0muaJlNm TT7FbcL8/sYoxjLamUWdWxe4poyAKv7zAJ6bMPcW/6BW3a1+nXCkMomg6Zrt/c+tvrST raa4Cvu6kQOEClgAT2BXuoiB7R0bR/D1l8fejZA6G6BHuPd8A+oTWjKZKV2eLVvTRt7R XZTA== X-Gm-Message-State: APjAAAV23ZdFEAvv5pkldg5Ba1e1VO4QUizqjiTHRypvGDhkomxGw/Op WqNaKGenEDnXf8wRwg0UKhfRnQ== X-Received: by 2002:a63:8dc8:: with SMTP id z191mr87505404pgd.9.1558483482349; Tue, 21 May 2019 17:04:42 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a11sm15675685pff.128.2019.05.21.17.04.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 May 2019 17:04:40 -0700 (PDT) Date: Tue, 21 May 2019 17:04:39 -0700 From: Kees Cook To: Catalin Marinas Cc: Evgenii Stepanov , Andrey Konovalov , Khalid Aziz , 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 , 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 Subject: Re: [PATCH v15 00/17] arm64: untag user pointers passed to the kernel Message-ID: <201905211633.6C0BF0C2@keescook> References: <20190517144931.GA56186@arrakis.emea.arm.com> <20190521182932.sm4vxweuwo5ermyd@mbp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190521182932.sm4vxweuwo5ermyd@mbp> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 21, 2019 at 07:29:33PM +0100, Catalin Marinas wrote: > On Mon, May 20, 2019 at 04:53:07PM -0700, Evgenii Stepanov wrote: > > On Fri, May 17, 2019 at 7:49 AM Catalin Marinas wrote: > > > IMO (RFC for now), I see two ways forward: > > > [...] > > > 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). > > > > 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. > > It's also the fact such patch would go unnoticed for a long time until > someone exercises that code path. And when they do, the user would be > pretty much in the dark trying to figure what what went wrong, why a > SIGSEGV or -EFAULT happened. What's worse, we can't even say we fixed > all the places where it matters in the current kernel codebase (ignoring > future patches). So, looking forward a bit, this isn't going to be an ARM-specific issue for long. In fact, I think we shouldn't have arm-specific syscall wrappers in this series: I think untagged_addr() should likely be added at the top-level and have it be a no-op for other architectures. So given this becoming a kernel-wide multi-architecture issue (under the assumption that x86, RISC-V, and others will gain similar TBI or MTE things), we should solve it in a way that we can re-use. We need something that is going to work everywhere. And it needs to be supported by the kernel for the simple reason that the kernel needs to do MTE checks during copy_from_user(): having that information stripped means we lose any userspace-assigned MTE protections if they get handled by the kernel, which is a total non-starter, IMO. As an aside: I think Sparc ADI support in Linux actually side-stepped this[1] (i.e. chose "solution 1"): "All addresses passed to kernel must be non-ADI tagged addresses." (And sadly, "Kernel does not enable ADI for kernel code.") I think this was a mistake we should not repeat for arm64 (we do seem to be at least in agreement about this, I think). [1] https://lore.kernel.org/patchwork/patch/654481/ > > 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. > > Would the kernel also catch up with providing a stable ABI? Because we > have two moving targets. > > On one hand, you have Android or some Linux distro that stick to a > stable kernel version for some time, so they have better chance of > clearing most of the problems. On the other hand, we have mainline > kernel that gets over 500K lines every release. As maintainer, I can't > rely on my testing alone as this is on a limited number of platforms. So > my concern is that every kernel release has a significant chance of > breaking the ABI, unless we have a better way of identifying potential > issues. I just want to make sure I fully understand your concern about this being an ABI break, and I work best with examples. The closest situation I can see would be: - some program has no idea about MTE - malloc() starts returning MTE-tagged addresses - program doesn't break from that change - program uses some syscall that is missing untagged_addr() and fails - kernel has now broken userspace that used to work The trouble I see with this is that it is largely theoretical and requires part of userspace to collude to start using a new CPU feature that tickles a bug in the kernel. As I understand the golden rule, this is a bug in the kernel (a missed ioctl() or such) to be fixed, not a global breaking of some userspace behavior. I feel like I'm missing something about this being seen as an ABI break. The kernel already fails on userspace addresses that have high bits set -- are there things that _depend_ on this failure to operate? -- Kees Cook