From nobody Fri Nov 20 14:06:43 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jWHFb7087z71pgT for ; Fri, 20 Nov 2026 14:06:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jWHFb4BB2z4Y0Q for ; Fri, 20 Nov 2026 14:06:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795183603; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JGOWNIGlrGcsmXqrdyhfZEl0NN0rg+IZNt1rl5KtF7E=; b=gXD3ZRNO0eb6j8oqG4r7eGoDhcXzVD0NaZG/IozmAOW8MDZlHDKFLz7StUvJV+0JZ2TsIw smAovSZ4vjUfyHM/wu2dQnbjLqzyGfrt46kGYpgdJiySmLnA2sjWNWfjyuoJe9O1uGTQs4 HsnaA3jglWXBCBgVixWwomlzSUwRlaBqbe1xXFElzpdbSLAyhnf7fasDTyv5tqYEsQ0IRV 3Lt9gYQbVdBV03o/zIkQQjy0z4o5Q7vCSw/WnJx5dC6PeuX95uJd1RWHisXBYEisyl26gC /opo1VWCUbNM6tw5MtmjG2jk2dyGqphI3BVWYkN7x9bqAFrl406rql8z8HeLGA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795183603; b=FOZyO5PxfrpusDRysXE9BPolbFbQebRJM40AMOHHwBOBXeep3QnrBfXDYSw1P8wS9N398j v3RTHtagCKm6qVgLoHE6G15t7ghLYznOPNiBSKO54GVj/nJiU85gIy71XFJKq73sXhjkNP iu4l8JcBS9jLiDScMXVcwB45MM+2IKj7S7ByyrtKVymkoFL55VDK0qHyVmXYPebWtpk9di 4+M3Ez1wwEA2MENcBlaG1XbmoH2W8ghGo8giWaDRVewuKB4xCb3Uh+C17NWx1TT/3h6CDq SRh42JWZMu+bfaIBbgI9okYxXThrTzK2Adzpby0jWD+163IyHnqYYfi5e2W2JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795183603; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JGOWNIGlrGcsmXqrdyhfZEl0NN0rg+IZNt1rl5KtF7E=; b=OhcUsl30FEZ6iztcuxc/xbmEaTmHDst+BaCplUmsxqWTJMsyZG3K+mzQSoyPnlRgRmZtCx aS+43T6Qu4RNxuOZnaHM2UXRe3JvEnkKmd5u35fgZF+OeQWAqeNzQpglNPXoB+50Tdjxer w+jlcqAMNHKwxhe5hZs967syyLHPmWbCRJNqixBj1atWLAr7+Z76Gd/vZ+B2zpND7B71Si 93q2MF75gc2ybbPFqkOL7paMJgnPbTcmgAwu+bNb9XJQ1R+8/CI6uzLVY5wIAlxqAMjts6 8tTzXAoRmrzqmp+Zs+WFKgUBnMXb/fGZRyFbVRkyi5OFEzoa7b003bpld4VdeQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jWHFb3Fn7zrMD for ; Fri, 20 Nov 2026 14:06:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 115fa by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 20 Nov 2026 14:06:43 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: d5cbb6229f53 - main - lindebugfs: Do not expose a node before its private data is set List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d5cbb6229f53c213f1ce769c0dacd1a979ec000f Auto-Submitted: auto-generated Date: Fri, 20 Nov 2026 14:06:43 +0000 Message-Id: <6b0053f3.115fa.13a7959f@gitrepo.freebsd.org> The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=d5cbb6229f53c213f1ce769c0dacd1a979ec000f commit d5cbb6229f53c213f1ce769c0dacd1a979ec000f Author: Emmanuel Vadot AuthorDate: 2026-11-18 08:27:18 +0000 Commit: Emmanuel Vadot CommitDate: 2026-11-20 14:05:59 +0000 lindebugfs: Do not expose a node before its private data is set pfs_create_file(), pfs_create_dir() and pfs_create_link() link the new node into its parent and return, and only then do the debugfs_create_*() functions set pn_data. Between the two, the node can already be found by a lookup but pn_data is NULL, so a concurrent stat(2) or read(2) calls debugfs_attr(), debugfs_fill() or debugfs_fill_data() which dereference it: a driver creating debugfs entries while lindebugfs is mounted can panic whoever is looking at the tree at that moment. The window is only a few instructions wide, which made it hard to hit; with a delay added on purpose it panics at once in debugfs_attr() called from stat(2). Changing pfs_create_*() to take the data would change the pseudofs API and ABI. Use the visibility callback instead: pseudofs checks it before creating a vnode for a node and before getattr, read and write, so a node whose pn_data is not set yet is reported as not visible and lookups return ENOENT. The data is published with a release store and read with an acquire load, so whoever sees the pointer sees the initialized dentry_meta. debugfs_lookup() now also returns NULL for such a node. Reviewed by: dumbell Reported by: llm-postcr Differential Revision: https://reviews.freebsd.org/D61705 --- sys/compat/lindebugfs/lindebugfs.c | 41 ++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/sys/compat/lindebugfs/lindebugfs.c b/sys/compat/lindebugfs/lindebugfs.c index b26d2b31b62f..af9e2a24b899 100644 --- a/sys/compat/lindebugfs/lindebugfs.c +++ b/sys/compat/lindebugfs/lindebugfs.c @@ -88,6 +88,27 @@ struct dentry_meta { int dm_type; }; +/* + * pseudofs makes a node visible to lookups as soon as pfs_create_*() has added + * it to its parent, but pn_data can only be set once these functions return. + * Report the node as not visible until then, so that nothing can reach it + * (lookups fail with ENOENT) while pn_data is still NULL. The release store + * makes the dentry_meta contents visible to whoever sees the pointer. + */ +static int +debugfs_vis(PFS_VIS_ARGS) +{ + + return (atomic_load_acq_ptr((volatile uintptr_t *)&pn->pn_data) != 0); +} + +static void +debugfs_set_data(struct pfs_node *pn, struct dentry_meta *dm) +{ + + atomic_store_rel_ptr((volatile uintptr_t *)&pn->pn_data, (uintptr_t)dm); +} + static int debugfs_attr(PFS_ATTR_ARGS) { @@ -235,12 +256,13 @@ debugfs_create_file(const char *name, umode_t mode, flags = fops->write ? PFS_RDWR : PFS_RD; pfs_create_file(pnode, &dnode->d_pfs_node, name, debugfs_fill, - debugfs_attr, NULL, debugfs_destroy, flags | PFS_RAW | PFS_NOWAIT); + debugfs_attr, debugfs_vis, debugfs_destroy, + flags | PFS_RAW | PFS_NOWAIT); if (dnode->d_pfs_node == NULL) { free(dm, M_DFSINT); return (NULL); } - dnode->d_pfs_node->pn_data = dm; + debugfs_set_data(dnode->d_pfs_node, dm); return (dnode); } @@ -314,13 +336,13 @@ debugfs_create_dir(const char *name, struct dentry *parent) else pnode = debugfs_root; - pfs_create_dir(pnode, &dnode->d_pfs_node, name, debugfs_attr, NULL, - debugfs_destroy, PFS_RD | PFS_NOWAIT); + pfs_create_dir(pnode, &dnode->d_pfs_node, name, debugfs_attr, + debugfs_vis, debugfs_destroy, PFS_RD | PFS_NOWAIT); if (dnode->d_pfs_node == NULL) { free(dm, M_DFSINT); return (NULL); } - dnode->d_pfs_node->pn_data = dm; + debugfs_set_data(dnode->d_pfs_node, dm); return (dnode); } @@ -349,10 +371,10 @@ debugfs_create_symlink(const char *name, struct dentry *parent, pnode = debugfs_root; pfs_create_link(pnode, &dnode->d_pfs_node, name, &debugfs_fill_data, - NULL, NULL, debugfs_destroy, PFS_NOWAIT); + NULL, debugfs_vis, debugfs_destroy, PFS_NOWAIT); if (dnode->d_pfs_node == NULL) goto fail; - dnode->d_pfs_node->pn_data = dm; + debugfs_set_data(dnode->d_pfs_node, dm); return (dnode); fail: free(dm, M_DFSINT); @@ -372,7 +394,10 @@ debugfs_lookup(const char *name, struct dentry *parent) if (pnode == NULL) return (NULL); - dm = (struct dentry_meta *)pnode->pn_data; + dm = (struct dentry_meta *)atomic_load_acq_ptr( + (volatile uintptr_t *)&pnode->pn_data); + if (dm == NULL) + return (NULL); dnode = &dm->dm_dnode; return (dnode);