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=1796400935; b=Wc9xdW28GGiUwWaOwnXpYjPo9mRfUqacK1j4Ui+94mM1AzPG1df52nk7QNc5gPlaiYPN 4dseZhHcuOMStAGrZDnkdxJezTydj1IN93YparuQx8TARVO49KJ8ZO0JEUza4cj+Hx1o5 YCuUJGBvxsJoDwMvBtp4CS3aWo8eS96/6j6tt8rX4P/UiOqHh2pVf5ravPRvPrUBHwFH/ iR+gAFrKGNEiGYwiYIB/90VEI4uEL3pPS8gYTFi3ZAd5OiWDM+rcb7lNAQ7v1ghq2iVlj Ima2p6tG6cEH8gW6UxVBxDse0auFKSEqCiKehuTk6mAMDm3gUcz1ZCgCbX6ZlNZle4g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400935; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=E2GAgV2ssO35oU+Ifi6UFCqjNOKalnVWhBIM/4tIMwU=; b=yb1rPQ1SEvez0aoJa2Xa0TrNe6qb4w+Hc9nOWMT4jN0TFI8K1hX72AGlPKHJFRoLMNEA eDyFp17s/oe99qqQfL+7br/4cBsp04PjVa3CI6zzayDwDcXg8/PTchEy42ZioQ+BhKGhu cNNnzJwl8OvmDi2W3uOdby88bckz0BwYJGwDRiTdeuTvNgqKFqzzGy/J7xl3jYIu5s2LL w9BXVJXEGhp0nlqxhvyfur7X5AaCSSXLf1jIeKYZEb//vA7Dayo2haL+2IX62jaQRz2XF K2/fyJbT5Rjg4hfllBorDrrzqYKbw11v9VtXNjerf16luj1H+MdXPsdRJ25CMHe/0AA== 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=l2kqZ6PK; 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 1C4E6606A33F; Fri, 4 Dec 2026 16:15:35 +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=l2kqZ6PK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A0171F000C2; Fri, 4 Dec 2026 16:15:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796400935; bh=E2GAgV2ssO35oU+Ifi6UFCqjNOKalnVWhBIM/4tIMwU=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=l2kqZ6PK6QZw4KKo/jO0IZkVnifmmcz5Ff1591d/vB221bRlaT/dmoecpbMZej3QL /g3w4QOfmqShMnYfhVIOK+fKg+jc83nHgkZyWXqgnihFf84yOkodnjL4u1MiEogFQQ Ov/EPFb1JE5k353DzgzpgHUTzmTVLSPy9l73frH9qGDZpzbdsvNZhWPfm0ZNPuwhMb gtgvILJdaUphK8OSgRYsabCX9IDG1iaVUeUecIxVPdkiqY2OR79q5UkwN2+BfGFKKu awIvkDRuYlDRq+aBUEJ3naStoXQGAloce1hujhZfFAjXhFZQ4aEjrxbsHNm6M3tIn4 NKp8rEKwEf08Q== Content-Type: multipart/mixed; boundary="===============8616899011201004538==" 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: In-Reply-To: <20261204155438.1413411-3-a.s.protopopov@gmail.com> References: <20261204155438.1413411-3-a.s.protopopov@gmail.com> Subject: Re: [PATCH v2 bpf-next 2/6] bpf: Don't allow the IMA helpers on inode_getxattr and inode_getattr 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:32 +0000 (UTC) --===============8616899011201004538== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit > bpf: Don't allow the IMA helpers on inode_getxattr and inode_getattr TL;DR: - Possible self-deadlock on iint->mutex remains for sleepable lsm.s/file_open programs calling IMA hash helpers; the deny set misses it (pre-existing) - Fixes: tag may point at the wrong commit > bpf: Don't allow the IMA helpers on inode_getxattr and inode_getattr > > The bpf_ima_inode_hash() and bpf_ima_file_hash() helpers take > iint->mutex in __ima_inode_hash(). IMA takes iint->mutex before the > inode lock in process_measurement(). So a program which calls them > with the inode locked can deadlock against a concurrent open of the > file. > [ ... ] > So a program on inode_getxattr can wait for the mutex > which its own task holds. > The hooks can't go to d_inode_locked_hooks as most callers don't hold > the lock. Don't allow the helpers on them. > Fixes: 423f16108c9d ("bpf: Augment the set of sleepable LSM hooks") > Signed-off-by: Anton Protopopov The Fixes: tag points at the commit that made inode_getxattr and inode_getattr sleepable, which did not add the IMA helpers, so no deadlock existed at that point. The helper being allowed on every sleepable hook comes from the commit that introduced bpf_ima_inode_hash(). Should this be: Fixes: 27672f0d280a ("bpf: Add a BPF helper for getting the IMA hash of an inode") > 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 [ ... ] > @@ -198,9 +198,17 @@ BPF_CALL_3(bpf_ima_inode_hash, struct inode *, inode, void *, dst, u32, size) > return ima_inode_hash(inode, dst, size); > } > > +/* Hooks which may be called with the inode locked or with iint->mutex held */ > +BTF_SET_START(bpf_ima_inode_hash_denied_hooks) > +BTF_ID(func, bpf_lsm_inode_getattr) > +BTF_ID(func, bpf_lsm_inode_getxattr) > +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); > + return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id) && > + !btf_id_set_contains(&bpf_ima_inode_hash_denied_hooks, > + prog->aux->attach_btf_id); > } The comment says this set holds hooks which may be called with iint->mutex held, but file_open is also called that way and is still allowed. Can a sleepable lsm.s/file_open program deadlock here? For a file opened without FMODE_READ (for example O_WRONLY): do_open() -> security_file_post_open() -> ima_file_check() process_measurement(..., MAY_WRITE, FILE_CHECK, ...) mutex_lock(&iint->mutex); ima_collect_measurement() ima_calc_file_hash() /* Open a new file instance in O_RDONLY if we cannot read */ dentry_open(&file->f_path, flags, file->f_cred) do_dentry_open() security_file_open(f) bpf_lsm_file_open -> sleepable lsm.s/file_open program bpf_ima_file_hash(f, ...) -> ima_file_hash(f) __ima_inode_hash() iint = ima_iint_find(inode); /* same iint */ mutex_lock(&iint->mutex); /* already held */ bpf_ima_inode_hash(f->f_inode, ...) reaches the same mutex through ima_inode_hash(). iint->mutex is a plain mutex, so the task would hang, and so would later opens of that inode. This looks reachable with the default ima_policy=appraise_tcb, whose rule {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .flags = IMA_FOWNER} has no func or mask restriction, so it matches FILE_CHECK with MAY_WRITE on root-owned files whenever IMA_COLLECTED is clear. Policies that measure on write trigger it as well. bpf_ima_inode_hash_allowed() still returns true for bpf_lsm_file_open: it is sleepable, not in bpf_ima_inode_hash_denied_hooks, and not covered by the d_inode_locked_hooks check that ca7b97a49368 adds later in the series. None of the later patches in the series (up to bebb89f50f4a) address it. This is the same self-deadlock the patch fixes for inode_getxattr, though it predates this patch (423f16108c9d added bpf_lsm_file_open to sleepable_lsm_hooks). Denying file_open would remove the main attach point for bpf_ima_file_hash(), so the fix may belong in IMA's internal reopen instead. Should the comment or the deny logic be adjusted, or the gap at least acknowledged? --- 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 --===============8616899011201004538==--