Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1414284pxb; Fri, 22 Jan 2021 15:32:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwnQswqUZ+4THgdo/TtdBKnEUDsb/CHAsMPnhjijHYvHE35hHIbaDSUx2ET9eJla61aOY2 X-Received: by 2002:aa7:d148:: with SMTP id r8mr634784edo.127.1611358340611; Fri, 22 Jan 2021 15:32:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611358340; cv=none; d=google.com; s=arc-20160816; b=WyLWdKAra3OVp89JA12p9vk2MjHfQgrkl8sJkxg0niRivkD1dc0FtoJNTbfrxlflDH y3xyS+TIK0RnxVQWLI4+pk4Qs01NJQgnMlwuuISS+jV/ErDVrgrfmz9AuU97VBcc3FLx yv1WXw+WI/2oMocjlmdWYkAPAgVP2Ux8CvK2HvjE48n0SXUWSFG+0V430rzwvxV/83up WB7/0nt7xlveq+8xsGxtyAuF00KcNepZihk+3+iX1dGcuNYUgIZpmpPbqOoXlztxN9gB LD6lZLnLh2E2cefinF0ucFFIP2+f9uWl5cuESsNuxrBPijNu1/btr5xVscw41uqJRUQ3 S5jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=gR+E6J/KWkeDvBUKGVIOIRFzbUvo3l+XqkwRbUylShY=; b=DSCG1g0RpSduBNIDU1XvbfzppC/zghBMrQsowuBT6xvSu8RTpL62Wsm/F6E0bKW7tP hvOoWmfF7Ao8DqkjKU86Veea5D2ZeQ8/OiwP6EXdOZlgi5+A7BX64+Wm/0KTsVOyJHpo wg7R6wPDVTuceMKu1cZme7hlYodHcOmFRrsnN7IqVwsOo6exlEfdq+8P+GN+i6t3+P38 02cCNj+iTbXmwmVe2ywvezKQ+JH/0Bw9O0QTDQEIQCyRfqU/owtnZAAuEYC1u2PpdTTZ 7UdrfkUn0vxmXr+tvdCaFygfvdmHI/EKkVWrvNqYIqD8DIxo4z7Z67SWiYyHwr5E5bz+ OKSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=cJpz6cfj; 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 e10si4085012edv.269.2021.01.22.15.31.56; Fri, 22 Jan 2021 15:32:20 -0800 (PST) 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=cJpz6cfj; 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 S1728377AbhAVX3W (ORCPT + 99 others); Fri, 22 Jan 2021 18:29:22 -0500 Received: from linux.microsoft.com ([13.77.154.182]:56220 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728164AbhAVX3T (ORCPT ); Fri, 22 Jan 2021 18:29:19 -0500 Received: from rapha-Virtual-Machine.mshome.net (unknown [131.107.160.57]) by linux.microsoft.com (Postfix) with ESMTPSA id A2CE220B7192; Fri, 22 Jan 2021 15:28:38 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A2CE220B7192 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1611358118; bh=gR+E6J/KWkeDvBUKGVIOIRFzbUvo3l+XqkwRbUylShY=; h=From:To:Cc:Subject:Date:From; b=cJpz6cfjkhbrFP40Q2e7ZBMISQNOUwwTdJqxZWE5qiTfeSLhLc4AoN3Rtz6iiJcnM zn+sR4ZBgqxiAvHmqtaMPkEJjJT88/tWHOzbmza6W/vOQ6RYteObtD5TADHxAiZsXB T+iEmNGYAndBv4cV20T1RCiVLwPGBDG7t5VMh1Rs= From: Raphael Gianotti To: zohar@linux.ibm.com Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, tusharsu@linux.microsoft.com, nramas@linux.microsoft.com, tyhicks@linux.microsoft.com Subject: [PATCH v2] IMA: Measure kernel version in early boot Date: Fri, 22 Jan 2021 15:28:27 -0800 Message-Id: <20210122232827.12840-1-raphgi@linux.microsoft.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The integrity of a kernel can be verified by the boot loader on cold boot, and during kexec, by the current running kernel, before it is loaded. However, it is still possible that the new kernel being loaded is older than the current kernel, and/or has known vulnerabilities. Therefore, it is imperative that an attestation service be able to verify the version of the kernel being loaded on the client, from cold boot and subsequent kexec system calls, ensuring that only kernels with versions known to be good are loaded. Measure the kernel version using ima_measure_critical_data() early on in the boot sequence, reducing the chances of known kernel vulnerabilities being exploited. With IMA being part of the kernel, this overall approach makes the measurement itself more trustworthy. To enable measuring the kernel version "ima_policy=critical_data" needs to be added to the kernel command line arguments. For example, BOOT_IMAGE=/boot/vmlinuz-5.11.0-rc3+ root=UUID=fd643309-a5d2-4ed3-b10d-3c579a5fab2f ro nomodeset ima_policy=critical_data If runtime measurement of the kernel version is ever needed, the following should be added to /etc/ima/ima-policy: measure func=CRITICAL_DATA label=kernel_version To extract the measured data after boot, the following command can be used: grep -m 1 "kernel_version" \ /sys/kernel/security/integrity/ima/ascii_runtime_measurements Sample output from the command above: 10 a8297d408e9d5155728b619761d0dd4cedf5ef5f ima-buf sha256:5660e19945be0119bc19cbbf8d9c33a09935ab5d30dad48aa11f879c67d70988 kernel_version 352e31312e302d7263332d31363138372d676564623634666537383234342d6469727479 The above corresponds to the following (decoded) version string: 5.11.0-rc3-16187-gedb64fe78244-dirty This patch is based on commit e58bb688f2e4 "Merge branch 'measure-critical-data' into next-integrity" in "next-integrity-testing" branch Change Log v2: - Changed the measurement to align with the latest version of ima_measure_critical_data(), without the need for queueing - Scoped the measurement to only measure the kernel version, found in UTS_RELEASE, instead of the entire linux_banner string Signed-off-by: Raphael Gianotti --- security/integrity/ima/ima_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 6a429846f90a..0a33f570725c 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "ima.h" @@ -994,8 +995,11 @@ static int __init init_ima(void) if (error) pr_warn("Couldn't register LSM notifier, error %d\n", error); - if (!error) + if (!error) { ima_update_policy_flag(); + ima_measure_critical_data("kernel_version", "kernel_version", + UTS_RELEASE, strlen(UTS_RELEASE), false); + } return error; } -- 2.28.0