Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3354710ybl; Mon, 19 Aug 2019 17:21:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIznGA9WBMWO/UXS52whSoEQu3oyXoxYgvgBsKdwb3EarlbRU0IG8a2c+tlDxh+0F7oRXN X-Received: by 2002:a17:902:6bc7:: with SMTP id m7mr25756303plt.60.1566260486335; Mon, 19 Aug 2019 17:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566260486; cv=none; d=google.com; s=arc-20160816; b=BO/OVPwSSGuDmCCPY3bxvK0Ft8ryw69f70QS/AO1+cCxC719gTpQ2JoT800L7nDxiU nRewEb9C5ByzJoMRVIfdaXmg6GdRsvn1RZdMy32CoH6YMOFieL6dZ/uDddFxPtzMulrE 0GQUajJfc4/d4MIxU1y/fmzAhKAQZLL2biRGbi1QfiqaSCo/sOQ1PhhG6QWxJHTvoWUv uu52kJqRtYy2n8l2K3CJeMNc6+N+i25AhfdMyeoqlD/xmARFX3rc5cSoG9RdipLuBb8g VFexNOoqlQiYdN0NNTMcAOGQoZA7w2P1UM/ifuIHBvGHbZL9hb+4aYWyejcvn9NclvDH WJVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=kSndO1IyWL1budUByV+82z7IsO0BZXBN4MJZqcoLXQw=; b=bfViG99opKGOMAzrFzJD9FVrPf2tqRe/2kYgg/yseDKldhjysCDUFxEM0Yhbo0liBv Fb5P/eNLlhT+4nz588K568qbiVyyVPRkdwuWUmIKAPi9C/9g4MDYVvRc3et4S3zuJ1Mf 2OAOPMJwgki3uxDSEaaL79tn1a1wxAFrjJXZ0gVoAOAs6fY8x0hoFWO4WH3lqZ5VbPi/ qq/xPgdhBVY+xfU8IUxjgKRHKpl/0qESD6WyX2mlGwfltUfvvrQ047BLHX//LnPg0w0c /bgq2SbTblvTXY9kPCBPwX8My+XLnNB2/oyvtV3kM60r1amk42pSCmv9hMkHF6ScYn9C 4PQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=j0nFVrNe; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c6si11100801pgb.105.2019.08.19.17.21.11; Mon, 19 Aug 2019 17:21:26 -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=@google.com header.s=20161025 header.b=j0nFVrNe; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729140AbfHTAT5 (ORCPT + 99 others); Mon, 19 Aug 2019 20:19:57 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:55359 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729109AbfHTATD (ORCPT ); Mon, 19 Aug 2019 20:19:03 -0400 Received: by mail-pg1-f202.google.com with SMTP id g126so3475364pgc.22 for ; Mon, 19 Aug 2019 17:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=kSndO1IyWL1budUByV+82z7IsO0BZXBN4MJZqcoLXQw=; b=j0nFVrNervC7I3BR+Z1QC81XmRIe2YmnXC7Cqwcn2E6D7xAhmPHmV+aT8y5rQpX9ad teINQ1HOSeqytN25tzMSG78dJkJYoNQdiYzoZhea3biYu46tS6p4cx3RtVoQp98SvwZi kfexMErcC5TovudQyU3zvN2BZbfwNhm0swRqHXfo28A7gW2byAyNbmIkiL3tftU+9FD2 Q7qQF0vRWQ+JwjjXM25yPwXV2ShaoYk7tlc45AR+1U8GomtEwFT0KNiCSQA5+nvNMOsG z2ZefRwY/v8btpHc9LUXrQdvd5dC3zl/57/AcBfDfHvWpd+wPZ5uoRK/Z58dbY1F/LAx IMfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kSndO1IyWL1budUByV+82z7IsO0BZXBN4MJZqcoLXQw=; b=fXtJDrJ5H3p7e4Uaj4V9NaCH54TnoZJ+qML4hbmmc/g0iboY03Dl62MiJpkC3hT/AO grGL2gHgMK68itHDlK0gTUQ0DAoqAcNJpyjZ7r2U4U5TUNwRvqEce0l5RnzzlzNESioc MxQbYi/bZZ6NHpHpGgiJr3NaX9s9DWfHQE4C1bqk0zc8dvGFCfYG48mBepfl36SniJUH CDyadB+LeraxqYAJcSsOtUDkALjntSYayULv+3/NbK2dpu2xuymn+HY1a6o/c/G/6JEQ MqpAg+3WGqaFEEAdSB+sguqmT6taTkURhuAPMIsu+sr20HjkDzC85OjoVaTd1IZHk9/J DVtQ== X-Gm-Message-State: APjAAAWu83sDGAQBlSCu65gkasI7TXO1MtE0yydrfLvA9N/p+360eX3n IEAS3dTyqxcalxoB/BFSRPHTnQ7KbiJ+r9USByjRiQ== X-Received: by 2002:a65:534c:: with SMTP id w12mr22332444pgr.51.1566260342057; Mon, 19 Aug 2019 17:19:02 -0700 (PDT) Date: Mon, 19 Aug 2019 17:17:56 -0700 In-Reply-To: <20190820001805.241928-1-matthewgarrett@google.com> Message-Id: <20190820001805.241928-21-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190820001805.241928-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog Subject: [PATCH V40 20/29] x86/mmiotrace: Lock down the testmmiotrace module From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, David Howells , Thomas Gleixner , Matthew Garrett , Steven Rostedt , Kees Cook , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org 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 From: David Howells The testmmiotrace module shouldn't be permitted when the kernel is locked down as it can be used to arbitrarily read and write MMIO space. This is a runtime check rather than buildtime in order to allow configurations where the same kernel may be run in both locked down or permissive modes depending on local policy. Suggested-by: Thomas Gleixner Signed-off-by: David Howells Acked-by: Steven Rostedt (VMware) Reviewed-by: Kees Cook cc: Thomas Gleixner cc: Steven Rostedt cc: Ingo Molnar cc: "H. Peter Anvin" cc: x86@kernel.org Signed-off-by: James Morris --- arch/x86/mm/testmmiotrace.c | 5 +++++ include/linux/security.h | 1 + security/lockdown/lockdown.c | 1 + 3 files changed, 7 insertions(+) diff --git a/arch/x86/mm/testmmiotrace.c b/arch/x86/mm/testmmiotrace.c index 0881e1ff1e58..a8bd952e136d 100644 --- a/arch/x86/mm/testmmiotrace.c +++ b/arch/x86/mm/testmmiotrace.c @@ -8,6 +8,7 @@ #include #include #include +#include static unsigned long mmio_address; module_param_hw(mmio_address, ulong, iomem, 0); @@ -115,6 +116,10 @@ static void do_test_bulk_ioremapping(void) static int __init init(void) { unsigned long size = (read_far) ? (8 << 20) : (16 << 10); + int ret = security_locked_down(LOCKDOWN_MMIOTRACE); + + if (ret) + return ret; if (mmio_address == 0) { pr_err("you have to use the module argument mmio_address.\n"); diff --git a/include/linux/security.h b/include/linux/security.h index 1a3404f9c060..d8db7ea4c4bf 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -114,6 +114,7 @@ enum lockdown_reason { LOCKDOWN_PCMCIA_CIS, LOCKDOWN_TIOCSSERIAL, LOCKDOWN_MODULE_PARAMETERS, + LOCKDOWN_MMIOTRACE, LOCKDOWN_INTEGRITY_MAX, LOCKDOWN_CONFIDENTIALITY_MAX, }; diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c index 0fa434294667..2eadbe0667e7 100644 --- a/security/lockdown/lockdown.c +++ b/security/lockdown/lockdown.c @@ -29,6 +29,7 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage", [LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO", [LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters", + [LOCKDOWN_MMIOTRACE] = "unsafe mmio", [LOCKDOWN_INTEGRITY_MAX] = "integrity", [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", }; -- 2.23.0.rc1.153.gdeed80330f-goog