Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796304761; b=DT279NEvCP31/++QM4szqZN8MWbhrMqlNzY6/+r4LFnMiqXwn1CEexKoku8MvKa+GN6A GpfK2NQvwcl9IATRrVDVPiJWQNDxd8sMRbN44BeqfdK1Z0INAc58Xb7oDCDkPKaQYSNHG P9E+Q9tAq/dTnl1j7Lg0aW+xxKDo2QUhplPStAIbtPtuWD0kJVRGu2PX/DGH4TboLBxZi 74JQikbFth8+DA3V4LBPuGNlpCUYlgey6XAFXhnr4VEMauiNIcv9e4+k7SNcl59dEs/yM 6g+6bGumUPeVHZmx0jmZlrONFcnA0G5oxnWx6tDVnm8K8gnVARR0SUh21yIoeJQYl3Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796304761; 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=Xa+m8A7isflfvYbLnJIolGWzC3rdejwio6mnBLXgVrM=; b=JkVDDli9yalq7JSlYULOX/Lw+pIiE8a1FFsgy5awsxIYrbHMQVvZgKE+cMLv43o2SSVX lTSgXIiLQXYUiQW8ZGtI/dBB9Flj0dTX4lRifrhPABXvEhmn/YlMcHb9RvIaRD4LkDIuC RgD/DdlWHAWg9+ch0F1IZajMFFVgSZ6CZMlbbB9V3zAaiLaiPvEy1pxNkgI7Z00sEpit2 Bw660KRdL+f29evhA1R+KspZVNo1hk/b/OazZNItZ7b9mbFrCCvExySjxT0lW6KxL2Erq enkg9PFMenNlVMRpTfnQiqfuehEBiRqRpMv+Tdy3m1KeZKO3ww9kXs0YZhNm6DGQkFg== 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=ebOofKYt; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 C67E6606A32F for ; Thu, 3 Dec 2026 13:32:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C67E6606A32F 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=ebOofKYt Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4a207b02a2cso104121355e9.1 for ; Thu, 03 Dec 2026 05:32:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796304759; x=1796909559; 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=Xa+m8A7isflfvYbLnJIolGWzC3rdejwio6mnBLXgVrM=; b=ebOofKYtELp+uSZszfXQT7LRJN4CvimgNsb6jJ4twhbpa5/2Nrj7TwGHxLyrk55jvm fakp371HUQ+85Ou99N3DuJcikkKSbuTiJmI04bbqtVXn5BwpGJtv18a0zaXSvtBJj5ZO PVo77PXJJLENQw2T7cywfLdeCa3Tz7I72kaD560D34dpDZ3GwW6zvJg1sCXyVdoT536e JKFILxQqNs4rdF45KUPpdryncMLDt5onzP9gGQpgjnWZRMH09qSsLC8QERcYa3pFYZ9U HaDmIriog66GK8FOA7Ng9f8ZseOJVOd03W+paoTpkvWalTnFRKXa8PCCbQh1mOnn8wie 96PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796304759; x=1796909559; 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=Xa+m8A7isflfvYbLnJIolGWzC3rdejwio6mnBLXgVrM=; b=GbqkLCelcgb6ZDSxKw1Ja3gab6B8rmi9lt6dC7BpQIE/gIiZ3BpiWEjfAjB+w6k7nX Iz4mbYAZRiXzRlSW1puG9toIrxEDT7mGNoVnfz1VSEUvRJjjrpIS7W/5yVU/uQ6uLkXx lLl1C1w54bumVCECHJw+sukCEA3tRUSV1TvYj9087neXZVZYNwpWHsWJmuKq9tvQspvN qvdALZU4B2az5lvQUIFfCYzrPldXj33fF7OwITYJjl71eWoefrfvtwA7BS7O8Ylvu89y iU4TSwPW34k0FUTVOEr51N5N0j/fDF2lly9Es5JI++8xgqqI77gYmgxMtXlCWZ5namXp 7cDA== X-Forwarded-Encrypted: i=1; AL+hErEpOb9boiDFwvi5TYw5Mb384wsKYz+bjuTHUYutEEgvyv4/cfokkqwIv+EUWmTmUJHz7WU=@vger.kernel.org X-Gm-Message-State: APuU4Z/nyR9mjHlTDdwBuaFgBtBo5nYS7T3RoxuMgzuTjk5SshpDUxKr goEdkoOIZdWQe9eGn3uc//CgSjopY+OeLgVZ/x++ZebYo96Ou1rpE4/l X-Gm-Gg: AZFdTZfTVEfo+L2Dn+VbRJw03KbmxOSHcILxKlXPgeamM2FSTRkvEIMKG/zzVZgyqAh 0noQNPKQqMr5jNP5kS0OaxpO3af3lDWYCMV86PI1Mt6pWrJIM68XTb1R/Li0cybQpcL1Idjq3DM q6qWsl/wPDRaxK3UGTC7u0w7J+J+cLQjKA6RJbo2jA3kSnVrpkzqqbo83ZnG2QxyQ9/QkSjg2Nb iRjD4GgkdCObEaLSoxvHgRObXKPqBD/nuLgNC78pW/5ZF5HdUYTbxhPK+sFOMYfidv52olp7pte GLp+pCU1lKs8VW2t2KbU5frEkvS6LzPd9iQ0T8luJ1a8IIQ/dILb4tKzvfboLIgVwea6hHIgltC A7lI2vozWWNy8KmetxqveriwQHVMpjwNIsNdRNpofnFazYlVBLRMFRUZbmWPyeRNRgRpw3D744r ZU53O8olSbb7hmI1uHDTaqRc6n0lB2McaDoFgjOSCWk63C9QZPi7hPGfEFOijBDJ7f+mR/VZB+n uINP2NhLnTWto9CxKa2bgH1FSyoe0R5FZww/SQg9aCa9Rc/yGvwsYOxHs5Ve2S2GoTw3GmLSDs2 eAH48priPPedh+HAo/vx7sSRyBpnerplpg39/jMPuOIJwVY= X-Received: by 2002:a05:600c:b8a:b0:4bb:7007:4a5a with SMTP id 5b1f17b1804b1-4bb88817772mr882270215e9.23.1796304759031; Thu, 03 Dec 2026 05:32:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:32:38 -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 2/3] bpf: Add a bpf_get_inode_xattr kfunc Date: Thu, 3 Dec 2026 13:44:06 +0000 Message-ID: <20261203134411.1092433-3-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: 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 The inode_create, inode_mkdir, inode_mknod, inode_symlink, inode_link and inode_rename hooks get the parent directory as an inode and the new entry as a dentry. To check a label of the directory, a program needs to read its xattr, but bpf_get_dentry_xattr() takes a dentry. The only dentry of the directory at hand is dentry->d_parent, and the verifier doesn't trust it. Making d_parent trusted would be wrong. It would be trusted on every hook, and many hooks don't hold the lock of the parent directory. For example, inode_getxattr and inode_readlink hold no lock at all. A concurrent rename can then move the dentry to another directory, and the old parent can be freed while a sleepable program still uses it. Add the bpf_get_inode_xattr() kfunc which reads an xattr of an inode through any of its dentries, found with d_find_any_alias(). Xattrs belong to the inode, so any dentry will do. d_find_alias() would not: it skips the unhashed dentry of an unlinked file which is still open. The kfunc doesn't change xattrs, so the setters still get only the dentries passed to the hook, and d_inode_locked_hooks stays correct for them. Signed-off-by: Anton Protopopov --- fs/bpf_fs_kfuncs.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c index 1b973bd4e535..654340a0bc70 100644 --- a/fs/bpf_fs_kfuncs.c +++ b/fs/bpf_fs_kfuncs.c @@ -169,6 +169,35 @@ __bpf_kfunc int bpf_get_file_xattr(struct file *file, const char *name__str, return bpf_get_dentry_xattr(dentry, name__str, value_p); } +/** + * bpf_get_inode_xattr - get xattr of an inode + * @inode: inode to get xattr from + * @name__str: name of the xattr + * @value_p: output buffer of the xattr value + * + * Get xattr *name__str* of *inode* and store the output in *value_ptr*. + * The xattr is read through any dentry of *inode*. + * + * For security reasons, only *name__str* with prefixes "user." or + * "security.bpf." are allowed. + * + * Return: length of the xattr value on success, -ENOENT if *inode* has + * no dentry, another negative value on error. + */ +__bpf_kfunc int bpf_get_inode_xattr(struct inode *inode, const char *name__str, + struct bpf_dynptr *value_p) +{ + struct dentry *dentry; + int ret; + + dentry = d_find_any_alias(inode); + if (!dentry) + return -ENOENT; + ret = bpf_get_dentry_xattr(dentry, name__str, value_p); + dput(dentry); + return ret; +} + __bpf_kfunc_end_defs(); static int bpf_xattr_write_permission(const char *name, struct inode *inode) @@ -506,6 +535,7 @@ BTF_ID_FLAGS(func, bpf_put_file, KF_RELEASE) BTF_ID_FLAGS(func, bpf_path_d_path) BTF_ID_FLAGS(func, bpf_get_dentry_xattr, KF_SLEEPABLE) BTF_ID_FLAGS(func, bpf_get_file_xattr, KF_SLEEPABLE) +BTF_ID_FLAGS(func, bpf_get_inode_xattr, KF_SLEEPABLE) BTF_ID_FLAGS(func, bpf_set_dentry_xattr, KF_SLEEPABLE) BTF_ID_FLAGS(func, bpf_remove_dentry_xattr, KF_SLEEPABLE) BTF_ID_FLAGS(func, bpf_real_data_inode, KF_SLEEPABLE | KF_RET_NULL) -- 2.43.0