From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796304754; b=F11w6a17VDl7u55fEZx9UAA+OchPAX4lbNQRneg2g3x5zGipwdi+q7QQ2k6U4sdhx75D vTNwA7j+pRx+c+1ffLkG/8bfjDJDmN03/1zWI0t2lMoGdkQbyt1+31AO6Wlym0mYv7hBX LxnFqwNteAx1QnpI0xwz4JjL2rdKGUUXcl5pqLvZeeYCbqNunLNENjVdgLwZhrKt/YXtt gYR1GbE9vwTtjn+W6EJ7D18yvfV114W4y2gu7oPXsl+ZqM5LKZNC2NZePidUAwP1K6Mjz 8faDdpVqE09bUejhZtCwj2FgzTu+4UWFyfcn3qwCIzWZVcAYtsFKQtK3K55dRjM2Kmg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796304754; 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=65uIm7i4hx2oN9SBu9fvc5mw906xE3iHtu0ZkBgiv+4=; b=cDmkeS5sksjtPpbdvwJLB9P4mcurgTBXVfVqtTpSYSB8TeuP/aOUpw0qeCtWiz8/9ifC Mjb8+ItaHDcDvvLDco1O7j2bWUJBq7cSKzPwJNaWHnwjc+CrokOAmH5m040rRZyI6Zj2F r4Z7oQ0GKalPclBtkq+O7XUALDAZuFNG8rAMvbNUv605ztLc+b4zLHwu8ftod54veEOtj Dd63tDYjNrL2jYJ719sYX2k77eRoASfmLmu7Qte/n0NNxQzxQZ61NoxnCCI90/vUnWhGU 1F5vmrpCZBfwldfhDVAA5UdpC/g6WBicTVoM0agQnuh+qVUT6Z/l1FRW7W02Ku8NVxg== 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=HKvakG8I; arc=none smtp.remote-ip=209.85.128.45 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 A83C7606A32C for ; Thu, 3 Dec 2026 13:32:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A83C7606A32C 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=HKvakG8I Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4bba5e17728so75659265e9.2 for ; Thu, 03 Dec 2026 05:32:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796304752; x=1796909552; 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=65uIm7i4hx2oN9SBu9fvc5mw906xE3iHtu0ZkBgiv+4=; b=HKvakG8IPGL6mOoa4oQxBNEErlrPwgD06sLnOabh7MqO7j5ch3XLSK5+9bQ/9B0iy6 U67liyiqFhOqUkx6EjD2ary9zh37jcYLl4tcTNu46dyq0YBXVcPUNiqKAnpzmdVBIdhs /2siJETE/6whIsYQdeh/ks7qyeFxcWbaIccX2ywmuP5s+4cAt1EbuDyqToGddAklH+VK os18npjsW5eL7bbkdgNLgn7ojx3RF+1C0puWM3r8m1TwLxmDN0yeXXRyxQpjACucckxX KBEyMET9/9Y8sc9F8ytUtl+HbjNX0JJFBxL7i0q7Ius/JgIPgTOPc+n4nKdfAQFdLZny KlIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796304752; x=1796909552; 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=65uIm7i4hx2oN9SBu9fvc5mw906xE3iHtu0ZkBgiv+4=; b=usgeV3ljVM0ar6M/47pWUuJ6SU9PCmHWD86qLes9sWipwHvdxNt9MBRyhf0cqDqvLL +H7YoVj5FdCdARfalF89+jNSAGAYv22tx5jbcD00t5QSH8RpYWtwjhMDhvbO3uf4/VlN WZMtzia6j4tDAT+2ksMW80SJkHgMNTyW0hFTCT/Fxk4jBXwvDham1IxdcS+XqyrLQSsp TbRCRQB5jJofzcCv7J8Qf2pW+PK6MIlcfbcPVIo1bOGUNo9pcVsaqx+dVhIbyLihMcDx aZqvyBLW5Vt9fXy+cGhrk2KxZ02hrl48tfFHEb8Y0NlD5cebnLAqW4Zj7G6KAS0U7KS0 qGeQ== X-Forwarded-Encrypted: i=1; AL+hErHt7PlrIz/Gt8AURiFLbWp/h/6HsAk/ANl289CuijAjpKmaWVNfr4gnn990Gpyxg2Ik1lMUqZTAgzHwZ6w=@vger.kernel.org X-Gm-Message-State: APuU4Z9BTY82DkLumHJ0ozh7r/fhfjTgzr/+ONsrEyBJCLwqszUH8doK wn956UJKArkGh6wyhogPZFPaUem4FxoYD3g80opyHrXtocpO9R9ApBuw X-Gm-Gg: AZFdTZdQfjkVdyt7WQzgwxjdT/TRdipEyMTJT7pJll/mSbegRRO/QpPDEJYK4v1h1kU 7AS2QHErMUO4lYQaXYl9ETjtZH4UU8E7alJoMknaA+G6R/+BVNDhYP4Cz/pOcnbEqUZI4LwENe/ oqGDGNIpgB5TBjL6ts0ambKJjD8yr42bjF8iw/UPYWTrFyYXsJRGUQmg3kAlwWG+M1CaWwkaSP8 YSyrBf4PGWd/g+QdHfONJBTis2jqqdud26EeaddekD0D1/FZklbifBufjvEEaC6bfQXllOW4jAQ Qs77WNFx6h6f/q9RMy5j/RyeNso8Bu1qzzeHsCfOwK/pfqcrrwYBNRrPPBG98jtPNB+WvyDO8ke SNOTCZLwWRa3U+cX6dqgGWDF3AJpNidGiCznufMTCtgXK4fneb44zNFrplZoAmbtCOArKzoR2YQ 0uVnCqsvMlV8x66ZLzb8xZwkA3eCjII8JSHC6NZLUJSpI72l9jwMPp9mXGGITorxjDC/0l+ezYs kdOqKUExvvGX9WFNQd6WK2sUZrr6Y+Qk8/OqaEo2Pl1/bSn+Ph3T7aWUn84i6fu6yeLzvicuSWO v2UWje2s7/GxlXXLIdLbUdOyPHS24BOmyB/nN18LeeDcMFg= X-Received: by 2002:a05:600c:468c:b0:4bb:6d61:af7c with SMTP id 5b1f17b1804b1-4bb88944bf5mr846983035e9.35.1796304751650; Thu, 03 Dec 2026 05:32:31 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00792besm74326105e9.4.2026.12.03.05.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:32:31 -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 , bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Anton Protopopov Subject: [PATCH v1 bpf-next 0/3] bpf: Use the xattr kfuncs on six more inode hooks Date: Thu, 3 Dec 2026 13:44:04 +0000 Message-ID: <20261203134411.1092433-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. Patch 1 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. Patch 2 adds the bpf_get_inode_xattr() kfunc. Patch 3 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. Anton Protopopov (3): 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 | 48 +++++++- kernel/bpf/bpf_lsm.c | 6 + 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, 295 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/bpf/progs/test_inode_xattr.c -- 2.43.0