From: Danny Hu <dannyhu@arista.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Mimi Zohar <zohar@linux.ibm.com>,
Roberto Sassu <roberto.sassu@huawei.com>,
Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
Eric Snowberg <eric.snowberg@oracle.com>, Jan Kara <jack@suse.cz>,
Victor Kamensky <kamensky@cisco.com>,
Taras Kondratiuk <takondra@cisco.com>,
Tianxing Zhang <zhangtianxing3@huawei.com>,
Zheng Zengkai <zhengzengkai@huawei.com>,
zhoushuiqing <zhoushuiqing2@huawei.com>,
zhangguangzhi <zhangguangzhi3@huawei.com>,
Danny Hu <dannyhu@arista.com>, Jason Yan <yanaijie@huawei.com>,
silviu.vlasceanu@huawei.com, hpa@zytor.com, arnd@arndb.de,
rob@landley.net, james.w.mcmechan@gmail.com,
niveditas98@gmail.com, pierre@arista.com, julien@arista.com,
kbharathi@arista.com, erosca@de.adit-jv.com,
alexandr.lobakin@intel.com, jim_baxter@mentor.com,
linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kbuild@vger.kernel.org, initramfs@vger.kernel.org,
linux-api@vger.kernel.org, linux-kernel@vger.kernel.org,
bug-cpio@gnu.org
Subject: [PATCH v5 1/4] ima: skip algorithm availability check until initramfs unpacking is finished
Date: Fri, 30 Oct 2026 14:09:40 -0700 [thread overview]
Message-ID: <20261030210944.2143778-2-dannyhu@arista.com> (raw)
In-Reply-To: <20261030210944.2143778-1-dannyhu@arista.com>
With CONFIG_IMA_APPRAISE=y, restoring xattrs during initramfs unpacking
can deadlock the kernel if the xattr being restored is signed with a hash
that the kernel does not already have available. This occurs when the
ima_inode_setxattr() hook calls crypto_has_alg(). crypto_has_alg() may
synchronously request a module leading to a circular dependency where the
userspace helper waits for initramfs unpacking to complete while initramfs
unpacking waits for the userspace helper.
Guard this crypto availability check in validate_hash_algo() until
initramfs unpacking is complete. This prevents the kernel from requesting
a module during unpacking and allows security.ima xattrs to be restored
even if the hash algorithm is unavailable in the running kernel.
Essentially, this flag distinguishes restoration of existing metadata
during initial population from setting/changing an xattr during runtime.
A benefit of this approach is that once unpacking is complete, all
subsequent xattr updates go through the same codepath as before which
preserves the existing behavior during normal userspace operation.
Signed-off-by: Danny Hu <dannyhu@arista.com>
---
security/integrity/ima/ima_appraise.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
index 63b0cb957c65..1403f5653973 100644
--- a/security/integrity/ima/ima_appraise.c
+++ b/security/integrity/ima/ima_appraise.c
@@ -20,6 +20,14 @@
#include "ima.h"
+static bool ima_initramfs_populated __ro_after_init =
+ !IS_ENABLED(CONFIG_BLK_DEV_INITRD);
+
+static void ima_notify_initramfs_populated(void)
+{
+ ima_initramfs_populated = true;
+}
+
#ifdef CONFIG_IMA_APPRAISE_BOOTPARAM
static char *ima_appraise_cmdline_default __initdata;
core_param(ima_appraise, ima_appraise_cmdline_default, charp, 0);
@@ -738,6 +746,22 @@ static int validate_hash_algo(struct dentry *dentry,
if (likely(xattr_hash_algo == ima_hash_algo))
return 0;
+ /*
+ * IMA validates the crypto algorithm whenever the security.ima
+ * xattr is set. Restoring xattrs during initramfs unpacking
+ * can call crypto_has_alg() before unpacking has completed.
+ *
+ * If the algo is unavailable, crypto_has_alg() may
+ * synchronously request a module. The userspace helper waits
+ * for initramfs unpacking to finish and creates a circular
+ * dependency.
+ *
+ * Skip the algorithm availability check until initramfs is
+ * populated to avoid this deadlock.
+ */
+ if (!ima_initramfs_populated)
+ return 0;
+
/* allow any xattr using an algorithm built in the kernel */
if (crypto_has_alg(hash_algo_name[xattr_hash_algo], 0, 0))
return 0;
@@ -829,6 +853,7 @@ static struct security_hook_list ima_appraise_hooks[] __ro_after_init = {
LSM_HOOK_INIT(inode_set_acl, ima_inode_set_acl),
LSM_HOOK_INIT(inode_removexattr, ima_inode_removexattr),
LSM_HOOK_INIT(inode_remove_acl, ima_inode_remove_acl),
+ LSM_HOOK_INIT(initramfs_populated, ima_notify_initramfs_populated),
};
void __init init_ima_appraise_lsm(const struct lsm_id *lsmid)
--
2.51.0
next prev parent reply other threads:[~2026-10-30 21:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 21:09 [PATCH v5 0/4] initramfs: add support for xattrs in the initial ram disk Danny Hu
2026-10-30 21:09 ` Danny Hu [this message]
2026-10-30 21:09 ` [PATCH v5 2/4] initramfs: add file metadata Danny Hu
2026-10-30 21:09 ` [PATCH v5 3/4] initramfs: read metadata from special file METADATA!!! Danny Hu
2026-10-30 21:09 ` [PATCH v5 4/4] gen_init_cpio: add support for file metadata Danny Hu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261030210944.2143778-2-dannyhu@arista.com \
--to=dannyhu@arista.com \
--cc=alexandr.lobakin@intel.com \
--cc=arnd@arndb.de \
--cc=brauner@kernel.org \
--cc=bug-cpio@gnu.org \
--cc=dmitry.kasatkin@gmail.com \
--cc=eric.snowberg@oracle.com \
--cc=erosca@de.adit-jv.com \
--cc=hpa@zytor.com \
--cc=initramfs@vger.kernel.org \
--cc=jack@suse.cz \
--cc=james.w.mcmechan@gmail.com \
--cc=jim_baxter@mentor.com \
--cc=julien@arista.com \
--cc=kamensky@cisco.com \
--cc=kbharathi@arista.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=niveditas98@gmail.com \
--cc=pierre@arista.com \
--cc=rob@landley.net \
--cc=roberto.sassu@huawei.com \
--cc=silviu.vlasceanu@huawei.com \
--cc=takondra@cisco.com \
--cc=viro@zeniv.linux.org.uk \
--cc=yanaijie@huawei.com \
--cc=zhangguangzhi3@huawei.com \
--cc=zhangtianxing3@huawei.com \
--cc=zhengzengkai@huawei.com \
--cc=zhoushuiqing2@huawei.com \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox