From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796400939; b=cBQuGCqz1T/tQe5ebYS5Ei94MKUDAUqEBBbTarNZOevnPKI8yNocoRXJ8wICeDZEBegw lDzswwD/lI6G5ITaYa36Zd5kyJCnC5PjBvBhLHcRega3iOjrnmwTTmuh4tyA85C/xBXHG kL2NxabwYHL/5ZZuUKSid0GaeWA4Gjh7HbXGnMzNTe2UJxo6z3A4rdL5Se6p/pahFGnZ8 1fiyoeZTNXYVVoSY6hKT2AlX0WLF8cvwoI20L5nRVxfnQflti1L556UtDJW4Ff/Z/XXIf T7BDFCcS6g+f3CSpWeow+ypFAn7vNYBzDfPGmE35KV9rcYAdI1kqAYEp8XmFLyioW6Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400939; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=OKYf3xQVh9aYICRrxKSCBOwDIlVNTZ8HB3bfv+1kETQ=; b=LY/EtgqWWzYScMdBzJX0kpAEbbrq49N4BKpxyJcTj9PG4qkW1DufqUq10Ayr9xWNIP1o 9iKwWHiUz0gWQFeSUTZI2NclUnUGY3u9cMuuEr+PsA5CpRRAnRDJsqgVtqa9V0OzLN+Is H/J1OxV4crmpyiCb2Acfa435TcFZQXGQ9c/ccCu9UUAmkCbL+Qsn+yVsvUQMhGPksYVCh mdGDXSvkqa/YaEbV5dKIr120zF4rr9Pyh4f9HUhNCDNxjNxludufZfjcM03+4oiGf/J5w MmD74rZnKxe4NUjvNxPNDTMFTI27BfmuNEHOTiYSZZtXwGiNkQo0DFbXVPJBaCvzrlA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RjubOkPP; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF380606A336; Fri, 4 Dec 2026 16:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RjubOkPP Received: by smtp.kernel.org (Postfix) with ESMTPSA id F22741F00937; Fri, 4 Dec 2026 16:15:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796400939; bh=OKYf3xQVh9aYICRrxKSCBOwDIlVNTZ8HB3bfv+1kETQ=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=RjubOkPPRCCW8Or/Dba/mSTZzb/uCvY+Hqvjv2+j3FioKP8gETeDhY0l/PADPkH5W 31vkUx7Sks74UiBlxBhQh6nRSMltf63KngEcgxQytKN2irGoywvzZReGkkb6l4RZt+ 7Aq5J/DfrwqKbRIK7TzjfyH4s54tXo1WWXz7RVqEKiSeEmNC0klz48KiTLSPgoBvGI 59yuN0EYOv+wUtsfHTiaZM49ulTUUfOpCazPQtPzwA5+2R376VXaawcIjBfSyY5mY3 a3zVpYRogivfmrGzgmx8qX7v98/eDPbD8FkZvq5gMw04wLcDVLgzB0J4p4CTK2T18W gJ7ph+nCTm19w== Content-Type: multipart/mixed; boundary="===============2554539164200704666==" X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-Id: <182aad0008425e31fe08c4e1f68117ac89af5ab75db88ed83148037b23bccc2f@mail.kernel.org> In-Reply-To: <20261204155438.1413411-4-a.s.protopopov@gmail.com> References: <20261204155438.1413411-4-a.s.protopopov@gmail.com> Subject: Re: [PATCH v2 bpf-next 3/6] bpf: Don't allow the IMA hash helpers on hooks with the inode locked From: bot+bpf-ci@kernel.org To: a.s.protopopov@gmail.com,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,kpsingh@kernel.org,matt@bobrowski.net,viro@zeniv.linux.org.uk,brauner@kernel.org,jack@suse.cz,zohar@linux.ibm.com,roberto.sassu@huawei.com,bpf@vger.kernel.org,linux-integrity@vger.kernel.org,linux-fsdevel@vger.kernel.org,linux-kernel@vger.kernel.org Cc: a.s.protopopov@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev Date: Fri, 4 Dec 2026 16:15:36 +0000 (UTC) --===============2554539164200704666== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit > bpf: Don't allow the IMA hash helpers on hooks with the inode locked TL;DR: Possible self-deadlock on iint->mutex remains: a sleepable file_open BPF LSM program calling the IMA hash helpers from IMA's own dentry_open() may block, and file_open isn't denied by this patch. > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > --- a/kernel/bpf/bpf_lsm.c > +++ b/kernel/bpf/bpf_lsm.c [ ... ] > @@ -207,6 +207,7 @@ BTF_SET_END(bpf_ima_inode_hash_denied_hooks) > static bool bpf_ima_inode_hash_allowed(const struct bpf_prog *prog) > { > return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id) && > + !bpf_lsm_has_d_inode_locked(prog) && > !btf_id_set_contains(&bpf_ima_inode_hash_denied_hooks, > prog->aux->attach_btf_id); > } The commit message says inode_post_setxattr can wait for iint->mutex "which the task itself holds when IMA sets security.ima". Is inode_post_setxattr the only hook where that self-deadlock can happen? While IMA holds iint->mutex in ima_update_xattr(), it calls ima_collect_measurement() before ima_fix_xattr(), and for a writer without FMODE_READ ima_calc_file_hash() opens a new file instance: /* Open a new file instance in O_RDONLY if we cannot read */ if (!(file->f_mode & FMODE_READ)) { ... f = dentry_open(&file->f_path, flags, file->f_cred); dentry_open() reaches security_file_open() through vfs_open() and do_dentry_open(), which runs a sleepable BPF LSM program attached to file_open. file_open is not in d_inode_locked_hooks and is not in bpf_ima_inode_hash_denied_hooks, so the helpers are still allowed there. The helper then reaches __ima_inode_hash(): iint = ima_iint_find(inode); if (iint) mutex_lock(&iint->mutex); which finds the iint whose mutex the task already holds: __fput() security_file_release() ima_file_free() ima_check_last_writer() mutex_lock(&iint->mutex) ima_update_xattr() ima_collect_measurement() ima_calc_file_hash() dentry_open() do_dentry_open() security_file_open() bpf_lsm_file_open bpf_ima_file_hash() __ima_inode_hash() mutex_lock(&iint->mutex) The same can happen from process_measurement(), which holds iint->mutex and calls ima_collect_measurement(), for an O_WRONLY open matched by an appraise rule with no mask, such as the fowner=0 rule of ima_policy=appraise_tcb. In that case the mutex stays held, so later opens of the file also block in process_measurement(). file_open was already sleepable when 27672f0d280a added the helper, and the later commits in this series do not seem to cover it. Could the changelog or the deny logic deal with file_open as well, for example when the hook runs from IMA's own dentry_open() in ima_calc_file_hash()? --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47369735357 --===============2554539164200704666==--