Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6088738ybh; Wed, 7 Aug 2019 17:08:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxd+GqhsJWc792bbBZHumx28CqXmUliaMrPOOcnAyM3Jk8U1a+isUl/M5uKbT4QRQtlco/t X-Received: by 2002:a17:90a:ac13:: with SMTP id o19mr1000239pjq.143.1565222925798; Wed, 07 Aug 2019 17:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565222925; cv=none; d=google.com; s=arc-20160816; b=lsIJvYTzwawW7zk6WKqR4kIUGZmmm83FPgorGdrRLeO7dXksfukyobdv21dO4mafgn GkZNtScs+8ieB6uXz2MDYJyhBz8w8yqYtiFvHDudiMbgyvM9dm4lL3ZgxXR+hRAQIT6z qdim4ekT1/ew6ccIg4p2pxTcXvaIH+TxTATjC5QHHj/uGFLHZnDJ5BROlPw9UHl2MrEa MT2DWvu4mBq3b+v+ykqD77jXuwKB77upJVuxJbAEE0KGg7tr9J03qRVGnxQ3yePB47G/ zUZZnCOvI0lurtTqusaTb7tAxVwrhhgtA4WzrAGI823NlHfD+YvtrKSp2d4Q4/+T9D+5 E37w== 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=F1VsQKe1CvGe90szBrckBeIyG/tsASbX2ypyWhc14LE=; b=ygS91IY93VIJsX2gxSEbxBAh6wM1SxOccdl8MhscqTEVkdtYyg0EqYx7OAS6zUghm7 iWsJHpOkmoRJEtRL/ZeoT6yL4+K8QSI6R8OjngerEW1fx60M4rT9lF/2K1yA1CyBRy8x L3lp3Xt8ClJELkHkuAC7KDkElRrCQyh1p+5579JKP8RIhDUNfZBaN8T7undZfKkYAwEN A1NI4m83AsKvDP4Nj5W8UoJyUiRej0UCosdaEKTItmw5Lb3l9vQicFAcwR5dINncoZpP vLGWxycJMT3T/2i+5rnBOfvGZQgN+IHJhARG0RkM/eOhG3Rz1YQmnJfem0NHKDkfXX11 r60A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qMlQjFH4; 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 r11si451134pjq.108.2019.08.07.17.08.30; Wed, 07 Aug 2019 17:08:45 -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=qMlQjFH4; 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 S2389330AbfHHAHm (ORCPT + 99 others); Wed, 7 Aug 2019 20:07:42 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:46606 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730680AbfHHAHk (ORCPT ); Wed, 7 Aug 2019 20:07:40 -0400 Received: by mail-pf1-f201.google.com with SMTP id g21so57838935pfb.13 for ; Wed, 07 Aug 2019 17:07:40 -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=F1VsQKe1CvGe90szBrckBeIyG/tsASbX2ypyWhc14LE=; b=qMlQjFH4LNkPFt7okSAYQH4LtgYOG/hpHDLWPX566YGyPNtYJPUP46rcks4c8eYnlb 0bNs4gihvrRlVOh7tP/Xx/1BqrbyEXSnnaOOpY9HI+9wJsc3wJD2PF5r/GwLRZeUaYMb amKeZJBCwihyM/juh7mpeQuNxOuwGxJ9NIxBA9znCQKrTU72jhbs+1l3EcTedt8WGozq BelKAb8SlmNg4vuZFYuqAK88knD3oJ0DDgpmSGebDO7s3E3QGb7ZbaHu1OLTTpwaG5sS F0qMtxQ/4l2MjyX8Z6GY0yoXhEMxtyJK+E73Gdo88OD3vLRca9iG/my2Faw6p3KXszOw kfgA== 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=F1VsQKe1CvGe90szBrckBeIyG/tsASbX2ypyWhc14LE=; b=JxZ0IYnI4F+Ts5XCEr2oN1rJy4B1WWxXJXT9oXv/8LreW4pPdkHuPz593UbvQcYRzm Np3DGFUKr597oBFWybDXTjheJHkKTyu9H3n//0weJ3V5BrD5omKa3DUl7ortvSxcY6bO 7P6hpH3zGJPyzLwRfnFLstTOqodPDi3hkrVbVvsMuCyrTc1RaZFYBZg2ReIqsygDJhbv It2cXa9glUw5AGY/nfpUzA4eXqc10nC1A9YVYruancZ6kHqVUvxxPkv66bU/ec1JkWSZ p9jB9hSOPAaXbnWManmMpcGoPEOrwht+OgjG06vnuVRbTU30TeMyVxgtxZMrmuUbeiu8 d2qA== X-Gm-Message-State: APjAAAWkNlYsNYTFLwK/Vhwop5xichqn7G9v8OXwBQLBcOyahc9xNMXJ 3/2YQRcDyYH5YJA5eb9wPBmz8rxZRaa4gS5xMbMreg== X-Received: by 2002:a65:6815:: with SMTP id l21mr10209698pgt.146.1565222859667; Wed, 07 Aug 2019 17:07:39 -0700 (PDT) Date: Wed, 7 Aug 2019 17:06:58 -0700 In-Reply-To: <20190808000721.124691-1-matthewgarrett@google.com> Message-Id: <20190808000721.124691-7-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190808000721.124691-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog Subject: [PATCH V38 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 --- 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 9458152601b5..69c5de539e9a 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 d2ef29d9f0b2..6f302c156bc8 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.22.0.770.g0f2c4a37fd-goog