Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1391256ybh; Thu, 16 Jul 2020 10:45:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzE+KU+m4fsKa3yrA9KLHKypV3/U2WPwX0ntKUFHJ3OSHG/4hitx1hc3fxk5eDSEPlJGqqT X-Received: by 2002:a17:906:7709:: with SMTP id q9mr4738967ejm.123.1594921513690; Thu, 16 Jul 2020 10:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594921513; cv=none; d=google.com; s=arc-20160816; b=sQwjT2ULWUEKt6eoyKVogmn5PDcButrFseGNvaoo7eMmH0HXjfzgbTx09FW8M+T2L0 IN/te3aZjStyqeyD8iejFA0QxtVfGzHFXny6IpHZQnK/KQQHKIDLxGdVm8lUjJYOQl+e L4XGsnYoouBmj+USdxhTBGYS1JntKnrQekOl1bOavzdqbcUJCtkkt8RquriUiukKu1o7 L8umSfqFVt1jxtUX1EUgc8Tk6eYBmkA4zsDgatXnT/TT+ttiUpjBYhsI3HiL7q/Kvmc4 Xvgfm9DJb3ptQpLMSWJIS/x7wEc//I37csod1ax67tgW4oe3ARdqQkOYJ1mnd9d1ahKS Gifg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=RWokx6Gd27oCAJ3WfeSZo3rN7tWPRY28o2No3gTEX3A=; b=lddul+oDnWB0tFSQ1QxxI15x0qwoIGOBZEKtevBR6gJf+Y2JlJMQOJygZX6l1dX58U 1dci3FK5DZlN89YXqsyqr/Ek7rrj57PtyF2XYGcLUMYDNu+LQgU3z1IpJ2/qTyf0uQVI 5+83/XhG/XnzN3WLZtQkuyd4u4D20qxeThfaPERpftVidc5rOhN/JkpNKPCgTnAWhDgL XKpsHQTZYztIquEhh5n+D0y0uoRwN0hqsfQOpcjD3FiyjoJFbmP6dVyB7yuZ9RpLfucL MHNeLgY1PjgMJGMT+Ns0PuAJRxmHAKeaQ2csmz5dvGoAKF40rEl3wJTnkt6C2WxB5JiP vhyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=V2kfrWmU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cy5si3617796edb.554.2020.07.16.10.44.50; Thu, 16 Jul 2020 10:45:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=V2kfrWmU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729525AbgGPRoR (ORCPT + 99 others); Thu, 16 Jul 2020 13:44:17 -0400 Received: from linux.microsoft.com ([13.77.154.182]:54484 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729416AbgGPRoE (ORCPT ); Thu, 16 Jul 2020 13:44:04 -0400 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 8BA4920B490D; Thu, 16 Jul 2020 10:44:03 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8BA4920B490D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1594921443; bh=RWokx6Gd27oCAJ3WfeSZo3rN7tWPRY28o2No3gTEX3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V2kfrWmU7YIfIqlbgLC/mi8r0ZWO2GiMiSjgSWF43XfOjVpq2lG7EXeViNital8Ba frJZ9rLF8E0IBRk9rJWbjQLzV5PIjL8EvwOYxywk2PiskVEa8NBn9UKmK+dGbdLmyn Rauqdot2l24h+eHytODFuglMFpsm9DGTt1szL3Gc= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, stephen.smalley.work@gmail.com, casey@schaufler-ca.com Cc: jmorris@namei.org, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/5] LSM: Add security_measure_data in lsm_info struct Date: Thu, 16 Jul 2020 10:43:49 -0700 Message-Id: <20200716174351.20128-4-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200716174351.20128-1-nramas@linux.microsoft.com> References: <20200716174351.20128-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The security modules that require their data to be measured using the IMA subsystem need to define a function that the LSM can call to trigger the measurement. Add a function pointer field namely security_measure_data in lsm_info structure. Update LSM to call this security module function, if defined, to measure the security module's data using the IMA subsystem. Signed-off-by: Lakshmi Ramasubramanian --- include/linux/lsm_hooks.h | 3 +++ security/security.c | 48 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 95b7c1d32062..56f0e524838c 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1591,6 +1591,9 @@ struct lsm_info { int *enabled; /* Optional: controlled by CONFIG_LSM */ int (*init)(void); /* Required. */ struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */ + int (*security_measure_data)(void); /* Optional: for measuring + * security module data. + */ }; extern struct lsm_info __start_lsm_info[], __end_lsm_info[]; diff --git a/security/security.c b/security/security.c index 70a7ad357bc6..1afa2aebc3ac 100644 --- a/security/security.c +++ b/security/security.c @@ -86,6 +86,9 @@ static __initconst const char * const builtin_lsm_order = CONFIG_LSM; static __initdata struct lsm_info **ordered_lsms; static __initdata struct lsm_info *exclusive; +static struct lsm_info *security_state_lsms; +static int security_state_lsms_count; + static __initdata bool debug; #define init_debug(...) \ do { \ @@ -235,6 +238,45 @@ static void __init initialize_lsm(struct lsm_info *lsm) } } +static int measure_security_state(struct lsm_info *lsm) +{ + if (!lsm->security_measure_data) + return 0; + + return lsm->security_measure_data(); +} + +static void __init initialize_security_state_lsms(void) +{ + struct lsm_info **lsm; + int count = 0; + int inx; + + for (lsm = ordered_lsms; *lsm; lsm++) { + if ((*lsm)->security_measure_data) + count++; + } + + if (count == 0) + return; + + security_state_lsms = kcalloc(count, sizeof(struct lsm_info), + GFP_KERNEL); + if (!security_state_lsms) + return; + + inx = 0; + for (lsm = ordered_lsms; *lsm; lsm++) { + if ((*lsm)->security_measure_data) { + security_state_lsms[inx].security_measure_data = + (*lsm)->security_measure_data; + inx++; + } + } + + security_state_lsms_count = count; +} + /* Populate ordered LSMs list from comma-separated LSM name list. */ static void __init ordered_lsm_parse(const char *order, const char *origin) { @@ -352,8 +394,12 @@ static void __init ordered_lsm_init(void) lsm_early_cred((struct cred *) current->cred); lsm_early_task(current); - for (lsm = ordered_lsms; *lsm; lsm++) + for (lsm = ordered_lsms; *lsm; lsm++) { initialize_lsm(*lsm); + measure_security_state(*lsm); + } + + initialize_security_state_lsms(); kfree(ordered_lsms); } -- 2.27.0