Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp844796ybd; Sat, 22 Jun 2019 16:58:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+TZt2IRjHDeTHVgRBkugMbJVel72QJ8gwMS8MS2obPeV9vdIlZZSS0C2sBLdyKA6BOQrH X-Received: by 2002:a63:6183:: with SMTP id v125mr20952488pgb.221.1561247926722; Sat, 22 Jun 2019 16:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561247926; cv=none; d=google.com; s=arc-20160816; b=SgyAdD/5QwzcTMz3ts1eJng/DO3VPBnqAr7gZKYoNLIxn+Ts2advyyXrZLlIx2UIB8 85ShNGCwT+jJMwSBu/qfI9zW03Te05JBY37+lebCstieROEnXLbwMT4KihLvjHjXvkWc o2Whs9Xrf2chJrrqzyQr32VhG3dQflEPzdcGwmROKyjfolb7DNf3lMqMbZ+JHyUnsxZj TbFStvBErrsRYWevZpIBOK8EFRpMl4UF9M28PJE7a2hCKzqHDdv33a9yqqCQ5Ld6b8ME oxd3djuyWJ2cSybD1Kzf9zH85ruipUCgSbNdQK+Vd1qhASrAFSzeHFzY1AjFHDQ5ItIo SkYA== 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=QkZqiu2e/y7+phBcsq5SoX4+beWXUj/CML40Z1zWPDw=; b=rZAtbO3I5+AMbfAfTEZmq+85GpGlkcTMduH42wFVw/3RIR9JCFybWw1WLevCyk+HYC dzJjJkmu/x+Wbj3HyPg2JG2j3zsYQXHelrBAsetPs/uup/i2aQuCH4wVuMIlhJKY1mLf n+SVODhFD3SZSklzRWhRT8IgHiqvi13he8NMMweFRXK1XGD2ezw++I6T09Wi45Tg6BzQ iC12L7J31J+GYhyurg8TaBYHbgOWmDgR2kQQO0NG5bk7UH1HRqfiVwtS2+T4fJyQEuUI rrs3mQLWSkukBsf8Bo6M0NiwHMLMZ9vOjsusaon7Isj5yoZ97Dyc6jht8EX7H5NVc39F qq9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dGAAyY5e; 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 x82si3429921pgx.416.2019.06.22.16.58.31; Sat, 22 Jun 2019 16:58:46 -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=dGAAyY5e; 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 S1726460AbfFVX6Z (ORCPT + 99 others); Sat, 22 Jun 2019 19:58:25 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41884 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726343AbfFVX6Y (ORCPT ); Sat, 22 Jun 2019 19:58:24 -0400 Received: by mail-pg1-f194.google.com with SMTP id y72so5110108pgd.8 for ; Sat, 22 Jun 2019 16:58:24 -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=QkZqiu2e/y7+phBcsq5SoX4+beWXUj/CML40Z1zWPDw=; b=dGAAyY5eundVFCsa+eIl/VJN4Acqx7GYdJxXAKE3xONM/98BgVGI2N6I0p7PwaBqST zQUgtbOOrGDpELJmQE2730Lf8twlogB9yOxEmrOrcX12TwKTwEDFDsqNUieOmT7Uzl/X GgaaWR100aNp1cSTdmWHKbrHVznJvWlCS+YEk= 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=QkZqiu2e/y7+phBcsq5SoX4+beWXUj/CML40Z1zWPDw=; b=lVHojj3tTcqyKWbdhEOSsWUuS/vJxQv6NUrtgE0hSNHHZupPoRzqB2oNAH4I7oHey7 AxRwMRz9mr3iC28CEXfym6MhehWocasCnb7pJr3Z2q9iGLAuiQz5A4bnzd/OWWXHgwAV SUPgRfmOOCsVAVt8zsEQ6hgl90F1JfK/nICIq3CrN2MqezWSwF6+kg0hsvynxEuBCx/2 oiSgNC1Bk6Pd8tXT0SqavNggO7WpQrlz1HvGRiugmg7VSWKyEOb7VchhJ3qxEnOf6yoG jyOWLESaTUsIgXCexk52W509i9SFnp3DlsCsd8tA4s5Y/EuSqqdFqGlz2dOU1hfWF46g 46ZQ== X-Gm-Message-State: APjAAAXiaa89jJ9HOlmZIM0987jushiChVjQYnooXGnT92847o8noSYL P6/o829E8QHQ5UQ0lenhM4N2Cg== X-Received: by 2002:a63:5202:: with SMTP id g2mr25404741pgb.386.1561247903777; Sat, 22 Jun 2019 16:58:23 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id o13sm6832459pje.28.2019.06.22.16.58.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Jun 2019 16:58:23 -0700 (PDT) Date: Sat, 22 Jun 2019 16:58:22 -0700 From: Kees Cook To: Matthew Garrett Cc: jmorris@namei.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Matthew Garrett , Matthew Garrett , David Howells , x86@kernel.org Subject: Re: [PATCH V34 12/29] x86: Lock down IO port access when the kernel is locked down Message-ID: <201906221658.C4956B7@keescook> References: <20190622000358.19895-1-matthewgarrett@google.com> <20190622000358.19895-13-matthewgarrett@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190622000358.19895-13-matthewgarrett@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 21, 2019 at 05:03:41PM -0700, Matthew Garrett wrote: > From: Matthew Garrett > > IO port access would permit users to gain access to PCI configuration > registers, which in turn (on a lot of hardware) give access to MMIO > register space. This would potentially permit root to trigger arbitrary > DMA, so lock it down by default. > > This also implicitly locks down the KDADDIO, KDDELIO, KDENABIO and > KDDISABIO console ioctls. > > Signed-off-by: Matthew Garrett Reviewed-by: Kees Cook -Kees > Signed-off-by: David Howells > cc: x86@kernel.org > --- > arch/x86/kernel/ioport.c | 7 +++++-- > include/linux/security.h | 1 + > security/lockdown/lockdown.c | 1 + > 3 files changed, 7 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c > index 0fe1c8782208..61a89d3c0382 100644 > --- a/arch/x86/kernel/ioport.c > +++ b/arch/x86/kernel/ioport.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -31,7 +32,8 @@ long ksys_ioperm(unsigned long from, unsigned long num, int turn_on) > > if ((from + num <= from) || (from + num > IO_BITMAP_BITS)) > return -EINVAL; > - if (turn_on && !capable(CAP_SYS_RAWIO)) > + if (turn_on && (!capable(CAP_SYS_RAWIO) || > + security_locked_down(LOCKDOWN_IOPORT))) > return -EPERM; > > /* > @@ -126,7 +128,8 @@ SYSCALL_DEFINE1(iopl, unsigned int, level) > return -EINVAL; > /* Trying to gain more privileges? */ > if (level > old) { > - if (!capable(CAP_SYS_RAWIO)) > + if (!capable(CAP_SYS_RAWIO) || > + security_locked_down(LOCKDOWN_IOPORT)) > return -EPERM; > } > regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | > diff --git a/include/linux/security.h b/include/linux/security.h > index 1b849f10dec6..60569b7e9465 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -87,6 +87,7 @@ enum lockdown_reason { > LOCKDOWN_KEXEC, > LOCKDOWN_HIBERNATION, > LOCKDOWN_PCI_ACCESS, > + LOCKDOWN_IOPORT, > LOCKDOWN_INTEGRITY_MAX, > LOCKDOWN_CONFIDENTIALITY_MAX, > }; > diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c > index e2ee8a16b94c..895ef3ba1b4c 100644 > --- a/security/lockdown/lockdown.c > +++ b/security/lockdown/lockdown.c > @@ -23,6 +23,7 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { > [LOCKDOWN_KEXEC] = "kexec of unsigned images", > [LOCKDOWN_HIBERNATION] = "hibernation", > [LOCKDOWN_PCI_ACCESS] = "direct PCI access", > + [LOCKDOWN_IOPORT] = "raw io port access", > [LOCKDOWN_INTEGRITY_MAX] = "integrity", > [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", > }; > -- > 2.22.0.410.gd8fdbe21b5-goog > -- Kees Cook