On 2026/7/13 20:06, Roberto Sassu wrote:
On Mon, 2026-07-13 at 11:10 +0000, Gaosheng Cui wrote:
When hashing large files, the while loop in ima_calc_file_hash_tfm
processes PAGE_SIZE chunks without any scheduling point, which can
cause soft lockup warnings:
watchdog: BUG: soft lockup - CPU#0 stuck for 50s!
Call Trace:
   _sha256_update+0x12d/0x1a0
   ima_calc_file_hash_tfm+0xfb/0x150
   ima_calc_file_hash+0x6e/0x160
   ima_collect_measurement+0x202/0x340
   process_measurement+0x3a9/0xb30
   ima_file_check+0x56/0xa0
   do_open+0x11b/0x250
   path_openat+0x10b/0x1d0
   do_filp_open+0xa9/0x150
   do_sys_openat2+0x223/0x2a0
   __x64_sys_openat+0x54/0xa0
   do_syscall_64+0x59/0x110
   entry_SYSCALL_64_after_hwframe+0x78/0xe2

Add cond_resched() at the end of each loop iteration to voluntarily
yield the CPU when needed.

Fixes: 3323eec921ef ("integrity: IMA as an integrity service provider")
Signed-off-by: Gaosheng Cui <[email protected]>
---
  security/integrity/ima/ima_crypto.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/security/integrity/ima/ima_crypto.c 
b/security/integrity/ima/ima_crypto.c
index 0d72b48249ee..3b7d41a9fd18 100644
--- a/security/integrity/ima/ima_crypto.c
+++ b/security/integrity/ima/ima_crypto.c
@@ -233,6 +233,8 @@ static int ima_calc_file_hash_tfm(struct file *file,
                rc = crypto_shash_update(shash, rbuf, rbuf_len);
                if (rc)
                        break;
+
+               cond_resched();
I would recommend not doing at every loop but every 4 MB at least:

if (IS_ALIGNED(offset, SZ_4M))
         cond_resched();

Thanks

Roberto

Thanks,

I've updated to patch v2,call cond_resched() every 4MB.

        }
        kfree(rbuf);
  out:
.

Reply via email to