Received: by 10.213.65.68 with SMTP id h4csp3631409imn; Tue, 3 Apr 2018 08:13:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/vOTBaAMmcy2S3BgfC0s8IY2cpr6k/h13Hn9Xu2wyQdeCP0ZsWZrph6G7yUqbqoy6Gm22z X-Received: by 2002:a17:902:6b01:: with SMTP id o1-v6mr14301790plk.350.1522768380348; Tue, 03 Apr 2018 08:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522768380; cv=none; d=google.com; s=arc-20160816; b=dftyKCAQ4CHW3kEqpeiz0EGmIn3hKHHCDKWaOQO6XfkAEZ6PkHXuVIk30g7t3zWiag XbkiY6snued9LekhU0VOKF/gWfU8DsnZaInefaoYJ6cAjOdv9MIUUVQxQnzhelg/R25H reJJcDJp8NYvDBbry+e0BhNLpxEULbxrD2sge1+ackAf/cOIaMG4PShF9ofTFmsSZOHy jJjoV7Os4YrvX/3QDFFUDz/1V1G/u/R6Rfa0ijyrtCDC0qSnyLcNlLWzGULos8qBsdGh 7UBuN1DBGoCRVIVAGYfYEG3aF+4NpD1lXkfy/SqHRWqFfo8Nb/1eTfAPVR27FEVRs4K0 dRCA== 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 :references:in-reply-to:mime-version:dmarc-filter :arc-authentication-results; bh=3N7lrS69SQNfSXwaDyJUlg7/aUdqTjWCDxZBByncAVM=; b=GEhC/Wq3dlhRo1Nf5JlZmJimJUxgEXC4+MdeNtwOH939VbRW3iTx92ejqLvnrAHOH6 R3uz+PGI3B+CiYXxmM0vbAChkyONMbcZ7YHdo9upGx2jP7mlYGMAvJJWBKLv60kAgfXt 6vKnreLhOg3P4Tjw3QvgYmpYJAUkT9e5YgAIWzLVMxmbL95kDgxaHYfTIWWozK5kJjIq cQ+v8VXUlF3sGsk5xagy4oW8xVdfAICA9tONf7M00lgZm2AWE2f4HV+enHEkl5rGz8hY QJiwv6IzbSAxa/kWmKaejG4Mvq3jqdCjc+V5W5wDs9DG1zR2OIFAnzq1f/NuWg0G324T tqpA== 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 o4-v6si741051pll.93.2018.04.03.08.12.45; Tue, 03 Apr 2018 08:13:00 -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 S1751685AbeDCPLb (ORCPT + 99 others); Tue, 3 Apr 2018 11:11:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:40686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751434AbeDCPL2 (ORCPT ); Tue, 3 Apr 2018 11:11:28 -0400 Received: from mail-it0-f42.google.com (mail-it0-f42.google.com [209.85.214.42]) (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 51D8721836 for ; Tue, 3 Apr 2018 15:11:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51D8721836 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=luto@kernel.org Received: by mail-it0-f42.google.com with SMTP id b5-v6so12974284itj.1 for ; Tue, 03 Apr 2018 08:11:28 -0700 (PDT) X-Gm-Message-State: ALQs6tAgGqMELpClWGWqslRDoQ2y2xnqDRnBDnUS9+jMngENZp5AiWmE Q5WOfRuZonmXnK+vkEsSIzXCYtEAcQsMf9Ve753cSw== X-Received: by 2002:a24:5bd5:: with SMTP id g204-v6mr5640114itb.55.1522768287559; Tue, 03 Apr 2018 08:11:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.137.70 with HTTP; Tue, 3 Apr 2018 08:11:07 -0700 (PDT) In-Reply-To: <30459.1522739219@warthog.procyon.org.uk> References: <4136.1522452584@warthog.procyon.org.uk> <186aeb7e-1225-4bb8-3ff5-863a1cde86de@kernel.org> <30459.1522739219@warthog.procyon.org.uk> From: Andy Lutomirski Date: Tue, 3 Apr 2018 08:11:07 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [GIT PULL] Kernel lockdown for secure boot To: David Howells , Ard Biesheuvel Cc: Andy Lutomirski , James Morris , One Thousand Gnomes , Linus Torvalds , Matthew Garrett , Greg KH , LKML , Justin Forbes , linux-man , joeyli , LSM List , Linux API , Kees Cook , linux-efi 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 [re-added cc's, I think. Sorry, I think I failed to use the gmane gateway correctly there.] On Tue, Apr 3, 2018 at 12:06 AM, David Howells wrote: > Andy Lutomirski wrote: > >> This is an attempt at a review. I'm replying here because I can't find the >> actual relevant patch emails. > > This was the latest post: > > https://lkml.org/lkml/2017/11/9/660 > > and they were posted multiple times before that, plus distributions, such as > Fedora, have been carrying them for a long while. > >> For the rest of this review, I'm going to pretend that you actually want two >> features: "try-prevent-root-from-corrupting-the-kernel" and >> "try-to-prevent-root-from-reading-kernel-memory". > > It theoretically boils down into those two, but the line is blurrier than you > think. > > Further, some of the vectors that can be used to do one can potentially do the > other also and it starts getting to be a lot of extra work to distinguish the > two. > >> I do *not* see why the mere act of using Secure Boot should have this >> effect. > > To be able to pass secure boot mode over kexec, you have to make sure that the > kernel image doesn't get corrupted, lest someone blacklist your signing key in > the bootloader. Can you explain that much more clearly? I'm asking why booting via UEFI Secure Boot should enable lockdown, and I don't see what this has to do with kexec. And "someone blacklist[ing] your key in the bootloader" sounds like a political issue, not a technical issue. What is the actual purpose of these patches? > >> In particular, UEFI Secure Boot should *not* enable >> "try-to-prevent-root-from-reading-kernel-memory", which means that, unless >> you actually implement the split, you should drop a bunch of the patches. > > Yes it should. If someone can read your kernel image, they can steal the > crypto keys you use to encrypt your filesystem. Can you please explain the actual attack that is avoided by doing this? Suppose I'm a bad guy attacking someone's laptop. If I just have normal uid!=0 access, then these patches have no effect. Instead, we're talking about an attacker who is somehow able to become global root and bypass all LSM restrictions but has not gained kernel code execution. It is indeed the case that your patches make it harder to simply read the dm-crypt encryption key out of main memory. But root can attack the disk encryption in many other ways. They can persistently compromise the machine by adding services or user accounts or intentionally misconfiguring something. They can directly read the entire contents of the disk. They can modify the initrd so that the next time the machine reboots and the user types the password, the attacker gets the key (unless the TPM is involved, but getting *that* right on a standard distro is difficult or impossible). And I'm not even sure why an attacker who manages to become root wants your disk encryption key. That key is worth nothing unless the attacker makes its attack persistent, but, if the attacker can install a persistent user-level backdoor, then they can read the cleartext off your disk just as easily as they can read the ciphertext. > >> "Restrict /dev/{mem,kmem,port} when the kernel is locked down": this should >> probably split into one restriction for read and one for write. > > Not so for /dev/port. Read & Write here are _not_ the same as Read & Write > on, say, /dev/mem. In fact, if /dev/mem gives you access to mmio ports, then > the same applies there. Btw, Fedora hasn't even provided /dev/kmem for a > while. Then split /dev/mem and turn off /dev/port for all locked-down modes. > >> "bpf: Restrict kernel image access functions when the kernel is locked down": >> This patch just sucks in general. > > Yes - but that's what Alexei Starovoitov specified. bpf kind of sucks since > it gives you unrestricted access to the kernel. bpf, in certain contexts, gives you unrestricted access to *reading* kernel memory. bpf should, under no circumstances, let you write to the kernel unless you're using fault injection or similar. I'm surprised that Alexei acked this patch. If something like XDP or bpfilter starts becoming widely used, this patch will require a lot of reworking to avoid breaking standard distros.