From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796398982; b=PE/6atO4Irq/DP9lkEH+n596lQuG8Re+CtzbR9XtXgR0sqHxRavwWA8CL2UHZZvnfsy8 rVIzzrYE5QhGsntnTTOj0Z8D4E8bN6eGdNEgKIAc5yahnDElpWTp3FG5cBxfI4FQrKqV2 Am76E/FxfkEQUr1F1vO8Wzo8JYCnN166ubDCnAbCcVWF/+ONFPfjFNogGReix/FkQvmXA 9xNHZWlwKv2PxBz9l/u94aKlelGFGMDEuS7W8QGONg41HI8Npk2UZKqVM8V9ZD4i/IjOm kaJDw0zlPgW6+cOooQfvl0jBWHEEDqEFPrIVPxL2ynHKeu9zDXw2AUMbeChhvIaBV4w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398982; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=rlPXek5gVqPHRGw0vtUWHSWUdE1Df/a+AR0fE5fLb+k=; b=cxQxaikjS0roQThYN3jWNRGg24CbGvjECy6K/v9FkLe/4Q9Fzc6+FIvPeiHS5qBxcYdM EBTaLhANUVMDHPCdRqBfZCzFq2g+BMHb6+r83priIzcGDHQZieITW+/b1Pm02qLpJLKS2 dAgoFmn+fIijlslef4jb68eSx82hcFzWjpB4cZj18BzMVsGDZk824Q264tnSdmyIEcG0q 36a+kz/QBTm8TlBfGc2e0cj99J1kJQAsFnYR4bf3Kdv2zJbYYSELmrA54kWC7sWf2WPVb jX3L5q4Nk2QvyWVQMv/PpG5u7/3iNod1uLnElotW057bjBnJE+l+qteOnQ1XSvzrLDw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dp9Vij0t; arc=none smtp.remote-ip=209.85.128.51 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89EC4606A322 for ; Fri, 4 Dec 2026 15:43:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 89EC4606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dp9Vij0t Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4ba013938d7so9649625e9.2 for ; Fri, 04 Dec 2026 07:43:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796398980; x=1797003780; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=rlPXek5gVqPHRGw0vtUWHSWUdE1Df/a+AR0fE5fLb+k=; b=dp9Vij0tDoPzZtDNi07PQnyw0qasBn80FqC+auJn1tevGaH+98fSunxvzNo9jlTXZ5 viA1uzG0tRey8/BoQp34RiB1p6X/920qpL7GEj/drJQ/wum7vArsZt+ErtmAXFcU+g07 BAx6oJdTJFoby3HJ1hxTj9H/ZLIBhmdBStytnkCjMXsC3pUEH2ZvW8+tl93PTsAW3LFG yozMrsvpFPj76RsKGimtXnHU1+h6rNo6TtySRU1arotlsX7q14Q9XCJLM0w9wW15BfGd 6N7R/20fneGO6uh6tydvxtASgBbMAfox1tTmBvkLxptmKvGLVULPLfbn911YifjZ6F3V ESJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796398980; x=1797003780; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rlPXek5gVqPHRGw0vtUWHSWUdE1Df/a+AR0fE5fLb+k=; b=EAnWQqZWVTwD50v7mttuYWYjk02PZgdtDI5zDk/MSefHBK6KPRWmiMnBGe9FCm8UhF 9TF2BMEC2m5tK8Cw+bVGRyzE+T7CrFd5SvnZRotMkq0QnBN5GTamL6RnfR2f6kYalzOg 03p3jh/kUfoDdpYRSh1waxeKVKFfsFA7PHJQmKDA+2amafRw2bElmj9i1r4Pj5G8tXjQ KUhSHbaB/iy7FiIPcp35X9aF9kTw4FE1Wf2ekKoOH+xCjuWS6ZKxHsn91M8VuUBpkZtn 212A7/AGqIQPFJsOGyUs2jKeWktj1+z1EU6YnSTr9/AUob2YhiXWJbHaaqtsFHarem2I Uwiw== X-Forwarded-Encrypted: i=1; AL+hErGRwQEVFFjvjqYBsIdXAJY2N11I3KFtoPaeygeWrGZhKeM2Si8TQm4KRvvpw8YJamMO24hUO+MRG1K8fYM=@vger.kernel.org X-Gm-Message-State: APuU4Z8SjWAvxdJkYyM7X9yGhCE7HEmrPd1FsdhEHpFxfHRXhCyG5XDW r5FLkZGBHPMRDrWXsh+woJEV6kmAlFuW2eKLrTwHGioZ+KYEdZO2TEDF X-Gm-Gg: AZFdTZdnaBpGhgxrXsiCnx2nctDwlje4PHlU2DUGaXkJvH5FgrKC9M14O2VdAnyYBRP l+7uL3xwmPVQcv0IW+pFOxWSR4KxrKyfoG0A08ZjAUYpfA8pZCkV1P6/W7/b6fhPWMX345pOF0g 8E/M70bVxfsxOChRiFEml0q5pBYMBSJ3njwI6FgSaxZd3U/q2m9bvhp7JOy/mYDU2L8In+K6HmY bHd1OQqDrDNm7TbptqVBLoIBc3KOArGn+hPg1Lvbxr1U4wVd5SgIEXrwX0cMu5Gjfi9zJRCyN8N bI8JHHyAAeScR1N2YJzYWfkvVsozTgpRgyy3lx+1gnGHrxneEsuCb9zTfAc866Jjws+Uf1xapGl lzcHu74BbirnJR97/PVyUm6Q87Me6ZQRB4o979rsuAqPXQN8yOdgpikq+VWztDxHHDQ9uNEC7S2 dsT+6MnNhd4O/Zq4pyLn/6lRmALrdZ9mRmSsuTuFhGok7SdEI6xarMhnK7u5aY5tboednKnaqqf EqZBRzQs5mGwux0PGkg64PhH06jjrx4QtQ8B7t4nsOllqmj7tsz2jQnEzSpm8CHtGxvaPavdQua UOe62aLVsJwfoELL+WpLMNF6Ge+2QvG0Uc+TXG0pNQiVcR4= X-Received: by 2002:a05:600c:470a:b0:4bb:aa4f:c027 with SMTP id 5b1f17b1804b1-4bbeb603179mr52476955e9.0.1796398979998; Fri, 04 Dec 2026 07:42:59 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea25ce51sm63147535e9.5.2026.12.04.07.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 07:42:59 -0800 (PST) From: Anton Protopopov To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , KP Singh , Matt Bobrowski , Alexander Viro , Christian Brauner , Jan Kara , Mimi Zohar , Roberto Sassu , bpf@vger.kernel.org, linux-integrity@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Anton Protopopov Subject: [PATCH v2 bpf-next 0/6] bpf: Use the xattr kfuncs on six more inode hooks Date: Fri, 4 Dec 2026 15:54:30 +0000 Message-ID: <20261204155438.1413411-1-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 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 Content-Transfer-Encoding: 8bit A BPF LSM can keep labels in security.bpf. xattrs and check them in its hooks. For example it can refuse a new entry in a labeled directory or an ACL change on a labeled file. The xattr kfuncs may sleep, so only sleepable programs can call them. But inode_mkdir, inode_link, inode_set_acl, inode_remove_acl, inode_file_setattr and inode_copy_up are not in sleepable_lsm_hooks. Also the hooks which create an entry get the parent directory as an inode, and there is no kfunc to read an xattr of an inode. Patches 1-3 fix deadlocks of the bpf_ima_inode_hash() and bpf_ima_file_hash() helpers. Both take iint->mutex, which IMA takes before the inode lock. So the helpers can deadlock on hooks called with the inode locked. Patch 1 adds path_chmod and path_chown, which are called with the inode locked, to d_inode_locked_hooks. Patch 2 doesn't allow the helpers on inode_getxattr and inode_getattr, which are sometimes called with the inode locked. Patch 3 doesn't allow them on the hooks in d_inode_locked_hooks. Patch 4 lets sleepable programs attach to the six hooks. The ACL and file_setattr hooks are called with the inode locked, so they go to d_inode_locked_hooks and the verifier replaces the setters with the _locked variants there. On inode_copy_up the setters are refused: the caller holds the copy-up lock and a setter would wait on it. The IMA helpers are refused there too, since IMA may copy up a file while it holds iint->mutex. Patch 5 adds the bpf_get_inode_xattr() kfunc. Patch 6 tests both. The other way to read a label of the parent directory would be to make dentry->d_parent a trusted pointer. But it would be trusted on every hook, and many hooks don't hold the lock of the parent. There a concurrent rename can move the dentry and the old parent can be freed while a sleepable program still reads it. The dir inode is passed to the hook by its caller, which holds it for the duration of the hook. Some deadlocks stay open, robots will report on them, but they're not introduced, and are out of scope of this patch series: * A program on inode_getxattr may call the setters while EVM holds the inode lock to update security.evm. Refusing the setters there would break existing programs: the selftest of the setters uses this hook. * IMA reopens a file which isn't open for reading to hash it, and it holds iint->mutex while it does. So a file_open program which calls the IMA helpers can deadlock. * A program can get the executable of the task with bpf_get_task_exe_file() and pass it to the IMA helpers. A stacked filesystem may call hooks like file_open or inode_rename while the inode of that executable is locked. (These need a fix in IMA or in the IMA helpers rather than in the lists of hooks.) v1 -> v2: * Add patches 1-3 which fix deadlocks of the IMA hash helpers * Don't allow the IMA hash helpers on inode_copy_up (patch 4) * Read the xattr through a hashed dentry if the inode has one (patch 5) v1: https://lore.kernel.org/bpf/20261203134411.1092433-1-a.s.protopopov@gmail.com Anton Protopopov (6): bpf: Add path_chmod and path_chown to d_inode_locked_hooks bpf: Don't allow the IMA helpers on inode_getxattr and inode_getattr bpf: Don't allow the IMA hash helpers on hooks with the inode locked bpf: Let sleepable LSM programs attach to six more inode hooks bpf: Add a bpf_get_inode_xattr kfunc selftests/bpf: Test xattr kfuncs on the new sleepable inode hooks fs/bpf_fs_kfuncs.c | 55 ++++++++- kernel/bpf/bpf_lsm.c | 18 ++- tools/testing/selftests/bpf/bpf_kfuncs.h | 11 ++ .../selftests/bpf/prog_tests/fs_kfuncs.c | 107 ++++++++++++++++++ .../selftests/bpf/progs/test_inode_xattr.c | 89 +++++++++++++++ .../selftests/bpf/progs/verifier_vfs_accept.c | 13 +++ .../selftests/bpf/progs/verifier_vfs_reject.c | 22 ++++ 7 files changed, 313 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/test_inode_xattr.c -- 2.43.0