Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3988791yba; Mon, 29 Apr 2019 11:49:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUf6g6ObUNUPKbD/F2GQL+jtcj3h/saDHAaWXr5+8HAJ1Y1Su2UkpaedorWHbUMfihExKF X-Received: by 2002:a63:f707:: with SMTP id x7mr60152223pgh.343.1556563769765; Mon, 29 Apr 2019 11:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556563769; cv=none; d=google.com; s=arc-20160816; b=pBlTZSM9aZo9k+YwSIY0v1GRgDJoA/OgUWpQPWBcf6ZR92oaFWhol6NN/JR08s5OZS y+7UwFAzH6I52CqQltydtCNiFKjm/E3WuisBPoP4J+ZvyoaL2MYXB1hejmdc5WFb9pwK L2WJT6gT8R0SsG41bsZAnP2j4myDHcVhbM87BoZNGzUObUcNLX16eEXxoKGdy3eNos5P 2V639bPh+pyPge5iyl/p5Xsguy2UJ0jeQJCZBtliyLHpeZ0qyH/355v+3oUuHedoq6QQ TsO+/HsI8X8qwOI45SqKyIzccPRhmsBFtagF113O+lKX9EekquczlOpSf8OkV/V7wyPW 4Tdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1ru3TU3hV7O6QI0KEdTCu1He3w17tDE27Luu9bBISac=; b=zWVAsTssKfDZSFdSZgYP4ZOwiXjrCJVHOkDnI0iivKuW6lpzvpiKXFmbHNTipN7Ugu 7F+zv/qjo8pf38MDlZnN0WapJxKuO7nlWtNTWIj6o2UR5XoBdFmIENF1D/VI/sQNrk8W 8o89p8JKOJgT7xUbsLJ1eACb6uiLI7vyc9WlagGeIn4AfPcvXqGim5LxkFspbxCLXYPv 9XusXGAX63Js1jBFTJyMqM9/mnVJFUzzw7PecJluBBBo9fTcIFbHSE1NozJTK0zSQTnG ZL/fEvovhieE7tA6ZH/3qFb5LH++hLmjRCj38ccxQWnuF+Scanyz6zX95Ym3VqE25eGn 7kTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qZhWW23M; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6si14046495pfi.221.2019.04.29.11.49.14; Mon, 29 Apr 2019 11:49:29 -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=@kernel.org header.s=default header.b=qZhWW23M; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729217AbfD2Sqq (ORCPT + 99 others); Mon, 29 Apr 2019 14:46:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:48348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728964AbfD2Sqm (ORCPT ); Mon, 29 Apr 2019 14:46:42 -0400 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CA6C72067D for ; Mon, 29 Apr 2019 18:46:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556563602; bh=5j9NYksW1sFn4p0aXlHqBk4ZUKpOJxf0zYGvnIwtNvc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=qZhWW23MUGLTV1xDSbhGdYBi6Ok9eRCtMr6n1nCokzoNuWw+9JeXnf0EsGO5F7NPs X/PCZ9IWwRrVbLTkCL6BKXV1vMIK6WcURuaT7A0Eytq62xoVYAimqpRqwRhoVV6Fhb IpNjeuR9wz20QmsqdP9Eh/9sJy8bSiXE5p2BlFOU= Received: by mail-wr1-f45.google.com with SMTP id h4so17536587wre.7 for ; Mon, 29 Apr 2019 11:46:41 -0700 (PDT) X-Gm-Message-State: APjAAAUUHFLOaH5ieVKB4veWfM+/okvPhFLKvq7SHQP6BShqJxcF8406 PuivpmyQzBZyGFcECmSgqW/AsSPaearVFZAgALXOuQ== X-Received: by 2002:a5d:424e:: with SMTP id s14mr18705438wrr.77.1556563600428; Mon, 29 Apr 2019 11:46:40 -0700 (PDT) MIME-Version: 1.0 References: <1556228754-12996-1-git-send-email-rppt@linux.ibm.com> <1556228754-12996-3-git-send-email-rppt@linux.ibm.com> <20190426083144.GA126896@gmail.com> <20190426095802.GA35515@gmail.com> <20190427084752.GA99668@gmail.com> <20190427104615.GA55518@gmail.com> In-Reply-To: <20190427104615.GA55518@gmail.com> From: Andy Lutomirski Date: Mon, 29 Apr 2019 11:46:28 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 2/7] x86/sci: add core implementation for system call isolation To: Ingo Molnar Cc: Andy Lutomirski , Mike Rapoport , LKML , Alexandre Chartre , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , James Bottomley , Jonathan Adams , Kees Cook , Paul Turner , Peter Zijlstra , Thomas Gleixner , Linux-MM , LSM List , X86 ML , Linus Torvalds , Peter Zijlstra , Andrew Morton Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 27, 2019 at 3:46 AM Ingo Molnar wrote: > > > * Ingo Molnar wrote: > > > * Andy Lutomirski wrote: > > > > > > And no, I'm not arguing for Java or C#, but I am arguing for a sane= r > > > > version of C. > > > > > > IMO three are three credible choices: > > > > > > 1. C with fairly strong CFI protection. Grsecurity has this (supposed= ly > > > =E2=80=94 there=E2=80=99s a distinct lack of source code available), = and clang is > > > gradually working on it. > > > > > > 2. A safe language for parts of the kernel, e.g. drivers and maybe > > > eventually filesystems. Rust is probably the only credible candidate= . > > > Actually creating a decent Rust wrapper around the core kernel > > > facilities would be quite a bit of work. Things like sysfs would be > > > interesting in Rust, since AFAIK few or even no drivers actually get > > > the locking fully correct. This means that naive users of the API > > > cannot port directly to safe Rust, because all the races won't compil= e > > > :) > > > > > > 3. A sandbox for parts of the kernel, e.g. drivers. The obvious > > > candidates are eBPF and WASM. > > > > > > #2 will give very good performance. #3 gives potentially stronger > > > protection against a sandboxed component corrupting the kernel overal= l, > > > but it gives much weaker protection against a sandboxed component > > > corrupting itself. > > > > > > In an ideal world, we could do #2 *and* #3. Drivers could, for > > > example, be written in a language like Rust, compiled to WASM, and ru= n > > > in the kernel. > > > > So why not go for #1, which would still outperform #2/#3, right? Do we > > know what it would take, roughly, and how the runtime overhead looks > > like? > > BTW., CFI protection is in essence a compiler (or hardware) technique to > detect stack frame or function pointer corruption after the fact. > > So I'm wondering whether there's a 4th choice as well, which avoids > control flow corruption *before* it happens: > > - A C language runtime that is a subset of current C syntax and > semantics used in the kernel, and which doesn't allow access outside > of existing objects and thus creates a strictly enforced separation > between memory used for data, and memory used for code and control > flow. > > - This would involve, at minimum: > > - tracking every type and object and its inherent length and valid > access patterns, and never losing track of its type. > > - being a lot more organized about initialization, i.e. no > uninitialized variables/fields. > > - being a lot more strict about type conversions and pointers in > general. You're not the only one to suggest this. There are at least a few things that make this extremely difficult if not impossible. For example, consider this code: void maybe_buggy(void) { int a, b; int *p =3D &a; int *q =3D (int *)some_function((unsigned long)p); *q =3D 1; } If some_function(&a) returns &a, then all is well. But if some_function(&a) returns &b or even a valid address of some unrelated kernel object, then the code might be entirely valid and correct C, but I don't see how the runtime checks are supposed to tell whether the resulting address is valid or is a bug. This type of code is, I think, quite common in the kernel -- it happens in every data structure where we have unions of pointers and integers or where we steal some known-zero bits of a pointer to store something else. --Andy