mirror of
https://github.com/torvalds/linux.git
synced 2024-11-27 14:41:39 +00:00
kernfs: fix a subdir count leak
Currently kernfs_link_sibling() increates parent->dir.subdirs before adding the node into parent's chidren rb tree. Because it is possible that kernfs_link_sibling() couldn't find a suitable slot and bail out, this leads to a mismatch between elevated subdir count with actual children node numbers. This patches fix this problem, by moving the subdir accouting after the actual addtion happening. Signed-off-by: Jianyu Zhan <nasa4836@gmail.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
a798c10faf
commit
c1befb8859
@ -232,9 +232,6 @@ static int kernfs_link_sibling(struct kernfs_node *kn)
|
|||||||
struct rb_node **node = &kn->parent->dir.children.rb_node;
|
struct rb_node **node = &kn->parent->dir.children.rb_node;
|
||||||
struct rb_node *parent = NULL;
|
struct rb_node *parent = NULL;
|
||||||
|
|
||||||
if (kernfs_type(kn) == KERNFS_DIR)
|
|
||||||
kn->parent->dir.subdirs++;
|
|
||||||
|
|
||||||
while (*node) {
|
while (*node) {
|
||||||
struct kernfs_node *pos;
|
struct kernfs_node *pos;
|
||||||
int result;
|
int result;
|
||||||
@ -249,9 +246,15 @@ static int kernfs_link_sibling(struct kernfs_node *kn)
|
|||||||
else
|
else
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add new node and rebalance the tree */
|
/* add new node and rebalance the tree */
|
||||||
rb_link_node(&kn->rb, parent, node);
|
rb_link_node(&kn->rb, parent, node);
|
||||||
rb_insert_color(&kn->rb, &kn->parent->dir.children);
|
rb_insert_color(&kn->rb, &kn->parent->dir.children);
|
||||||
|
|
||||||
|
/* successfully added, account subdir number */
|
||||||
|
if (kernfs_type(kn) == KERNFS_DIR)
|
||||||
|
kn->parent->dir.subdirs++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user