Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2667752ybi; Sat, 1 Jun 2019 22:10:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaRDYkoVqQE/6b+ivn+lcfQVxjZWBqDJUKyZ+JU80YQMOtoEJaU6jQC5SHQ9j6P53sCx1n X-Received: by 2002:a17:90a:d3c7:: with SMTP id d7mr6106204pjw.1.1559452222153; Sat, 01 Jun 2019 22:10:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559452222; cv=none; d=google.com; s=arc-20160816; b=ks2QF70YiHrRx5IZtAG3jfGy5hdNhG3UIPzB2+Jv2ucwrxfz1Cbb1ezdjBr4DxahjK 22cJHtlnlIqFtaNdLI6PaauGZZ8REN49wQE38bCZYvgnPQsAljuAoKxpanlhi13miH0e B5V+/HoP/mkb3h4doIX0fITr3X0XBQLR89EHmxsDzyjpGycpczIaID+dV5vGtw7XHNbj 1nVv6e5q38DAuFzICvoW986JGeAXJr/B4eOUNTp26Qdk16HzIrYf71qCMH52ux2ug2XE WJcoMuC/CLlGBxu5jfiRGx+t/gFgZUneKPmZ/WrT2y2KC0JsGrciJpsEgkwHevktpAHO AcNA== 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=8FrEn8Oc47oyqvsIyUn+ei84DckXK5ddHX1nKUOQVF0=; b=ERbaDUxZDGU+/WX8Qe8m1kSAQN0AQlConNW2xcEEpoq/Hp4HRswyAKW6eKBPL9HNyC gyZB3nIMiYJlLlyiP6ZXDxLNsOzTCUA19JJEwelmO7+tfxQ8jjZh9e4W8cFJI0ic8UJP 2Y4BAFgE9qOnCXxOXz3C4nG5bAwJ8qFR+RWwom/bGdq1gs7S54LPCkXHV2HP3HtV0dSU j0hm9z+laUK+CZXGelLUilxQi127MAIR8xbQB9y5RYtqIc4JQ+x4gkA/iJkhGN5djZB1 emLLz2kteoEOeGnemxanhvCAVgWg8+ZyltrssI7y/R6qREq5/tpUQJqbO6i4SofHowyD Qolw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=I+l433GU; 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 k136si10114864pgc.401.2019.06.01.22.09.34; Sat, 01 Jun 2019 22:10:22 -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=I+l433GU; 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 S1726084AbfFBFGO (ORCPT + 99 others); Sun, 2 Jun 2019 01:06:14 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36908 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbfFBFGO (ORCPT ); Sun, 2 Jun 2019 01:06:14 -0400 Received: by mail-pg1-f193.google.com with SMTP id 20so6338889pgr.4 for ; Sat, 01 Jun 2019 22:06:13 -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=8FrEn8Oc47oyqvsIyUn+ei84DckXK5ddHX1nKUOQVF0=; b=I+l433GU6rh5Vh+cXRg2sWftONjf5E0xtYRJR0maMC3On194A0XuFQ8es0fmdrLaO4 QMulbFvcAdi+pOn8HpskX0ufgW7qoStMxwwMGtpoIzBLU8ImYfubQhLJZlu5J4RYe6TO Yim8ter4osHiihcYza518LDlKNV+048cHSWMc= 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=8FrEn8Oc47oyqvsIyUn+ei84DckXK5ddHX1nKUOQVF0=; b=ZJ+lJdc/A3sG97aoYifQw2cihVoqHTOvOH3rD8yPALqmBlLRy8rBKGc7VgDz/cbb+x 6OEHFQwBPKOu4OYOA/s2zlh9ZJiOTlRL6YE1OzWaU1RkCUVSDuOMypzNpTuik3hvKAhe YgrM1S4ueY8uoJ3mLA8htMW9+0OoVFVVQBYV4rSg0AiG+Pd3hZbizVK24jJ7sak8JBY7 kmCV+2y06HeY5W87OGKzYgI/jPBUFBxLB7W2VXEgN2SWaJxizfljyqWAhWpGccMFMGLU z8ckAvfzbFMzgKvYZluFh86VILA9VD2EQCy380bq5h+LEwitqa/PewJleHaeK8UZrs9a sWbg== X-Gm-Message-State: APjAAAVQsTKO/O2aHiC8wJcTDiu/ZW7q96jAE9Ew1hj/wprmqyTThWch +4Rg+fbB744kMLhFqCXFU/BbUw== X-Received: by 2002:a65:520b:: with SMTP id o11mr20347226pgp.184.1559451973138; Sat, 01 Jun 2019 22:06:13 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x28sm12472404pfo.78.2019.06.01.22.06.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Jun 2019 22:06:12 -0700 (PDT) Date: Sat, 1 Jun 2019 22:06:10 -0700 From: Kees Cook To: Catalin Marinas Cc: enh , 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 Subject: Re: [PATCH v15 00/17] arm64: untag user pointers passed to the kernel Message-ID: <201906012156.55E2C45@keescook> References: <201905211633.6C0BF0C2@keescook> <20190522101110.m2stmpaj7seezveq@mbp> <20190522163527.rnnc6t4tll7tk5zw@mbp> <201905221316.865581CF@keescook> <20190523144449.waam2mkyzhjpqpur@mbp> <201905230917.DEE7A75EF0@keescook> <20190523174345.6sv3kcipkvlwfmox@mbp> <201905231327.77CA8D0A36@keescook> <20190528170244.GF32006@arrakis.emea.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190528170244.GF32006@arrakis.emea.arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 28, 2019 at 06:02:45PM +0100, Catalin Marinas wrote: > On Thu, May 23, 2019 at 02:31:16PM -0700, Kees Cook wrote: > > syzkaller already attempts to randomly inject non-canonical and > > 0xFFFF....FFFF addresses for user pointers in syscalls in an effort to > > find bugs like CVE-2017-5123 where waitid() via unchecked put_user() was > > able to write directly to kernel memory[1]. > > > > It seems that using TBI by default and not allowing a switch back to > > "normal" ABI without a reboot actually means that userspace cannot inject > > kernel pointers into syscalls any more, since they'll get universally > > stripped now. Is my understanding correct, here? i.e. exploiting > > CVE-2017-5123 would be impossible under TBI? > > > > If so, then I think we should commit to the TBI ABI and have a boot > > flag to disable it, but NOT have a process flag, as that would allow > > attackers to bypass the masking. The only flag should be "TBI or MTE". > > > > If so, can I get top byte masking for other architectures too? Like, > > just to strip high bits off userspace addresses? ;) > > Just for fun, hack/attempt at your idea which should not interfere with > TBI. Only briefly tested on arm64 (and the s390 __TYPE_IS_PTR macro is > pretty weird ;)): OMG, this is amazing and bonkers. I love it. > --------------------------8<--------------------------------- > diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h > index 63b46e30b2c3..338455a74eff 100644 > --- a/arch/s390/include/asm/compat.h > +++ b/arch/s390/include/asm/compat.h > @@ -11,9 +11,6 @@ > > #include > > -#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p( \ > - typeof(0?(__force t)0:0ULL), u64)) > - > #define __SC_DELOUSE(t,v) ({ \ > BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \ > (__force t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \ > diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h > index e2870fe1be5b..b1b9fe8502da 100644 > --- a/include/linux/syscalls.h > +++ b/include/linux/syscalls.h > @@ -119,8 +119,15 @@ struct io_uring_params; > #define __TYPE_IS_L(t) (__TYPE_AS(t, 0L)) > #define __TYPE_IS_UL(t) (__TYPE_AS(t, 0UL)) > #define __TYPE_IS_LL(t) (__TYPE_AS(t, 0LL) || __TYPE_AS(t, 0ULL)) > +#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0 ? (__force t)0 : 0ULL), u64)) > #define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a > +#ifdef CONFIG_64BIT > +#define __SC_CAST(t, a) (__TYPE_IS_PTR(t) \ > + ? (__force t) ((__u64)a & ~(1UL << 55)) \ > + : (__force t) a) > +#else > #define __SC_CAST(t, a) (__force t) a > +#endif > #define __SC_ARGS(t, a) a > #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long)) I'm laughing, I'm crying. Now I have to go look at the disassembly to see how this actually looks. (I mean, it _does_ solve my specific case of the waitid() flaw, but wouldn't help with pointers deeper in structs, etc, though TBI does, I think still help with that. I have to catch back up on the thread...) Anyway, if it's not too expensive it'd block reachability for those kinds of flaws. I wonder what my chances are of actually getting this landed? :) (Though, I guess I need to find a "VA width" macro instead of a raw 55.) Thanks for thinking of __SC_CAST() and __TYPE_IS_PTR() together. Really made my day. :) -- Kees Cook