Commit 20e6d9a8 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix lookup_inode_for_snapshot()

This fixes a use-after-free.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 6b20d746
......@@ -682,6 +682,7 @@ lookup_inode_for_snapshot(struct bch_fs *c, struct inode_walker *w,
if (snapshot != i->snapshot && !is_whiteout) {
struct inode_walker_entry new = *i;
size_t pos;
int ret;
new.snapshot = snapshot;
......@@ -693,9 +694,12 @@ lookup_inode_for_snapshot(struct bch_fs *c, struct inode_walker *w,
while (i > w->inodes.data && i[-1].snapshot > snapshot)
--i;
ret = darray_insert_item(&w->inodes, i - w->inodes.data, new);
pos = i - w->inodes.data;
ret = darray_insert_item(&w->inodes, pos, new);
if (ret)
return ERR_PTR(ret);
i = w->inodes.data + pos;
}
return i;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment