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=1796400831; b=mRQ9OlyA07C7FawreoI52RQaNujRFfbS+s9eZE537fzR8a1fEpjzubKkss7lnL4flK8G 4IDd0m0bXUtYqciUZ/fInP/LaxtKoC7WVAk5pY7anHq2OFSTyZn7r+0puSY+e3a+vR07d onO/TXEa5/lbGEiTTl2SusNLeEubZmtjsekUt0WtdGF40Hg+uLqqDwPG5Q0potP7aVB81 Z1Im5l7stYNyXTvo1Tq1XQqtRLri9puwPs+wY6PZX3tXqZlv8Fcky100Z8RvqLhPj2/Vg 9OvaTPQ0HHy/2dEXm8J9V8srQ5rOL6vqsuh8e4j5aV8YR6J+H0/rA/HtZGN8/BfNGxg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400831; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=cl7n8ar2SeeqHmJ9ItHHFlT4LPjo394mGa/RXtaBL5M=; b=r+5Z2CDYKAaRg87IHC4B/7ojWgda6gFDCare8uwZDJpyx9/6knmcyEIu0kn3vvE6knJa SN6ASSH9r7BbYm3vtpas1TubA/ZHJwIkxHlJm5+1s5KSd8oF2ppM+q02LaxsZ7uSQO/Xd oQHQdITTAIESU3zRwdJSe3yeOY2DXHfAH3YegjVoQH71UL0Qw2yWk6vvmX1dIG9I5N2LP gZPeZU1E2qo7AFHn1iL2wKbKCm+iwvz9t4LJpB3tX+/IUTtVzE9vWyZ+hPoh0BNo0S/nZ t/yBKAr0EHf0BJK0yeeMrUKFmdFCaAF4r578dQ0f01/qYx2LNVeI0ruYa7tb34IkRCg== 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=eDKKp5hr; 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 49871606A32C for ; Fri, 4 Dec 2026 16:13:51 +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=eDKKp5hr Received: by smtp.kernel.org (Postfix) with ESMTPSA id C12741F000C2; Fri, 4 Dec 2026 16:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796400830; bh=cl7n8ar2SeeqHmJ9ItHHFlT4LPjo394mGa/RXtaBL5M=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=eDKKp5hrV51EX69RpwkpZ0Kfc76zQvTHlg7qYTDkIn5FO39O9gZm2iied36oJFoSq xprTlO6t3DjiFfCaFGjZwmlV3pbi/2EFPDQ4mgXhu5KnBNdO9jIGDk7sYHpzzVqfAP T7hOrnbch6HJjrRQudo9lji1V3Fi7ABSD9T65YXR2+4YQwgyTMFBxihI/LJSm2GYTU OtQXx79S1u72wmsCdOFmXHXAZIeaGMUuhCyHegSsNqI9TDk9+zhwu84V4OxwI/h2Pm Al0yQ6LyQNs0NjxzO/hrUEUpLkeJbQ9tOXhl3Ej5hOtHF73htMaQADXS1msJV57efP o3lEisG8fz1rA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 bpf-next 4/6] bpf: Let sleepable LSM programs attach to six more inode hooks Reply-To: sashiko-reviews@lists.linux.dev To: "Anton Protopopov" , bpf@vger.kernel.org In-Reply-To: <20261204155438.1413411-5-a.s.protopopov@gmail.com> References: <20261204155438.1413411-1-a.s.protopopov@gmail.com> <20261204155438.1413411-5-a.s.protopopov@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 16:13:50 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] bpf: bpf_real_data_inode() can nest OVL_I()->lock on new sleepable LSM hooks - [High] bpf: missing inode_mkdir and inode_link in bpf_ima_inode_hash_denied_hooks -- commit 83267828169188f48079e5f449fe1b875d3553b4 Author: Anton Protopopov bpf: Let sleepable LSM programs attach to six more inode hooks This patch adds inode_mkdir, inode_link, inode_set_acl, inode_remove_acl, inode_file_setattr, and inode_copy_up to sleepable_lsm_hooks, updates d_inode_locked_hooks for the ACL and file_setattr hooks, and restricts xattr setters and IMA hash helpers on inode_copy_up. > diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c > index a512d449b54d9..6021e9f60ad28 100644 > --- a/fs/bpf_fs_kfuncs.c > +++ b/fs/bpf_fs_kfuncs.c [ ... ] > @@ -539,8 +548,12 @@ static int bpf_fs_kfuncs_filter(const struct bpf_pro= g *prog, u32 kfunc_id) > return -EACCES; > return 0; > } > - if (prog->type =3D=3D BPF_PROG_TYPE_LSM) > + if (prog->type =3D=3D BPF_PROG_TYPE_LSM) { > + if (btf_id_set_contains(&bpf_fs_kfunc_lsm_only_ids, kfunc_id) && > + btf_id_set_contains(&bpf_xattr_read_only_hooks, prog->aux->attach_= btf_id)) > + return -EACCES; > return 0; > + } > if (prog->type !=3D BPF_PROG_TYPE_STRUCT_OPS) > return -EACCES; > /* ->st_ops is unset during the cfg pass; enforced once it is set. */ [Severity: High] Can sleepable LSM programs on bpf_lsm_inode_link and bpf_lsm_inode_copy_up still call bpf_real_data_inode() and deadlock on OVL_I(inode)->lock? bpf_fs_kfuncs_filter() only denies xattr setters on inode_copy_up, leaving bpf_real_data_inode() allowed on both newly sleepable hooks. On overlayfs mounted with metacopy=3Don and verity=3Don, a metadata-only copy-up in ovl_copy_up_tmpfile() or ovl_copy_up_workdir() sets OVL_HAS_DIGEST, clears OVL_VERIFIED_DIGEST, and leaves OVL_UPPERDATA unset. When a process executing such an fs-verity lower file calls link() on its own executable, it self-deadlocks if a sleepable inode_link program calls bpf_real_data_inode(bpf_get_task_exe_file(current)): ovl_link() ovl_copy_up(old) /* metacopy: clears OVL_VERIFIED_DIGEST */ ovl_nlink_start(old) /* locks OVL_I(inode)->lock */ ovl_do_link() -> vfs_link() -> security_inode_link() bpf_real_data_inode(bpf_get_task_exe_file(current)) ovl_d_real() -> ovl_maybe_validate_verity() ovl_inode_lock_interruptible(inode) <-- self-deadlock Two tasks concurrently linking each other's executables can also ABBA-deadlock on their OVL_I()->lock mutexes. On bpf_lsm_inode_copy_up, ovl_copy_up_one() holds OVL_I()->lock of the target file across security_inode_copy_up(), so calling bpf_real_data_inode() on a metacopied executable nests another OVL_I()->lock of the same lockdep class and triggers a recursive-locking violation. Should bpf_fs_kfuncs_filter() also reject bpf_real_data_inode() on hooks that can run under OVL_I()->lock? [ ... ] > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > index 6c79d4786f675..c4b626b0dbdac 100644 > --- a/kernel/bpf/bpf_lsm.c > +++ b/kernel/bpf/bpf_lsm.c > @@ -200,6 +200,7 @@ BPF_CALL_3(bpf_ima_inode_hash, struct inode *, inode,= void *, dst, u32, size) > =20 > /* Hooks which may be called with the inode locked or with iint->mutex h= eld */ > BTF_SET_START(bpf_ima_inode_hash_denied_hooks) > +BTF_ID(func, bpf_lsm_inode_copy_up) > BTF_ID(func, bpf_lsm_inode_getattr) > BTF_ID(func, bpf_lsm_inode_getxattr) > BTF_SET_END(bpf_ima_inode_hash_denied_hooks) [Severity: High] Should bpf_lsm_inode_mkdir and bpf_lsm_inode_link also be added to bpf_ima_inode_hash_denied_hooks? Both hooks are added to sleepable_lsm_hooks without being in d_inode_locked_hooks or bpf_ima_inode_hash_denied_hooks, so bpf_ima_inode_hash_allowed() now permits bpf_ima_inode_hash() and bpf_ima_file_hash() there. However, the same IMA-triggered overlayfs copy-up path holds iint->mutex into both hooks: ovl_copy_up_workdir() -> ovl_create_real() -> vfs_mkdir() -> security_inode_mkdir() when copying up lower-only ancestor directories, and ovl_copy_up_tmpfile() -> ovl_do_link() -> vfs_link() -> security_inode_link() when linking the copied-up file. With IMA or EVM appraisal in fix mode, a sleepable LSM program on either hook that calls bpf_ima_file_hash() or bpf_ima_inode_hash() (for example on bpf_get_task_exe_file(current)) causes an ABBA deadlock with the upper directory's i_rwsem: CPU0 CPU1 ---- ---- lock(&iint->mutex) lock(&upperdir->i_rwsem) lock(&upperdir->i_rwsem) lock(&iint->mutex) *** DEADLOCK *** CPU0: process_measurement() -> ima_fix_xattr() -> ovl_copy_up() -> ovl_copy_up_tmpfile() -> ovl_do_link() CPU1: ovl_link() -> ovl_start_creating_upper() -> vfs_link() -> security_inode_link() -> bpf_ima_file_hash() It also self-deadlocks directly on iint->mutex when a task triggers appraisal on its own lower-only overlayfs executable. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204155438.1413= 411-1-a.s.protopopov@gmail.com?part=3D4