From patchwork Thu Mar 13 17:33:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 14015565 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08A4E1C84A1 for ; Thu, 13 Mar 2025 17:34:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887302; cv=none; b=WM0jiCjtBj+s8HK8ki3hei0WFCZ8YJOnsuDyvF6YJ6hEA0R90iTOeY0+3aatGYiF4Bb0R8tdZPTcgvYDoYF8SrGqa9veoDWpcCqCoVWr0N6wJCoVa+rNCu0228S5HzGcrwNSfkf/q03x0Atcsbf5k1XFCvBhw/AUuWUQiO4Llto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887302; c=relaxed/simple; bh=v1rvhmq9flKJdSz5Ye+r21lmnpjN+EZa7Dx6O7Yts0g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uMg0qbI86itq58CYzOCFN42VkepHpBebqwJkZ6TwTsTQbcVLrBxUrMQYRfyzBXfjR1zM8oQsEvqwiaRQ65AVrlT16COgLPesQUwHjTkfdALGl9Dj8+snYVt6oMAO1wMUrxjo5yTLYdgZ/KoPr5fp+udwhGNZVtnigGT8Zcu5AUg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=UuBmwy3i; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=yfYZxTpT; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=UuBmwy3i; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=yfYZxTpT; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="UuBmwy3i"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="yfYZxTpT"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="UuBmwy3i"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="yfYZxTpT" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 42A6F21180; Thu, 13 Mar 2025 17:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741887297; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ov3jCGTl7GwgRNl8Ff+VlfzSKuKGonTrVISwQrPpSHI=; b=UuBmwy3iB4ebdyeo3YELrvg3tEt3ETM4jdQhpXtPj5Cv7FmiMKmw7kkzHEYyqPanxvfngj /ceVG5J2ZWe1bgLW19g7m9hhDmN6duGLnx4VJRvl6IncmStldVDK+qlUvAbKSoUCSNUdV7 8tpA8Fg0jGge4Q7pnArZLYeQO/I8yLQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741887297; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ov3jCGTl7GwgRNl8Ff+VlfzSKuKGonTrVISwQrPpSHI=; b=yfYZxTpTtjKKJzEdNrWGggIWxYUzJ2jgOOfJEn5NO4oAlURlOSwXBvvZMeugw2ItY6AGvs il2Q1rbroxhTzbCw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741887297; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ov3jCGTl7GwgRNl8Ff+VlfzSKuKGonTrVISwQrPpSHI=; b=UuBmwy3iB4ebdyeo3YELrvg3tEt3ETM4jdQhpXtPj5Cv7FmiMKmw7kkzHEYyqPanxvfngj /ceVG5J2ZWe1bgLW19g7m9hhDmN6duGLnx4VJRvl6IncmStldVDK+qlUvAbKSoUCSNUdV7 8tpA8Fg0jGge4Q7pnArZLYeQO/I8yLQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741887297; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ov3jCGTl7GwgRNl8Ff+VlfzSKuKGonTrVISwQrPpSHI=; b=yfYZxTpTtjKKJzEdNrWGggIWxYUzJ2jgOOfJEn5NO4oAlURlOSwXBvvZMeugw2ItY6AGvs il2Q1rbroxhTzbCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 332BA137BA; Thu, 13 Mar 2025 17:34:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id iG1VC0EX02cHQwAAD6G6ig (envelope-from ); Thu, 13 Mar 2025 17:34:57 +0000 From: Nicolai Stange To: Mimi Zohar , Roberto Sassu , Dmitry Kasatkin Cc: Eric Snowberg , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [RFC PATCH v1 1/7] ima: don't expose runtime_measurements for unsupported hashes Date: Thu, 13 Mar 2025 18:33:33 +0100 Message-ID: <20250313173339.3815589-2-nstange@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250313173339.3815589-1-nstange@suse.de> References: <20250313173339.3815589-1-nstange@suse.de> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -5.30 X-Spamd-Result: default: False [-5.30 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; FREEMAIL_TO(0.00)[linux.ibm.com,huawei.com,gmail.com]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_SEVEN(0.00)[8]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; TAGGED_RCPT(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Flag: NO X-Spam-Level: IMA creates one runtime_measurements_ sysfs file for every TPM bank + for SHA1 if not covered by any such. These differ only in that the template hash value for each record is of the file's associated algorithm each. The kernel does not necessarily support each hash algorithm associated with some TPM bank though -- the most common case probably being that the algorithm is not built-in, but provided as a module, if at all, and thus not available at IMA init time yet. If that happens to be the case, the behavior is a bit counter-intuitive: probably for historic reasons and to still extend the TPM bank with something, a record's template hash is filled with the padded SHA1 value. That is, it is perfectly possible that runtime_measurements_sha256 contains padded SHA1 template hashes if SHA-256 was unavailable at IMA init. I would argue that it's likely that no existing userspace tool is relying on this fallback logic -- they either wouldn't consume the hash value from the measurement list directly but recreate it by themselves, as is required for verification against PCRs, or, if they did, they would somehow assume a hash algorithm and expect the hashes in the measurement list to be of that type. If of the latter kind, this could even lead to hard to debug verification failures. For example, from looking at keylime's current code, the verifier logic seems to assume that the template hashes found in the provided measurement list are of the configured 'ima_log_hash_alg' type. In particular, it does not check against padded SHA1 upon mismatch. That being said, there's also another dimension: currently IMA has a hard requirement on SHA-1 and subsequent patches in this series will attempt to get rid of that. If SHA-1 is not available at IMA init though, it would also mean that padded SHA-1 values cannot get filled in as a fallback for other unsupported algorithms. Substituting something like hard coded all-zeroes or all-ones would be dangerous, because some application or user scripts could perhaps (ab)use the template hashes from the exported measurement lists for some kind of fingerprinting scheme or so. In conclusion, I think it's best to not create the runtime_measurements_ sysfs files for hash algorithms not supported by the kernel. That way, applications expecting a certain hash algorithm for the measurement list and which are not able to handle the padded-SHA1 fallback scheme would fail with a clear indication on what the problem is. Furthermore, as digests for unsupported banks are not getting exposed to userspace anymore, we'll have all flexibility to set it to any value internally, including all-ones as will be needed in a subsequent patch when addressing PCR extend for unsupported banks. So, do not create runtime_measurements_ sysfs files for unsupported hash algorithms. Likewise for their ascii counterparts. Note that at this point, SHA-1 is still mandatory, and thus, runtime_measurements_sha1 as well as the "runtime_measurements" will remain there, even though the code has provisions already to skip their creation as well in case SHA-1 was unavailable. Signed-off-by: Nicolai Stange --- security/integrity/ima/ima_fs.c | 35 +++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c index e4a79a9b2d58..a8df2fe5f4cb 100644 --- a/security/integrity/ima/ima_fs.c +++ b/security/integrity/ima/ima_fs.c @@ -454,6 +454,9 @@ static int __init create_securityfs_measurement_lists(void) return -ENOMEM; for (i = 0; i < securityfs_measurement_list_count; i++) { + if (!ima_algo_array[i].tfm) + continue; + algo = ima_algo_array[i].algo; sprintf(file_name, "ascii_runtime_measurements_%s", @@ -573,20 +576,26 @@ int __init ima_fs_init(void) if (ret != 0) goto out; - binary_runtime_measurements = - securityfs_create_symlink("binary_runtime_measurements", ima_dir, - "binary_runtime_measurements_sha1", NULL); - if (IS_ERR(binary_runtime_measurements)) { - ret = PTR_ERR(binary_runtime_measurements); - goto out; - } + if (ima_algo_array[ima_sha1_idx].tfm) { + binary_runtime_measurements = + securityfs_create_symlink("binary_runtime_measurements", + ima_dir, + "binary_runtime_measurements_sha1", + NULL); + if (IS_ERR(binary_runtime_measurements)) { + ret = PTR_ERR(binary_runtime_measurements); + goto out; + } - ascii_runtime_measurements = - securityfs_create_symlink("ascii_runtime_measurements", ima_dir, - "ascii_runtime_measurements_sha1", NULL); - if (IS_ERR(ascii_runtime_measurements)) { - ret = PTR_ERR(ascii_runtime_measurements); - goto out; + ascii_runtime_measurements = + securityfs_create_symlink("ascii_runtime_measurements", + ima_dir, + "ascii_runtime_measurements_sha1", + NULL); + if (IS_ERR(ascii_runtime_measurements)) { + ret = PTR_ERR(ascii_runtime_measurements); + goto out; + } } runtime_measurements_count = From patchwork Thu Mar 13 17:33:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 14015566 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7157B1D5165 for ; Thu, 13 Mar 2025 17:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887305; cv=none; b=et8VvTAgjienJeHQm0rO3BQu7lFY5R7vd33cvldODoQ5E1X4kqDcN9y0GpYas3gnxLZriEXBTEGNvgpf2xIeeFRDiCMTJ2n5rqzPNmnj6es60wvOMz6Z3iGu6CgpBGFHBHE0UDh1ucAfetVlRH5dh2jU9F52ACMDbvpGTI6Qlzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887305; c=relaxed/simple; bh=ofk0dyiGJGUPbX7KRZbBwqReFP1t2mJ0ikjz0JZiPHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sCXKb2JgiW1V7ny6JgL9hXkA770UHSIzf+f6ON5vsNKDnBtqW6IscyavbcKWmzaiDkH8+451UpfQnMXgFHyW5vG15BRJoOnNw14pp/KH3FeXpqQrQ9oiob9wbmEAaxHPb8MZSwF6aY1H9cig+9bm38L9uGknq6wCG5P0ypNSL5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=yYZgIEcS; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=npLhIGwW; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=yYZgIEcS; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=npLhIGwW; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="yYZgIEcS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="npLhIGwW"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="yYZgIEcS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="npLhIGwW" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 98F371F769; Thu, 13 Mar 2025 17:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741887300; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=USlxaMFieu/+hsrqsfqIHnzxT/feUUlitxBTpJXrB0A=; b=yYZgIEcSLtOx0ewkStIVSpei4aI/h2rg7Cd2fJABZjV8oAg3gCpga9bLnA9sg8RfF5Uw1D 9SUzAzgRzYQ0FKiO413dI2WH0pcK55689D7UXSC7dLVFnazvanUkUJeXvicp1voTykXG60 bg5RQoA4OH5wg7Hpu7LCx3YpeEt2nig= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741887300; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=USlxaMFieu/+hsrqsfqIHnzxT/feUUlitxBTpJXrB0A=; b=npLhIGwWRHukPgeghFs+Ofeb/dKs1vyAZkY46PpxpBYPkhOjcbfx+RoEC5NDAGrS0P3QVE qgpGSAeoWZNpoyAA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741887300; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=USlxaMFieu/+hsrqsfqIHnzxT/feUUlitxBTpJXrB0A=; b=yYZgIEcSLtOx0ewkStIVSpei4aI/h2rg7Cd2fJABZjV8oAg3gCpga9bLnA9sg8RfF5Uw1D 9SUzAzgRzYQ0FKiO413dI2WH0pcK55689D7UXSC7dLVFnazvanUkUJeXvicp1voTykXG60 bg5RQoA4OH5wg7Hpu7LCx3YpeEt2nig= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741887300; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=USlxaMFieu/+hsrqsfqIHnzxT/feUUlitxBTpJXrB0A=; b=npLhIGwWRHukPgeghFs+Ofeb/dKs1vyAZkY46PpxpBYPkhOjcbfx+RoEC5NDAGrS0P3QVE qgpGSAeoWZNpoyAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8847B137BA; Thu, 13 Mar 2025 17:35:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id QycUIEQX02cLQwAAD6G6ig (envelope-from ); Thu, 13 Mar 2025 17:35:00 +0000 From: Nicolai Stange To: Mimi Zohar , Roberto Sassu , Dmitry Kasatkin Cc: Eric Snowberg , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [RFC PATCH v1 2/7] ima: always create runtime_measurements sysfs file for ima_hash Date: Thu, 13 Mar 2025 18:33:34 +0100 Message-ID: <20250313173339.3815589-3-nstange@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250313173339.3815589-1-nstange@suse.de> References: <20250313173339.3815589-1-nstange@suse.de> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-5.30 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[99.99%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; FREEMAIL_TO(0.00)[linux.ibm.com,huawei.com,gmail.com]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_SEVEN(0.00)[8]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; TAGGED_RCPT(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Score: -5.30 X-Spam-Flag: NO runtime_measurements_ sysfs files are getting created for each PCR bank + for SHA-1. Now that runtime_measurements_ sysfs file creation is being skipped for unsupported hash algorithms, it will become possible that no such file would be provided at all once SHA-1 is made optional in a later patch. Always create the file for the 'ima_hash' algorithm, even if it's not associated with any of the PCR banks. As IMA initialization will continue to fail if the ima_hash algorithm is not available to the kernel, this guarantees that at least one such file will always be there. Signed-off-by: Nicolai Stange --- security/integrity/ima/ima_fs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c index a8df2fe5f4cb..f030ff7f56da 100644 --- a/security/integrity/ima/ima_fs.c +++ b/security/integrity/ima/ima_fs.c @@ -436,10 +436,8 @@ static int __init create_securityfs_measurement_lists(void) u16 algo; int i; - securityfs_measurement_list_count = NR_BANKS(ima_tpm_chip); - - if (ima_sha1_idx >= NR_BANKS(ima_tpm_chip)) - securityfs_measurement_list_count++; + securityfs_measurement_list_count = + NR_BANKS(ima_tpm_chip) + ima_extra_slots; ascii_securityfs_measurement_lists = kcalloc(securityfs_measurement_list_count, sizeof(struct dentry *), From patchwork Thu Mar 13 17:33:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 14015567 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF86218C006 for ; Thu, 13 Mar 2025 17:35:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887311; cv=none; b=haK5RkwppcHIs2YpQbYKYNtV07S6BRdSE8hrJeqqYF+5lPCvgZ5ok5AIiIUu+SaYoE/I8DDMtV/oNlumYkBRKnyTyZ37TKXHv4IFA18u5THOFWScNVKzpbMxf/P4WC8Mxw4TgnsjMGHiq5MBodL7ziCchmiyM51nIgOBI5daeLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887311; c=relaxed/simple; bh=+/CXGFgCUz0uWuCA+o+zWIoOUsY7OcPsmo/uFiucgO0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JvPPAzF7CPFUyJrYGfK83q3hyTbEqpQoT6T2EPYgiX3/A/DPSNJqD7/hGvV7F2WsqYiRJumrb3FGg2iepoYDAwXoySV5IngKoK0rK5AmhkKXOGbvLaF0sULmZwkNhJ2xqvrlKq/YvlPKI21DAc0k2ZhgRakFGtmPf0nfGetWqT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7612C1F769; Thu, 13 Mar 2025 17:35:07 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 656BB137BA; Thu, 13 Mar 2025 17:35:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id MAiKF0sX02cXQwAAD6G6ig (envelope-from ); Thu, 13 Mar 2025 17:35:07 +0000 From: Nicolai Stange To: Mimi Zohar , Roberto Sassu , Dmitry Kasatkin Cc: Eric Snowberg , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [RFC PATCH v1 3/7] ima: move INVALID_PCR() to ima.h Date: Thu, 13 Mar 2025 18:33:35 +0100 Message-ID: <20250313173339.3815589-4-nstange@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250313173339.3815589-1-nstange@suse.de> References: <20250313173339.3815589-1-nstange@suse.de> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; TAGGED_RCPT(0.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 7612C1F769 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: Make the INVALID_PCR() #define available to other compilation units by moving it from ima_policy.c to ima.h and renaming it to IMA_INVALID_PCR() in the course. Signed-off-by: Nicolai Stange --- security/integrity/ima/ima.h | 4 ++++ security/integrity/ima/ima_policy.c | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index a4f284bd846c..1158a7b8bf6b 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -198,6 +198,10 @@ struct ima_iint_cache { struct ima_digest_data *ima_hash; }; +#define IMA_INVALID_PCR(a) (((a) < 0) || \ + (a) >= (sizeof_field(struct ima_iint_cache, measured_pcrs) * 8)) + + extern struct lsm_blob_sizes ima_blob_sizes; static inline struct ima_iint_cache * diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 128fab897930..d9e4210ea814 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -48,9 +48,6 @@ #define HASH 0x0100 #define DONT_HASH 0x0200 -#define INVALID_PCR(a) (((a) < 0) || \ - (a) >= (sizeof_field(struct ima_iint_cache, measured_pcrs) * 8)) - int ima_policy_flag; static int temp_ima_appraise; static int build_ima_appraise __ro_after_init; @@ -1855,7 +1852,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) ima_log_string(ab, "pcr", args[0].from); result = kstrtoint(args[0].from, 10, &entry->pcr); - if (result || INVALID_PCR(entry->pcr)) + if (result || IMA_INVALID_PCR(entry->pcr)) result = -EINVAL; else entry->flags |= IMA_PCR; From patchwork Thu Mar 13 17:33:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 14015568 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C25521E835C for ; Thu, 13 Mar 2025 17:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887313; cv=none; b=GFPYcbuL6DLPrZRvYXaiyDgICjphixNk0zrifyP2n3qdcXUT8HHk61kFlZue1v+R52uuC27F8Ew8YR9Vg2sSRKL1PN3sq2gVNzmubAg7BG6Xh1dr0xPnisJFlarSTw/C/dn+ZugAyncTaZXtOzHMo33MbCN1cAfyrot5CruWSvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887313; c=relaxed/simple; bh=uVVTskfCompucQ0Jmp6zLdiPS5sGlOV63hkAik5gLE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TMtoQD2e88g8RYlp/7YitVljBue7oLHQNcCeWqUr2IqOPSkDV/Gw6hTscowtEdRV75c0DU85rDHoaAqUBmo6fQDk7Z2TFjqr5RwWbrHBpgLN+/tHtyMXjBohKUBcZRymlyqRaji4P7N1uPE2XeN4SkqS/167fkV9EAJf7BBVRGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 56A0C21175; Thu, 13 Mar 2025 17:35:10 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 466BE137BA; Thu, 13 Mar 2025 17:35:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id RaTvD04X02cdQwAAD6G6ig (envelope-from ); Thu, 13 Mar 2025 17:35:10 +0000 From: Nicolai Stange To: Mimi Zohar , Roberto Sassu , Dmitry Kasatkin Cc: Eric Snowberg , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [RFC PATCH v1 4/7] ima: track the set of PCRs ever extended Date: Thu, 13 Mar 2025 18:33:36 +0100 Message-ID: <20250313173339.3815589-5-nstange@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250313173339.3815589-1-nstange@suse.de> References: <20250313173339.3815589-1-nstange@suse.de> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; TAGGED_RCPT(0.00)[] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: 56A0C21175 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org A subsequent patch will make IMA to invalidate PCR banks associated with unsupported hash algorithms once at a PCR's first use. To prepare for that, make it track the set of PCRs ever extended. Maintain the set of touched PCRs in an unsigned long bitmask, 'ima_extended_pcrs_mask'. Amend the IMA_INVALID_PCR() #define to check that a given PCR can get represented in that bitmask. Note that this is only for improving code maintainablity, it does not actually constain the set of allowed PCR indices any further. Make ima_pcr_extend() to maintain the ima_extended_pcrs_mask, i.e. to set the currently extented PCR's corresponding bit. Make ima_restore_measurement_list() to restore the ima_extended_pcrs_mask from the measurement list in order to maintain it across kexecs. Signed-off-by: Nicolai Stange --- security/integrity/ima/ima.h | 8 ++++++-- security/integrity/ima/ima_queue.c | 6 ++++++ security/integrity/ima/ima_template.c | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 1158a7b8bf6b..f99b1f81b35c 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "../integrity.h" @@ -62,6 +63,8 @@ extern int ima_hash_algo_idx __ro_after_init; extern int ima_extra_slots __ro_after_init; extern struct ima_algo_desc *ima_algo_array __ro_after_init; +extern unsigned long ima_extended_pcrs_mask; + extern int ima_appraise; extern struct tpm_chip *ima_tpm_chip; extern const char boot_aggregate_name[]; @@ -198,8 +201,9 @@ struct ima_iint_cache { struct ima_digest_data *ima_hash; }; -#define IMA_INVALID_PCR(a) (((a) < 0) || \ - (a) >= (sizeof_field(struct ima_iint_cache, measured_pcrs) * 8)) +#define IMA_INVALID_PCR(a) (((a) < 0) || \ + (a) >= (8 * min(sizeof_field(struct ima_iint_cache, measured_pcrs), \ + sizeof(ima_extended_pcrs_mask)))) extern struct lsm_blob_sizes ima_blob_sizes; diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c index 83d53824aa98..f00ba2222c34 100644 --- a/security/integrity/ima/ima_queue.c +++ b/security/integrity/ima/ima_queue.c @@ -51,6 +51,11 @@ static DEFINE_MUTEX(ima_extend_list_mutex); */ static bool ima_measurements_suspended; +/* + * Set of PCRs ever extended by IMA. + */ +unsigned long ima_extended_pcrs_mask; + /* lookup up the digest value in the hash table, and return the entry */ static struct ima_queue_entry *ima_lookup_digest_entry(u8 *digest_value, int pcr) @@ -152,6 +157,7 @@ static int ima_pcr_extend(struct tpm_digest *digests_arg, int pcr) result = tpm_pcr_extend(ima_tpm_chip, pcr, digests_arg); if (result != 0) pr_err("Error Communicating to TPM chip, result: %d\n", result); + ima_extended_pcrs_mask |= BIT(pcr); return result; } diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c index 04c49f05cb74..55d335097d85 100644 --- a/security/integrity/ima/ima_template.c +++ b/security/integrity/ima/ima_template.c @@ -525,12 +525,19 @@ int ima_restore_measurement_list(loff_t size, void *buf) } } + if (IMA_INVALID_PCR(entry->pcr)) { + pr_err("invalid measurement PCR index"); + ret = -EINVAL; + break; + } + entry->pcr = !ima_canonical_fmt ? *(u32 *)(hdr[HDR_PCR].data) : le32_to_cpu(*(__le32 *)(hdr[HDR_PCR].data)); ret = ima_restore_measurement_entry(entry); if (ret < 0) break; + ima_extended_pcrs_mask |= BIT(entry->pcr); } return ret; } From patchwork Thu Mar 13 17:33:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 14015569 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91ECD1C57B2 for ; Thu, 13 Mar 2025 17:35:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887319; cv=none; b=LI3t4tuOl1y6z8RYiUez8IkuJXYWjdDP0MMslIVk3+alvKyPlB++1UZy93q1DfT9VRYSu0Wbhm4wRYYF3dlH8T+P6VBFZQazfIUTtYEFr3pXilWylUJMpY9uW8Ur5UD6pG5WfPjJO/zMu0TxB11hahnKrtj19ul9hzfDOEo5PJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887319; c=relaxed/simple; bh=AsIkeK09hk52nluzfxUarovF7udCAcT3sMsQxqv/FkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hSyjGmt7RHK6/7XSKzDzdpwW/ONSQONle3+fxhP2fhwi9hKwOm/DWQtMbpAV7afccGbZNIpT759/KLqHpWbny+5DEFjGjp7TJwn8NNEpiKJAo3auj7qE5US7bZhpu5O0AP0z5fH3t1PifBkGAXpob2xjS8K7yp/4bDI9PUlPhXk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=kImw4fCp; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=6FL8huor; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=kImw4fCp; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=6FL8huor; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="kImw4fCp"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="6FL8huor"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="kImw4fCp"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="6FL8huor" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 823A421196; Thu, 13 Mar 2025 17:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741887315; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P0m1Yv5mHukwYIyLV3KcW9iiUDiW+55hMfyF/aLIeB8=; b=kImw4fCpmlh8Fob1aahnQGx2a9+eQ0dUeeDUkAcZT1Q7gIB6fgHGOj9ZXbe03YP6CVnzJU yVtZMfqKzmxiwskkcit2MYgjtSGaYBXqTKHOeL5Wc/kuaChwuzOLOoiZz0k+dPNibITo8i dgZAu5n6XRWtA9UgVMBenBIfMZES8Sw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741887315; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P0m1Yv5mHukwYIyLV3KcW9iiUDiW+55hMfyF/aLIeB8=; b=6FL8huorIfULzfGjfXkbQOt1NCpiTHN0FG00kAfmKbBa24hwabMFMAzTQceUoQwqjRkUks qP6EE/O/tZPhjHDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741887315; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P0m1Yv5mHukwYIyLV3KcW9iiUDiW+55hMfyF/aLIeB8=; b=kImw4fCpmlh8Fob1aahnQGx2a9+eQ0dUeeDUkAcZT1Q7gIB6fgHGOj9ZXbe03YP6CVnzJU yVtZMfqKzmxiwskkcit2MYgjtSGaYBXqTKHOeL5Wc/kuaChwuzOLOoiZz0k+dPNibITo8i dgZAu5n6XRWtA9UgVMBenBIfMZES8Sw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741887315; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P0m1Yv5mHukwYIyLV3KcW9iiUDiW+55hMfyF/aLIeB8=; b=6FL8huorIfULzfGjfXkbQOt1NCpiTHN0FG00kAfmKbBa24hwabMFMAzTQceUoQwqjRkUks qP6EE/O/tZPhjHDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 72872137BA; Thu, 13 Mar 2025 17:35:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id JWTLGlMX02chQwAAD6G6ig (envelope-from ); Thu, 13 Mar 2025 17:35:15 +0000 From: Nicolai Stange To: Mimi Zohar , Roberto Sassu , Dmitry Kasatkin Cc: Eric Snowberg , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [RFC PATCH v1 5/7] tpm: enable bank selection for PCR extend Date: Thu, 13 Mar 2025 18:33:37 +0100 Message-ID: <20250313173339.3815589-6-nstange@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250313173339.3815589-1-nstange@suse.de> References: <20250313173339.3815589-1-nstange@suse.de> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-5.30 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_TO(0.00)[linux.ibm.com,huawei.com,gmail.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_SEVEN(0.00)[8]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Score: -5.30 X-Spam-Flag: NO The existing tpm_pcr_extend() extends all of a PCR's allocated banks with the corresponding digest from the provided digests[] argument. An upcoming code change to IMA will introduce the need to skip over those banks it does not have a hash algorithm implementation available for. Introduce tpm_pcr_extend_sel() to support this. tpm_pcr_extend_sel() also expects a digests[] array, always being the number of allocated PCR banks in size, just as it's the case for the existing tpm_pcr_extend(). In addition to that however, it takes a 'banks_skip_mask', and will skip the extension of any bank having its corresponding bit set there. Signed-off-by: Nicolai Stange --- drivers/char/tpm/tpm-interface.c | 29 +++++++++++++++++++++++++++-- drivers/char/tpm/tpm.h | 3 ++- drivers/char/tpm/tpm2-cmd.c | 29 +++++++++++++++++++++++++++-- include/linux/tpm.h | 3 +++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index b1daa0d7b341..2bab251034b5 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -314,6 +314,26 @@ EXPORT_SYMBOL_GPL(tpm_pcr_read); */ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, struct tpm_digest *digests) +{ + return tpm_pcr_extend_sel(chip, pcr_idx, digests, 0); +} +EXPORT_SYMBOL_GPL(tpm_pcr_extend); + +/** + * tpm_pcr_extend_sel - extend a PCR value into selected banks. + * @chip: a &struct tpm_chip instance, %NULL for the default chip + * @pcr_idx: the PCR to be retrieved + * @digests: array of tpm_digest structures used to extend PCRs + * @banks_skip_mask: pcr banks to skip + * + * Note: callers must pass a digest for every allocated PCR bank, in the same + * order of the banks in chip->allocated_banks. + * + * Return: same as with tpm_transmit_cmd() + */ +int tpm_pcr_extend_sel(struct tpm_chip *chip, u32 pcr_idx, + struct tpm_digest *digests, + unsigned long banks_skip_mask) { int rc; int i; @@ -330,7 +350,13 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, } if (chip->flags & TPM_CHIP_FLAG_TPM2) { - rc = tpm2_pcr_extend(chip, pcr_idx, digests); + rc = tpm2_pcr_extend(chip, pcr_idx, digests, 0); + goto out; + } + + /* There's only one SHA1 bank with TPM 1. */ + if (banks_skip_mask & 1) { + rc = 0; goto out; } @@ -341,7 +367,6 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, tpm_put_ops(chip); return rc; } -EXPORT_SYMBOL_GPL(tpm_pcr_extend); int tpm_auto_startup(struct tpm_chip *chip) { diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 7bb87fa5f7a1..f4ed49cb4101 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -291,7 +291,8 @@ int tpm2_get_timeouts(struct tpm_chip *chip); int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, struct tpm_digest *digest, u16 *digest_size_ptr); int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, - struct tpm_digest *digests); + struct tpm_digest *digests, + unsigned long banks_skip_mask); int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max); ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, u32 *value, const char *desc); diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index dfdcbd009720..23ded8ea47dc 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -226,16 +226,34 @@ int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, * @chip: TPM chip to use. * @pcr_idx: index of the PCR. * @digests: list of pcr banks and corresponding digest values to extend. + * @banks_skip_mask: pcr banks to skip * * Return: Same as with tpm_transmit_cmd. */ int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, - struct tpm_digest *digests) + struct tpm_digest *digests, + unsigned long banks_skip_mask) { struct tpm_buf buf; + unsigned long skip_mask; + u32 banks_count; int rc; int i; + banks_count = 0; + skip_mask = banks_skip_mask; + for (i = 0; i < chip->nr_allocated_banks; i++) { + const bool skip_bank = skip_mask & 1; + + skip_mask >>= 1; + if (skip_bank) + continue; + banks_count++; + } + + if (banks_count == 0) + return 0; + if (!disable_pcr_integrity) { rc = tpm2_start_auth_session(chip); if (rc) @@ -257,9 +275,16 @@ int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, tpm_buf_append_auth(chip, &buf, 0, NULL, 0); } - tpm_buf_append_u32(&buf, chip->nr_allocated_banks); + tpm_buf_append_u32(&buf, banks_count); + skip_mask = banks_skip_mask; for (i = 0; i < chip->nr_allocated_banks; i++) { + const bool skip_bank = skip_mask & 1; + + skip_mask >>= 1; + if (skip_bank) + continue; + tpm_buf_append_u16(&buf, digests[i].alg_id); tpm_buf_append(&buf, (const unsigned char *)&digests[i].digest, chip->allocated_banks[i].digest_size); diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 20a40ade8030..7587eecc82fd 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -447,6 +447,9 @@ extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, struct tpm_digest *digest); extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, struct tpm_digest *digests); +extern int tpm_pcr_extend_sel(struct tpm_chip *chip, u32 pcr_idx, + struct tpm_digest *digests, + unsigned long banks_skip_mask); extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max); extern struct tpm_chip *tpm_default_chip(void); void tpm2_flush_context(struct tpm_chip *chip, u32 handle); From patchwork Thu Mar 13 17:33:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 14015570 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45F1F1BB6BA for ; Thu, 13 Mar 2025 17:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887328; cv=none; b=XIeffg0rflN0E7zP3YZ7eMy2uYUGmg8SUr2+EoYhx6nMYTE9iaCV0XHqz+6ID4GGuUDDJSo/HoJAHy6Y06H+bMsia8EAx8bEfA3L2lQHznGE5x3yz+E9lSffQdZ2PckUy2Yg18dXbumq9kmSMZNjf1YwJ4dbEJME3AsWMwVyxGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887328; c=relaxed/simple; bh=8arRVF8Ot/JXKah4Mg83WJFCmCwufI/OEu7Cnmyg7CA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LewkuYHQhijvpGEd0wmcxFr5ObYs6Y4cer4IYGOUh3f6dPhamAyG2mkmLAePMtbs9+H0ncjX6CqYGLQpLajbCjsBLxjlZcUwAlhV+mUPf1FLKHSRGxttHv9rzfVUYV0t10P/mAgW0EGNhFkJNph547isiJaZMDwAzEGrK0+wLy4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BE4611F769; Thu, 13 Mar 2025 17:35:24 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id AE86D137BA; Thu, 13 Mar 2025 17:35:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 57FjKVwX02cqQwAAD6G6ig (envelope-from ); Thu, 13 Mar 2025 17:35:24 +0000 From: Nicolai Stange To: Mimi Zohar , Roberto Sassu , Dmitry Kasatkin Cc: Eric Snowberg , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [RFC PATCH v1 6/7] ima: invalidate unsupported PCR banks once at first use Date: Thu, 13 Mar 2025 18:33:38 +0100 Message-ID: <20250313173339.3815589-7-nstange@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250313173339.3815589-1-nstange@suse.de> References: <20250313173339.3815589-1-nstange@suse.de> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; TAGGED_RCPT(0.00)[] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: BE4611F769 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org Normally IMA would extend a template hash of each bank's associated algorithm into a PCR. However, if a bank's hash algorithm is unavailable to the kernel at IMA init time, it would fallback to extending padded SHA1 hashes instead. That is, if e.g. SHA-256 was missing at IMA init, it would extend padded SHA1 template hashes into a PCR's SHA-256 bank. The ima_measurement command (marked as experimental) from ima-evm-utils would accordingly try both variants when attempting to verify a measurement list against PCRs. keylime OTOH doesn't seem to -- it expects the template hash type to match the PCR bank algorithm. I would argue that for the latter case, the fallback scheme could potentially cause hard to debug verification failures. There's another problem with the fallback scheme: right now, SHA-1 availability is a hard requirement for IMA, and it would be good for a number of reasons to get rid of that. However, if SHA-1 is not available to the kernel, it can hardly provide padded SHA-1 template hashes for PCR banks with unsupported algos. There are several more or less reasonable alternatives possible, among them are: a.) Instead of padded SHA-1, use padded/truncated ima_hash template hashes. b.) Record every event as a violation, i.e. extend unsupported banks with 0xffs. c.) Don't extend unsupported banks at all. d.) Invalidate unsupported banks only once (e.g. with 0xffs) at first use. a.) would make verification from tools like ima_measurement nearly impossible, as it would have to guess or somehow determine ima_hash. b.) would still put an significant and unnecessary burden on tools like ima_measurement, because it would then have to exercise three possible variants on the measurement list: - the template hash matches the bank algorithm, - the template hash is padded SHA-1, - the template hash is all-ones. c.) is a security risk, because the bank would validate an empty measurement list. AFAICS, d.) is the best option to proceed, as it allows for determining from the PCR bank value in O(1) whether the bank had been maintained by IMA or not and also, it would not validate any measurement list (except one with a single violation entry at the head). So implement d.). As it potentially breaks existing userspace, i.e. the current implementation of ima_measurement, put it behind a Kconfig option, "IMA_COMPAT_FALLBACK_TPM_EXTEND". If set to "y", the original behavior of extending with padded SHA-1 is retained. Otherwise the new scheme to invalidate unsupported PCR banks once upon their first extension from IMA is implemented instead. As ima_measurement is marked as experimental and I find it unlikely that other existing tools depend on the padded SHA-1 fallback scheme, make the IMA_COMPAT_FALLBACK_TPM_EXTEND Kconfig option default to "n". For IMA_COMPAT_FALLBACK_TPM_EXTEND=n, - make ima_calc_field_array_hash() to fill the digests corresponding to banks with unsupported hash algorithms with 0xffs, - make ima_pcr_extend() to extend these into the unsupported PCR banks only upon the PCR's first usage, skip them on subsequent updates and - let ima_init_ima_crypto() help it with that by populating the new ima_unsupported_tpm_banks_mask with one bit set for each bank with an unavailable hash algorithm at init. [1] https://github.com/linux-integrity/ima-evm-utils Signed-off-by: Nicolai Stange --- security/integrity/ima/Kconfig | 14 ++++++++++++++ security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_crypto.c | 27 +++++++++++++++++++++++++-- security/integrity/ima/ima_queue.c | 20 +++++++++++++++++++- 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/security/integrity/ima/Kconfig b/security/integrity/ima/Kconfig index 475c32615006..d6ba392c0b37 100644 --- a/security/integrity/ima/Kconfig +++ b/security/integrity/ima/Kconfig @@ -122,6 +122,20 @@ config IMA_DEFAULT_HASH default "wp512" if IMA_DEFAULT_HASH_WP512 default "sm3" if IMA_DEFAULT_HASH_SM3 +config IMA_COMPAT_FALLBACK_TPM_EXTEND + bool + default n + help + In case a TPM PCR hash algorithm is not supported by the kernel, + retain the old behaviour to extend the bank with padded SHA1 template + digests. + + If Y, IMA will be unavailable when SHA1 is missing from the kernel. + If N, existing tools may fail to verify IMA measurement lists against + TPM PCR banks corresponding to hashes not supported by the kernel. + + If unsure, say N. + config IMA_WRITE_POLICY bool "Enable multiple writes to the IMA policy" default n diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index f99b1f81b35c..58e9a81b3f96 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -62,6 +62,7 @@ extern int ima_sha1_idx __ro_after_init; extern int ima_hash_algo_idx __ro_after_init; extern int ima_extra_slots __ro_after_init; extern struct ima_algo_desc *ima_algo_array __ro_after_init; +extern unsigned long ima_unsupported_tpm_banks_mask __ro_after_init; extern unsigned long ima_extended_pcrs_mask; diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index 6f5696d999d0..118ea15d737b 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -67,6 +67,8 @@ int ima_extra_slots __ro_after_init; struct ima_algo_desc *ima_algo_array __ro_after_init; +unsigned long ima_unsupported_tpm_banks_mask __ro_after_init; + static int __init ima_init_ima_crypto(void) { long rc; @@ -150,8 +152,10 @@ int __init ima_init_crypto(void) ima_algo_array[i].algo = algo; /* unknown TPM algorithm */ - if (algo == HASH_ALGO__LAST) + if (algo == HASH_ALGO__LAST) { + ima_unsupported_tpm_banks_mask |= BIT(i); continue; + } if (algo == ima_hash_algo) { ima_algo_array[i].tfm = ima_shash_tfm; @@ -167,6 +171,7 @@ int __init ima_init_crypto(void) } ima_algo_array[i].tfm = NULL; + ima_unsupported_tpm_banks_mask |= BIT(i); } } @@ -625,26 +630,44 @@ int ima_calc_field_array_hash(struct ima_field_data *field_data, u16 alg_id; int rc, i; +#if IS_ENABLED(CONFIG_IMA_COMPAT_FALLBACK_TPM_EXTEND) rc = ima_calc_field_array_hash_tfm(field_data, entry, ima_sha1_idx); if (rc) return rc; entry->digests[ima_sha1_idx].alg_id = TPM_ALG_SHA1; +#endif for (i = 0; i < NR_BANKS(ima_tpm_chip) + ima_extra_slots; i++) { +#if IS_ENABLED(CONFIG_IMA_COMPAT_FALLBACK_TPM_EXTEND) if (i == ima_sha1_idx) continue; +#endif if (i < NR_BANKS(ima_tpm_chip)) { alg_id = ima_tpm_chip->allocated_banks[i].alg_id; entry->digests[i].alg_id = alg_id; } - /* for unmapped TPM algorithms digest is still a padded SHA1 */ + /* + * For unmapped TPM algorithms, the digest is still a + * padded SHA1 if backwards-compatibility fallback PCR + * extension is enabled. Otherwise fill with + * 0xffs. This is the value to invalidate unsupported + * PCR banks with once at first PCR use. Also, a + * non-all-zeroes value serves as an indicator to + * kexec measurement restoration that the entry is not + * a violation and all its template digests need to + * get recomputed. + */ if (!ima_algo_array[i].tfm) { +#if IS_ENABLED(CONFIG_IMA_COMPAT_FALLBACK_TPM_EXTEND) memcpy(entry->digests[i].digest, entry->digests[ima_sha1_idx].digest, TPM_DIGEST_SIZE); +#else + memset(entry->digests[i].digest, 0xff, TPM_DIGEST_SIZE); +#endif continue; } diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c index f00ba2222c34..4db6c4be58fc 100644 --- a/security/integrity/ima/ima_queue.c +++ b/security/integrity/ima/ima_queue.c @@ -150,11 +150,27 @@ unsigned long ima_get_binary_runtime_size(void) static int ima_pcr_extend(struct tpm_digest *digests_arg, int pcr) { int result = 0; + unsigned long tpm_banks_skip_mask; if (!ima_tpm_chip) return result; - result = tpm_pcr_extend(ima_tpm_chip, pcr, digests_arg); +#if !IS_ENABLED(CONFIG_IMA_COMPAT_FALLBACK_TPM_EXTEND) + tpm_banks_skip_mask = ima_unsupported_tpm_banks_mask; + if (!(ima_extended_pcrs_mask & BIT(pcr))) { + /* + * Invalidate unsupported banks once upon a PCR's + * first usage. Note that the digests[] entries for + * unsupported algorithms have been filled with 0xffs. + */ + tpm_banks_skip_mask = 0; + } +#else + tpm_banks_skip_mask = 0; +#endif + + result = tpm_pcr_extend_sel(ima_tpm_chip, pcr, digests_arg, + tpm_banks_skip_mask); if (result != 0) pr_err("Error Communicating to TPM chip, result: %d\n", result); ima_extended_pcrs_mask |= BIT(pcr); @@ -280,9 +296,11 @@ int __init ima_init_digests(void) digest_size = ima_tpm_chip->allocated_banks[i].digest_size; crypto_id = ima_tpm_chip->allocated_banks[i].crypto_id; +#if IS_ENABLED(CONFIG_IMA_COMPAT_FALLBACK_TPM_EXTEND) /* for unmapped TPM algorithms digest is still a padded SHA1 */ if (crypto_id == HASH_ALGO__LAST) digest_size = SHA1_DIGEST_SIZE; +#endif memset(digests[i].digest, 0xff, digest_size); } From patchwork Thu Mar 13 17:33:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 14015571 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12D251D5AB5 for ; Thu, 13 Mar 2025 17:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887335; cv=none; b=NChCZxy/T+kI7MCt7DROE7xFkyYsB1ERwTijbIg0Ju4GlBaAfpO8Oq3W+muHo3YbUWauLAMHEI/+VbrVYk+rOfmUpz26lFhwe1KoRSMCMv1aNSaEZEepSeEiKQz9taeyKQPkMusWEQNbXcn6oUDv8ofZLzHsDHE8QhWemBssUjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741887335; c=relaxed/simple; bh=vQdoq9CEvtCoxe0/XgIj7OuZW3qXJ4NL8kAMzq1rRbM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aR57/3JsemVybuBv45uiunh52o1aOg2EQbmwg9233x30dyY40qtN74R7ygq33QFxNUe5r3Q+xso2obDe28gncypfMGUBIOnUhF0L8iuu3v3iXfwKKc7z1b6MX5FwwN/NllexxmbFCAM4oxcKwoO+sjWTxYIdDMgOJNMERJgjTzc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=y1NGj7YI; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=0CctoGQm; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=y1NGj7YI; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=0CctoGQm; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="y1NGj7YI"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="0CctoGQm"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="y1NGj7YI"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="0CctoGQm" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 712A01F76B; Thu, 13 Mar 2025 17:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741887332; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AssL4APWosYRwux5Sl/5PXBGFriuHOGNHF7c4W1mHz4=; b=y1NGj7YI236QfMjWfjyv7LrwSGiLStdfqnuRlM/CfAdhXKWKN4iTh2TRCrHzstePyZi12z +jPHKtd85Q3xbppcEPJoFHJ0lt4wfypY2T3zUTirUov+7hJc6c1pcTe1z9M99oouxg3cE+ 33y7xP7FMuqZBEhC8J2ZIqGLP+JiiAU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741887332; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AssL4APWosYRwux5Sl/5PXBGFriuHOGNHF7c4W1mHz4=; b=0CctoGQmht81QUlHsTv3wXnswkFWaKpZaDxclDD902ge4IuSoD8+Egh84CnLffg3g3M+9p gGX9yD+fq9CwKVDQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1741887332; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AssL4APWosYRwux5Sl/5PXBGFriuHOGNHF7c4W1mHz4=; b=y1NGj7YI236QfMjWfjyv7LrwSGiLStdfqnuRlM/CfAdhXKWKN4iTh2TRCrHzstePyZi12z +jPHKtd85Q3xbppcEPJoFHJ0lt4wfypY2T3zUTirUov+7hJc6c1pcTe1z9M99oouxg3cE+ 33y7xP7FMuqZBEhC8J2ZIqGLP+JiiAU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1741887332; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AssL4APWosYRwux5Sl/5PXBGFriuHOGNHF7c4W1mHz4=; b=0CctoGQmht81QUlHsTv3wXnswkFWaKpZaDxclDD902ge4IuSoD8+Egh84CnLffg3g3M+9p gGX9yD+fq9CwKVDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6105E137BA; Thu, 13 Mar 2025 17:35:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uzqGFmQX02cwQwAAD6G6ig (envelope-from ); Thu, 13 Mar 2025 17:35:32 +0000 From: Nicolai Stange To: Mimi Zohar , Roberto Sassu , Dmitry Kasatkin Cc: Eric Snowberg , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [RFC PATCH v1 7/7] ima: make SHA1 non-mandatory Date: Thu, 13 Mar 2025 18:33:39 +0100 Message-ID: <20250313173339.3815589-8-nstange@suse.de> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250313173339.3815589-1-nstange@suse.de> References: <20250313173339.3815589-1-nstange@suse.de> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-5.30 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_TO(0.00)[linux.ibm.com,huawei.com,gmail.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_SEVEN(0.00)[8]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Score: -5.30 X-Spam-Flag: NO For CONFIG_IMA_COMPAT_FALLBACK_TPM_EXTEND=n, SHA-1 is not a hard requirement anymore. Make ima_init_crypto() continue on SHA-1 instantiation errors. Note that the configure ima_hash must still be available. If that happened to be set to SHA-1 and SHA-1 was missing, then IMA would still fail to initialize. Signed-off-by: Nicolai Stange --- security/integrity/ima/ima_crypto.c | 60 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index 118ea15d737b..f68435f2679f 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -147,56 +147,51 @@ int __init ima_init_crypto(void) goto out; } + ima_algo_array[ima_hash_algo_idx].tfm = ima_shash_tfm; + ima_algo_array[ima_hash_algo_idx].algo = ima_hash_algo; + + if (ima_hash_algo != HASH_ALGO_SHA1) { + ima_algo_array[ima_sha1_idx].tfm = + ima_alloc_tfm(HASH_ALGO_SHA1); + if (IS_ERR(ima_algo_array[ima_sha1_idx].tfm)) { +#if IS_ENABLED(CONFIG_IMA_COMPAT_FALLBACK_TPM_EXTEND) + /* + * For backwards compatible fallback PCR + * extension, SHA1 is the fallback for missing + * algos. + */ + rc = PTR_ERR(ima_algo_array[ima_sha1_idx].tfm); + goto out_array; +#endif + ima_algo_array[ima_sha1_idx].tfm = NULL; + ima_unsupported_tpm_banks_mask |= BIT(ima_sha1_idx); + } + ima_algo_array[ima_sha1_idx].algo = HASH_ALGO_SHA1; + } + for (i = 0; i < NR_BANKS(ima_tpm_chip); i++) { algo = ima_tpm_chip->allocated_banks[i].crypto_id; ima_algo_array[i].algo = algo; + /* Initialized separately above. */ + if (i == ima_hash_algo_idx || i == ima_sha1_idx) + continue; + /* unknown TPM algorithm */ if (algo == HASH_ALGO__LAST) { ima_unsupported_tpm_banks_mask |= BIT(i); continue; } - if (algo == ima_hash_algo) { - ima_algo_array[i].tfm = ima_shash_tfm; - continue; - } - ima_algo_array[i].tfm = ima_alloc_tfm(algo); if (IS_ERR(ima_algo_array[i].tfm)) { - if (algo == HASH_ALGO_SHA1) { - rc = PTR_ERR(ima_algo_array[i].tfm); - ima_algo_array[i].tfm = NULL; - goto out_array; - } - ima_algo_array[i].tfm = NULL; ima_unsupported_tpm_banks_mask |= BIT(i); } } - if (ima_sha1_idx >= NR_BANKS(ima_tpm_chip)) { - if (ima_hash_algo == HASH_ALGO_SHA1) { - ima_algo_array[ima_sha1_idx].tfm = ima_shash_tfm; - } else { - ima_algo_array[ima_sha1_idx].tfm = - ima_alloc_tfm(HASH_ALGO_SHA1); - if (IS_ERR(ima_algo_array[ima_sha1_idx].tfm)) { - rc = PTR_ERR(ima_algo_array[ima_sha1_idx].tfm); - goto out_array; - } - } - - ima_algo_array[ima_sha1_idx].algo = HASH_ALGO_SHA1; - } - - if (ima_hash_algo_idx >= NR_BANKS(ima_tpm_chip) && - ima_hash_algo_idx != ima_sha1_idx) { - ima_algo_array[ima_hash_algo_idx].tfm = ima_shash_tfm; - ima_algo_array[ima_hash_algo_idx].algo = ima_hash_algo; - } - return 0; +#if IS_ENABLED(CONFIG_IMA_COMPAT_FALLBACK_TPM_EXTEND) out_array: for (i = 0; i < NR_BANKS(ima_tpm_chip) + ima_extra_slots; i++) { if (!ima_algo_array[i].tfm || @@ -206,6 +201,7 @@ int __init ima_init_crypto(void) crypto_free_shash(ima_algo_array[i].tfm); } kfree(ima_algo_array); +#endif out: crypto_free_shash(ima_shash_tfm); return rc;