From: Tejun Heo Date: Mon, 4 Nov 2019 23:54:29 +0000 (-0800) Subject: kernfs: kernfs_find_and_get_node_by_ino() should only look up activated nodes X-Git-Tag: v5.5-rc1~178^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=880df131617393252f1fff701ed5b7b6d14c52c4;p=thirdparty%2Fkernel%2Flinux.git kernfs: kernfs_find_and_get_node_by_ino() should only look up activated nodes kernfs node can be created in two separate steps - allocation and activation. This is used to make kernfs nodes visible only after the internal states attached to the node are fully initialized. kernfs_find_and_get_node_by_id() currently allows lookups of nodes which aren't activated yet and thus can expose nodes are which are still being prepped by kernfs users. Fix it by disallowing lookups of nodes which aren't activated yet. kernfs_find_and_get_node_by_ino() Signed-off-by: Tejun Heo Reviewed-by: Greg Kroah-Hartman Cc: Namhyung Kim --- diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 798f0f03b62bb..beabb585a7d88 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -714,7 +714,13 @@ struct kernfs_node *kernfs_find_and_get_node_by_ino(struct kernfs_root *root, if (!kn) goto err_unlock; - if (unlikely(!atomic_inc_not_zero(&kn->count))) + /* + * ACTIVATED is protected with kernfs_mutex but it was clear when + * @kn was added to idr and we just wanna see it set. No need to + * grab kernfs_mutex. + */ + if (unlikely(!(kn->flags & KERNFS_ACTIVATED) || + !atomic_inc_not_zero(&kn->count))) goto err_unlock; spin_unlock(&kernfs_idr_lock);