Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp725650imm; Mon, 1 Oct 2018 18:05:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV61OsgkClmfu/P5jEjTqJ8ER4C60uEX5JvaRUMlrXflBXa9W/EssM+KOi1LUYoutXvGvalgZ X-Received: by 2002:a17:902:6b09:: with SMTP id o9-v6mr14276976plk.316.1538442322211; Mon, 01 Oct 2018 18:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538442322; cv=none; d=google.com; s=arc-20160816; b=VFZfRomVeksZv9NRCZPAzQi/9EIvycpraWWd4Zycg+M1hZETQqN15UYyQVde9HYlZd zcnJu7gUNyCmfwS+gZMwsHq3IXkqG2NcaF+5waLObo7afvQkZoqiGKNVuTtLQXlMqzsq B1/vt5Ei6dZbIKmMeHqHE0AlZWC2Up6s3+jiS3lKLkLV4+fHrR1KD3DOD+gG4IsR4Hop SfZ7eojvF/XiId6FqJQeINX84ULl1BqpuF24PpfzzxNkRFcsLU+y6cQ9mjQ1+mS4bg86 YdB7eSNorxS6UvKOt0DtlRrvHwMgeUwCRsDsFk/I/KYvUYo0PoG9+hq2WN618jYSJsOj 2TZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=pq4ACjGaPlM3h3UYEHG6fyOCzAt325XuBayF3KFtHqs=; b=odpaRWzAgRmaoyhvgFmwGXpcwV5a4/Yn9HS5ZO3jvl7d5M7EjAohsnLMtBjHuuG/RT yr1Q8+suO725IZvmMwwQMxitcYTrZBiU2fSasCbRHoJC8pg/YMz7vZudt1p84WOQtpR9 OmHnyMkGElRuWdIELroTI3tW5ggJjlN368BSj3FmSfIT2SxXvCXWs65m9/ay562cEp+3 aob7PUpwQiqMUmRUrfW93pZy/0E1DBuAEif0M3XoaA/kwOCclWJS9CtxHQZp/qlbQe5/ 3QxLOo1AAdeLKq1Pp4kaDpXocFL8e+PpympSOQ7i/zvLHtYG9jA9Gu91iLvb0Z3aSOlw DVBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SzKobk9C; 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 p3-v6si14015319pld.329.2018.10.01.18.05.08; Mon, 01 Oct 2018 18:05:22 -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=SzKobk9C; 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 S1727204AbeJBHpN (ORCPT + 99 others); Tue, 2 Oct 2018 03:45:13 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:41316 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbeJBHpI (ORCPT ); Tue, 2 Oct 2018 03:45:08 -0400 Received: by mail-io1-f65.google.com with SMTP id q4-v6so275708iob.8 for ; Mon, 01 Oct 2018 18:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pq4ACjGaPlM3h3UYEHG6fyOCzAt325XuBayF3KFtHqs=; b=SzKobk9CWHgW0EjDQXpy5PM5QZ3lzRGlKyIOumCKOBfw36q+fvtBUq+NVX6EB408KK jkNAXDs5T/9+DbK8+FTehptO3P/TR2yTBQPWOeqyFtrVUk6ud/QmbGt56BDUGrSthTps kj5B3jrPoUo8KtnNxt02PY2FOyHzKtnaUUAR4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pq4ACjGaPlM3h3UYEHG6fyOCzAt325XuBayF3KFtHqs=; b=Oq9NkzAnV05TGAbcg7kUfvbuxOJ8YEo7kVKyWKcV9wwFZDg0qyGWX6w7gT0dWyjz3C JZ90O+7K1nytHruc7f/kmJNu3WTwxFw4Mp+nWuYHEPw8aIspVDVa577Fvn1nezlhNYR1 ebhnz6Sclgv9VDKe/sCsLDwKm2coyKVfN5l4XeoDqVHR7ld93qVJEuy6k3rDMZG/17NQ 93xKz7chkCjiuBc2U4GzYoaYiR7IlLQXOzq87dDSaR444/xcS00PGtCwI0dURzg5MZyd /c6NsUNUaR6WENEa+GRSaf55LTtZ0M6IAiDsGB9Budc2DbBkLDxJUYNH+Q11RRHfFQhW vrmw== X-Gm-Message-State: ABuFfogsX2pnrvGTqkHfDTSlviBHfEk1KtrcBtGjEC9pQVyQq8KScJ9B Mi2utLVuRpZhqLcoFnKTVPt3J/ktMds= X-Received: by 2002:a62:20d8:: with SMTP id m85-v6mr13963277pfj.152.1538442276863; Mon, 01 Oct 2018 18:04:36 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id n79-v6sm28498659pfk.19.2018.10.01.18.04.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 18:04:35 -0700 (PDT) From: Kees Cook To: James Morris Cc: Kees Cook , Casey Schaufler , John Johansen , Tetsuo Handa , Paul Moore , Stephen Smalley , "Schaufler, Casey" , LSM , Jonathan Corbet , linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH security-next v4 25/32] LSM: Introduce CONFIG_LSM_ORDER Date: Mon, 1 Oct 2018 17:54:58 -0700 Message-Id: <20181002005505.6112-26-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181002005505.6112-1-keescook@chromium.org> References: <20181002005505.6112-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This provides a way to declare LSM initialization order via Kconfig. Signed-off-by: Kees Cook Reviewed-by: Casey Schaufler --- security/Kconfig | 16 ++++++++++++++++ security/security.c | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/security/Kconfig b/security/Kconfig index 1e57619fd561..c68520d97fd7 100644 --- a/security/Kconfig +++ b/security/Kconfig @@ -286,5 +286,21 @@ config LSM_ENABLE changed with the "lsm.enable=" and "lsm.disable=" boot parameters. + Note that any enabled exclusive LSM modules will be initialized + based on LSM ordering, automatically disabling any following + exclusive LSMs. See CONFIG_LSM_ORDER for more details on + changing LSM initialization order. + +config LSM_ORDER + string "Default initialization order of builtin LSMs" + default "integrity" + help + A comma-separated list of LSMs, in initialization order. + Any LSMs left off this list will be link-order initialized + after any listed LSMs. Any LSMs listed here but not built in + the kernel will be ignored. + + If unsure, leave this as the default. + endmenu diff --git a/security/security.c b/security/security.c index 8706b42b4d44..0510bb8e0af0 100644 --- a/security/security.c +++ b/security/security.c @@ -47,6 +47,7 @@ static __initdata const char *chosen_lsm_disable; static __initdata const char *chosen_major_lsm; static __initconst const char * const builtin_lsm_enable = CONFIG_LSM_ENABLE; +static __initconst const char * const builtin_lsm_order = CONFIG_LSM_ORDER; /* Ordered list of LSMs to initialize. */ static __initdata struct lsm_info **ordered_lsms; @@ -122,14 +123,47 @@ static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from) is_enabled(lsm) ? "en" : "dis"); } -/* Populate ordered LSMs list from hard-coded list of LSMs. */ +/* Populate ordered LSMs list from given string. */ +static void __init parse_lsm_order(const char *order, const char *origin) +{ + struct lsm_info *lsm; + char *sep, *name, *next; + + if (!order) + return; + + sep = kstrdup(order, GFP_KERNEL); + next = sep; + /* Walk the list, looking for matching LSMs. */ + while ((name = strsep(&next, ",")) != NULL) { + bool found = false; + + for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { + if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0 && + strcmp(lsm->name, name) == 0) { + append_ordered_lsm(lsm, origin); + found = true; + } + } + + if (!found) + init_debug("%s ignored: %s\n", origin, name); + } + kfree(sep); +} + +/* Populate ordered LSMs list from builtin list of LSMs. */ static void __init prepare_lsm_order(void) { struct lsm_info *lsm; + /* Parse order from builtin list. */ + parse_lsm_order(builtin_lsm_order, "builtin"); + + /* Add any missing LSMs, in link order. */ for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { - if (strcmp(lsm->name, "integrity") == 0) - append_ordered_lsm(lsm, "builtin"); + if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0) + append_ordered_lsm(lsm, "link-time"); } } -- 2.17.1