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=1796304756; b=xIsDMKZgazJOxASdzsAuCtsBXXwG+KbNFeTkaMISmUxT/Oi2kIV34H5f3xH7wTSdbRHE sKkBuknlMdZHN9enqsT9VyV38A7bKp3jT41q3RdwqM1A3T5POw6DQggjTchCKIV0pg6xY uq61JrWjXV7HptNK70C7QFasUxhkC9tpVZ8Bo3nNbl925fgYyvz9Jpb8C2YyDx2srXF4f 2Agub4tsv7jpQ6ZdIbz/F1sc723HApdkWGKyNG8yWOvwqwY9fdwvLNORiXJ8/gaJFU8Ui Vr+cjV+RJP5DbaPTZB7QFcRxq5u1Bvejy6xxWSy8G4SuQLcD/t2pilsOl5Fpzj6xi7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796304756; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=/frE2NGDZ7cHqyCI6ZMPNMth11ps1fBQ0+wxK8ceO04=; b=0FTaHV+y0GbrD6ICmxPzdgd+12THu90NsyBdD1RUQ4hdLeeaCToNascTPqLkxAzSQbgL ebmjCcAHvKqKS8X6WHfpQiVFrJnD01UrZILU4urXg23QnmRAzY7gVoExKYu7ixEJnCQrY CLbw/J0+oDUEuztdTj8MZ/sjrZAJ5VyjyetA4Fwi1unQvg3uiyX6PUoNNLxA6urkdBkGk 5l7v4Nyc2oYIIewfTx+9StG4xoEpQOTAuIs1T3pdDc04FwoNluIKUnCtqVF9JCmCRTzhi McfvMXRVQHH8PPrwvpbB0a7GjuobdSsWCq2VLUeDeeKuTTvmf6gXn1zV8/80Ws5v+Dg== 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="gJL2ZAV/"; 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 2B305606A338 for ; Thu, 3 Dec 2026 13:32:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2B305606A338 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=gJL2ZAV/ Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4b79502c27aso145304785e9.1 for ; Thu, 03 Dec 2026 05:32:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796304754; x=1796909554; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/frE2NGDZ7cHqyCI6ZMPNMth11ps1fBQ0+wxK8ceO04=; b=gJL2ZAV/VH3Ipde0aEupgx4DB3gJOFfWrXn17Jaal6z4qytyTvsC+xfj18MQD5/dSx bf6l18NF1RUgvcTrSIdckHFuR/MU1N9mBsN/Avau3gX/ZmR7gb6knPKanNcFEAdURfSv uEmw4d2GmFyZ43+3Dlxahm/MrhnFXKi7/vruuZDXbyM1M0IrZIyb+sOoHsOMaK2cLqBT Z19bsdFdCjhgw6+hNZ5CB1k0JRVGso3azpq7AmQw5SkaZZIffhP7X4rZ5GrVF7fwmkDA rD8Ejm++B0pxMYUPoP9mCpC2VQMZtYbdBv1jaj9FAG5io7SXdbzvw9uwpiEq8zQuMdpU L/yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796304754; x=1796909554; h=content-transfer-encoding:mime-version:references:in-reply-to :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=/frE2NGDZ7cHqyCI6ZMPNMth11ps1fBQ0+wxK8ceO04=; b=H3Q+FY2kYBRUepe1SjLmrQ5syy/e6zyC/sJZ/d9DBqsR9V52rri1Brav/S1mafpJf/ TLpjXAp00lnBufU00FPpGDv0DQxB6uXbtl6DK0ULPW6nXPZJfah5+Hc64b29USAnO9lA inFi3g85zCSa0uxMNzf5+HAP4MvxyYdsezP5PDMP/+i5BSRki3ISnXoyoEh6IAaYJY8b UdHCygySC4Fq7fx2II5n4TOgn4yzxbrUSLWLmq0zkEEUun1gQ5Tkednu2V6RzGQh6V+1 uRQAXHDEf1/DJS/J7xGi5q0Wk3TAbJy7vNH7vbBK6jNgbxFdzj7ETI9h66AUo1fOuivu eW/Q== X-Forwarded-Encrypted: i=1; AL+hErFLVlwEVUvcEAlSynjNe4OmOF5W45xZaL9SpQ6d87N1/9cqfdHEdr8DK1RX4xforNankLBTTCaKXvaqgfM=@vger.kernel.org X-Gm-Message-State: APuU4Z+BYOCKJaQZN5z3Rq5FHCHy8PxZbejXEGtu1WdYsqizJVnqcnit YfLjwqP86nyC27k7phvTFgnfgmYlBMeUO4hS7GpCArnPemxBcBxD3ZXW X-Gm-Gg: AZFdTZd+CQVe5C+SS+M7Tm6FR+VK8JpsrwmuQXZbr5vpEfRrL6UFvQOpp+JSDWRB4BV zFBe7s5xcXglWh2rHwzfa+m0/Qt3mvaeRB1EJBHwFjYPvdpbAlkebRMBdzPGdW+m6tD4hiqXTm2 JejUDqHwJVVkkSyjX7WWxD5ONpAlwZ4VJZQPqw9GVVWGuWgbzs12pbpCXo6QykMkoM1xR9QdRdO 5wpVb1k8UF/6jdsJ35U2cZ1FGqjqMa7yYD80Z77jWzT4wnKtAfvxUQf6BOcY/9adSj+gmj8oWPu T4MbQqBYZt2sTBmlAYa5pl6K/rwH72aXQAAj+n0AJmEjCfQm9L4DAyQ4RipmJnlTt8DF3MBT0RL Zei3heBidnaq+ZCBeimzD7tdMsB9ATzPphD8xsI1MObEWKt2Jw7DR+bbE2u+x0dw2KMuWfp2xcJ nEK6m6wHtH6vKYmMhIg1fHo+K3Vjf+vVqWkSjz3sF+CHtDZADuHcEW1Tfkq4fFAiSYG5m6jdmRz Ri+92FfmlTmhoWXzmqC8ECWYJxP+XxIu7PIY2L/vkjINZIsTcwo6TmXezg8/8mKcFCi4B35zYnU twNwAZFyGbUQN8RawQ6d7fk6lEkVXaxr1+H01eaL+HG5oUqz X-Received: by 2002:a05:600c:19d0:b0:4bb:c483:ecaf with SMTP id 5b1f17b1804b1-4bbc483edc0mr244983155e9.4.1796304754466; Thu, 03 Dec 2026 05:32:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:32:34 -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 1/3] bpf: Let sleepable LSM programs attach to six more inode hooks Date: Thu, 3 Dec 2026 13:44:05 +0000 Message-ID: <20261203134411.1092433-2-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203134411.1092433-1-a.s.protopopov@gmail.com> References: <20261203134411.1092433-1-a.s.protopopov@gmail.com> 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 The bpf_get_dentry_xattr() and bpf_get_file_xattr() kfuncs may sleep, so only sleepable LSM programs can call them. The inode_mkdir, inode_link, inode_set_acl, inode_remove_acl, inode_file_setattr and inode_copy_up hooks are not in sleepable_lsm_hooks. So a program on these hooks can't read an xattr, for example to check a label kept in a security.bpf. xattr before a mkdir or an ACL change. All of these hooks are called in process context and may sleep. The vfs_mkdir() and vfs_link() functions call their hooks with the parent directory locked. Cachefiles calls inode_mkdir with no lock held. The vfs_set_acl(), vfs_remove_acl() and vfs_fileattr_set() functions call their hooks with the target inode locked. Overlayfs calls inode_copy_up under its own copy-up lock of the inode. Add the hooks to the set. The bpf_set_dentry_xattr() and bpf_remove_dentry_xattr() kfuncs lock the inode themselves, unless the hook is in d_inode_locked_hooks. For such hooks the verifier replaces them with the _locked variants. Add the ACL and file_setattr hooks to this list, otherwise a program which calls the setters there deadlocks. On inode_copy_up the setters can't be used at all: overlayfs would try to copy the inode up again and wait on the lock which the caller already holds. Refuse them there. Reading an xattr on inode_copy_up is fine. On inode_mkdir and inode_link the dentries passed to the hook are either negative or not locked, so the plain setters are right. Co-developed-by: Daniel Borkmann Signed-off-by: Daniel Borkmann Signed-off-by: Anton Protopopov --- fs/bpf_fs_kfuncs.c | 18 +++++++++++++++++- kernel/bpf/bpf_lsm.c | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c index 35ccd98a4de6..1b973bd4e535 100644 --- a/fs/bpf_fs_kfuncs.c +++ b/fs/bpf_fs_kfuncs.c @@ -527,6 +527,15 @@ BTF_SET_START(bpf_inode_init_xattr_hooks) BTF_ID(func, bpf_lsm_inode_init_security) BTF_SET_END(bpf_inode_init_xattr_hooks) +/* + * Hooks that may not set or remove an xattr. A setter on the overlay + * dentry of inode_copy_up copies it up again and waits on the copy-up + * lock the caller holds. + */ +BTF_SET_START(bpf_xattr_read_only_hooks) +BTF_ID(func, bpf_lsm_inode_copy_up) +BTF_SET_END(bpf_xattr_read_only_hooks) + static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id) { if (!btf_id_set8_contains(&bpf_fs_kfunc_set_ids, kfunc_id)) @@ -539,8 +548,12 @@ static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id) return -EACCES; return 0; } - if (prog->type == BPF_PROG_TYPE_LSM) + if (prog->type == 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 != BPF_PROG_TYPE_STRUCT_OPS) return -EACCES; /* ->st_ops is unset during the cfg pass; enforced once it is set. */ @@ -563,11 +576,14 @@ static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id) * should call bpf_[set|remove]_dentry_xattr. */ BTF_SET_START(d_inode_locked_hooks) +BTF_ID(func, bpf_lsm_inode_file_setattr) BTF_ID(func, bpf_lsm_inode_post_removexattr) BTF_ID(func, bpf_lsm_inode_post_setattr) BTF_ID(func, bpf_lsm_inode_post_setxattr) +BTF_ID(func, bpf_lsm_inode_remove_acl) BTF_ID(func, bpf_lsm_inode_removexattr) BTF_ID(func, bpf_lsm_inode_rmdir) +BTF_ID(func, bpf_lsm_inode_set_acl) BTF_ID(func, bpf_lsm_inode_setattr) BTF_ID(func, bpf_lsm_inode_setxattr) BTF_ID(func, bpf_lsm_inode_unlink) diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c index 1e2acb7581e7..62303210dde9 100644 --- a/kernel/bpf/bpf_lsm.c +++ b/kernel/bpf/bpf_lsm.c @@ -340,18 +340,24 @@ BTF_ID(func, bpf_lsm_file_open) BTF_ID(func, bpf_lsm_file_post_open) BTF_ID(func, bpf_lsm_file_receive) +BTF_ID(func, bpf_lsm_inode_copy_up) BTF_ID(func, bpf_lsm_inode_create) +BTF_ID(func, bpf_lsm_inode_file_setattr) BTF_ID(func, bpf_lsm_inode_free_security) BTF_ID(func, bpf_lsm_inode_getattr) BTF_ID(func, bpf_lsm_inode_getxattr) +BTF_ID(func, bpf_lsm_inode_link) +BTF_ID(func, bpf_lsm_inode_mkdir) BTF_ID(func, bpf_lsm_inode_mknod) BTF_ID(func, bpf_lsm_inode_need_killpriv) BTF_ID(func, bpf_lsm_inode_post_setxattr) BTF_ID(func, bpf_lsm_inode_post_removexattr) BTF_ID(func, bpf_lsm_inode_readlink) +BTF_ID(func, bpf_lsm_inode_remove_acl) BTF_ID(func, bpf_lsm_inode_removexattr) BTF_ID(func, bpf_lsm_inode_rename) BTF_ID(func, bpf_lsm_inode_rmdir) +BTF_ID(func, bpf_lsm_inode_set_acl) BTF_ID(func, bpf_lsm_inode_setattr) BTF_ID(func, bpf_lsm_inode_setxattr) BTF_ID(func, bpf_lsm_inode_symlink) -- 2.43.0