Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796304754; b=gjUZze+RJRj9mohPHOd4izUuWRW+j+xsHWfHY9HNxs9ZNHYb6Kt632eoqkRTv94z5+4v S8jL7L6YY+stKC73IYkNOozOohjfSpGo5JNfqLOZm7EilGYG0l65iY+XPTUVdbxXWO4CZ nRJSiBofZCDwyplHxC6E91Xi0MF0TY2ZPWFjZyv39H5eliGh4InQ6a1+JurcN+JrifSN8 PWcyJVNRy5NG/0dbzlzuh/M66My+uy7f0eJAgys222bCXUcpAWLqiqnv2YWxA0NY0N3+W btEp4rlFYPa2Rv6WUkUSukH9ZgGC/etyaaaRsts4z8sHKIlSSNyU0avJr1fWbzdsZfA== 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=4AodQdX5ccSiq0HizV06WlC1Lnerm23j3QATSk6JyVTXF8FF2WUVI9uu8GGV1etytfud 3xaLyK9A+6jyy9uOtfcHFGnRGWENiXiX9/yUnC/Pdz5dOnOgdVVPLmHkTVcEnbmzMmTfS 97Mwq3A9qjtfKNnldFlbHD0w17QyUd449VaXgql6nyYzmbcCc4kSZscynqElxssS/Cgzm mtrnunzS48DH73vV9GIZfl0qj2KTiZt4hKg5BCwt4k2SDeN+gAYS9XH1Dm/OBKtU5h8oE ATjwdBmcsYaoTxhIoaqedRINkiqq8uUw+4xH/jfXyoP2D6E6WNhCdfQBo0+sqaz9/MQ== 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.46 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 AD177606A32D for ; Thu, 3 Dec 2026 13:32:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AD177606A32D 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-f46.google.com with SMTP id 5b1f17b1804b1-4bba5e17728so75659305e9.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=DNb2altM6e+U2K4qG3hqrcrptSuq/YCz7GiexT3CTEQsSWTjDbYTB5yWj2MeHFtjSW TZeyHKoWUEBNXJyB0IrSaphMwAOTUrpf6/97VqdH4OQoDutTz8F4oVBK21FbouDi3Ygl lgtXQUCtzbXkXHqJ5iGYJ11s1u58+0x3eS7rk5tE7vcwN5gnWl7S/JJhMxGZn1wEBW6P 5Gb+KE9KJXv3QFLDhF5p0YODDjugwaGGF2Fk6hEsCiXfCWD1xkzZGwlY/LcjsSHgvmj3 veiYGasYBLlcLCwpIQe9NrW+dwTlUtK4I8hQrumEzjU62KV1dS70+UaToA8229z6asXj yOoQ== X-Forwarded-Encrypted: i=1; AL+hErGDt7E6q4nRs8tra9loFuEHr+t62E9la79HqOUzZ8JLoesX9GjElO40DQcM2lMczHfkBGA=@vger.kernel.org X-Gm-Message-State: APuU4Z+G0bcJV+YUn8FqTX6wFMLFDIjqn9w/3zgiQK33S8iM5ZLaIL3a inep+CoiJ/nKoG5hD5Bzv6JZsgzWPuWWpZpzRQX3tTMIMnh1iD0kWcR+ X-Gm-Gg: AZFdTZe3aGUWCvk0XQMp+A02C0EwnorbUmBTiuQnem2z+B+/rtcwtHEH1z//kuwkM84 NDlWnRIZJr7GL5PT2J1K0Ar7iGcfv1OJFa3bouyTgmkxBdT55BNf+3NtHMpa9SYDCig83Fzy87D TZVsQ7vbONYZRuNvtGMIdzJ/xEEAhXJL03sHQ5Ek7JZoUxnoL6OGZBXAe9QCezxXHFlLkATBp7i QC/qyloEOQz3A18WyLmk4GDFe5ubhQtZ30+M2SGRlRc3gjS9MAI4kUTw3GDt5dM6BZO8V3Z0UUd T++ZTW3OxxRxmX1iATc/vl09/SS9QqhA8xupbICSAskEs6HmfMzxNRqCBczRLfvMLgp46GDZN9H 64WQIo3ma871nmHf1L2YJRFFsuw9UKVzyt9MPq63/lnFN+o20knzoGywKLg4gk3eWLNrV0hqvJn tCHPBE0/7rXjxouHgZhiLvbqEPrXnUVZ0mBEMYO5j5l+yr6TaqQ4b+7WrnedKxPvEzEEz3PbRRL fwpBrkjRIZwXtQwcBZK2uN71/WJ3u2fQkCna2rBztSRDDBNK+Ew5Le45oSAIJSmw+dXsYabpBKp +Ep7mliHUjbUePRTrZXuvARiBwrPbNtdpx45oJhRImAjMZg= 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: bpf@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