Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3353506ybl; Mon, 19 Aug 2019 17:19:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxBi8ZXE7KtWCtAjIT+xYebP1JaFmovGS6nMccyIbrmqEVmvpwZL6PeYP3daaFQflhQ0lbv X-Received: by 2002:aa7:9790:: with SMTP id o16mr27452839pfp.51.1566260390082; Mon, 19 Aug 2019 17:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566260390; cv=none; d=google.com; s=arc-20160816; b=qjDiaX9ln0MIvwdgVCQ0hHRXHuhjO/f9LMPCLQgHJtpADz3nu1D0+YrAK+tuDqOtJN N++oB2CcI9ynX1lUMRimVk2KYqdg+Srpklz7SvtDuukGQKTyb0U5RCgyu6JQ3kw4UOG4 zmpku662bL4Pq6UGDK/vGdvGom/V5mYE4UdE253nBImqlhErQJDDC4ztrayz/kHFsR4C UXInwuUztWd4VXnHQ9WXlQscnBuxHaAJ5eCY7qMAn4tyjW+DsxjIcZkaUAZqYAdCwDcz 4Jaql/aYEEKmVhXPcs8zwdBMosKyyrSRNN8w3nv+yq30AXHQLMGsF7gvNqr/wj/iPE7W 2xLQ== 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=aETaOEPelySVl3QKK9Qr+qOWAsUAyXrm7SwwhN9vG4c=; b=QmGd1yXALvQEL2Wc1VelLjP7nhD+a70Jkti7+zzc3Q2/lccE9BEVg7CEZkWVGHrWfK sS20WEZwa8cUy+RXqosxe5VW9vREiz93MxoOHcSl1tSBynbX9IMVgzEFTGBJjFTK/Z3Z nbSyjLptoXtu0GqndhvMPKCWY1gThtXy6HdbuhmA3fkght6DCYkpp33LdVogHvKKOBCa FJYLQScqHMB2G62dHIDwVheGIA8GRlmGMXheoU9Tn1WRpA+4Hg03N3LH1kX4MOZAC5Sd m6VYAoUpvBRukEq9h+NmOkRgAwxA7jNREteDiE8dvlacykaqUUbZvC3RmwCXHJNdfSZa 3JbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KhujlyI2; 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 x203si10902230pgx.545.2019.08.19.17.19.35; Mon, 19 Aug 2019 17:19:50 -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=KhujlyI2; 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 S1728946AbfHTAS3 (ORCPT + 99 others); Mon, 19 Aug 2019 20:18:29 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:48834 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728941AbfHTAS1 (ORCPT ); Mon, 19 Aug 2019 20:18:27 -0400 Received: by mail-pf1-f201.google.com with SMTP id t14so3521181pfq.15 for ; Mon, 19 Aug 2019 17:18:26 -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=aETaOEPelySVl3QKK9Qr+qOWAsUAyXrm7SwwhN9vG4c=; b=KhujlyI2R6CEvYLT/F0SfZBAYudHduHuG5bZC22M5mysowFDhbeQ+KtmAa2GL+arTd ftXTboaJS5SyEuwjIFnjLzFD3F1edbJS+pifqs9WbNF9zE/hyk6bk+GHH5cqSmJPImAW 9Cavog1sTHJeQrWVJgdqMWImMQMxJFER0njBKXSFJMCBMzAX2DjrIIB05xDViM7bEXC6 Tolcpnnock/s2dnEVBo4OaAKzHAQ4bXrZLiRP/b1kKxHg9G0JLEAtNuA8C5e+3eNGEh9 yXCIfRVuj2JYvB/WKS9SEa1/3vFVqnmUa8t7IVZi8dFGhhhyFvgweYkxnUpU0ufI66MY ZcpA== 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=aETaOEPelySVl3QKK9Qr+qOWAsUAyXrm7SwwhN9vG4c=; b=fvOFdDkWTdHdSipMFcf6T8pUerJIdjHYmGuTIMvMitOwGVreGWQAFydlg3nRoH+G/s wrMzggyDWQtyE4V+fuXcmqprNlX/Mwc0WskpiIuLza5YaGJE2NEazzNGNkChtTiyjNIm gD57S16TxT7dp6X+SNoULUlItYpp3EFVEtQJ7F3oKIHDiU+tVYKzpdHyiITLtjwttPyA Tjq1BskKJ0cH5SC+7cOW4Amho7nIRo4tXqjNsn1PsNiPeB9HEZN8gEtrBRHJmXCWmZ+y puOJuMADIxldl9BCI4mRtBzvraZ0XWw0uBDsMfNm2+Y2R+wGZwLMS5pzWlvnnG8d84pC 2YiA== X-Gm-Message-State: APjAAAUL2mWN+FZd/q49eRpSBrMzq2aQB18WbRlZFwt21iKc9LlB1mNm VvodowfVBVgcGpHpFSg8moLeZwL60FYcT0UCT3KFAQ== X-Received: by 2002:a63:ff03:: with SMTP id k3mr22704545pgi.40.1566260305794; Mon, 19 Aug 2019 17:18:25 -0700 (PDT) Date: Mon, 19 Aug 2019 17:17:42 -0700 In-Reply-To: <20190820001805.241928-1-matthewgarrett@google.com> Message-Id: <20190820001805.241928-7-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 06/29] kexec_load: Disable at runtime if the kernel is locked down From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Matthew Garrett , David Howells , Matthew Garrett , Dave Young , Kees Cook , kexec@lists.infradead.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: Matthew Garrett The kexec_load() syscall permits the loading and execution of arbitrary code in ring 0, which is something that lock-down is meant to prevent. It makes sense to disable kexec_load() in this situation. This does not affect kexec_file_load() syscall which can check for a signature on the image to be booted. Signed-off-by: David Howells Signed-off-by: Matthew Garrett Acked-by: Dave Young Reviewed-by: Kees Cook cc: kexec@lists.infradead.org Signed-off-by: James Morris --- include/linux/security.h | 1 + kernel/kexec.c | 8 ++++++++ security/lockdown/lockdown.c | 1 + 3 files changed, 10 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index e5dd446ef35b..b607a8ac97fe 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -105,6 +105,7 @@ enum lockdown_reason { LOCKDOWN_NONE, LOCKDOWN_MODULE_SIGNATURE, LOCKDOWN_DEV_MEM, + LOCKDOWN_KEXEC, LOCKDOWN_INTEGRITY_MAX, LOCKDOWN_CONFIDENTIALITY_MAX, }; diff --git a/kernel/kexec.c b/kernel/kexec.c index 1b018f1a6e0d..bc933c0db9bf 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -205,6 +205,14 @@ static inline int kexec_load_check(unsigned long nr_segments, if (result < 0) return result; + /* + * kexec can be used to circumvent module loading restrictions, so + * prevent loading in that case + */ + result = security_locked_down(LOCKDOWN_KEXEC); + if (result) + return result; + /* * Verify we have a legal set of flags * This leaves us room for future extensions. diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c index 240ecaa10a1d..aaf30ad351f9 100644 --- a/security/lockdown/lockdown.c +++ b/security/lockdown/lockdown.c @@ -20,6 +20,7 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_NONE] = "none", [LOCKDOWN_MODULE_SIGNATURE] = "unsigned module loading", [LOCKDOWN_DEV_MEM] = "/dev/mem,kmem,port", + [LOCKDOWN_KEXEC] = "kexec of unsigned images", [LOCKDOWN_INTEGRITY_MAX] = "integrity", [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", }; -- 2.23.0.rc1.153.gdeed80330f-goog