[Bug 1024843] New: Btrfs: fix tree search logic when replaying directory entry deletes
![](https://seccdn.libravatar.org/avatar/3035b38ff33cf86f480bb169b8500b80.jpg?s=120&d=mm&r=g)
http://bugzilla.suse.com/show_bug.cgi?id=1024843 Bug ID: 1024843 Summary: Btrfs: fix tree search logic when replaying directory entry deletes Classification: openSUSE Product: openSUSE Distribution Version: Leap 42.1 Hardware: Other OS: Other Status: NEW Severity: Normal Priority: P5 - None Component: Kernel Assignee: jeffm@suse.com Reporter: jeffm@suse.com QA Contact: qa-bugs@suse.de Found By: --- Blocker: ---
From robbieko@synology.com Fri Feb 10 14:01:15 2017 From: Robbie Ko
Date: Fri, 7 Oct 2016 17:30:47 +0800 Subject: Btrfs: fix tree search logic when replaying directory entry deletes Git-commit: 2a7bf53f577e49c43de4ffa7776056de26db65d9 Patch-mainline: v4.10-rc1 References: pulled from 4.4-stable (4.1-stable had expired)
If a log tree has a layout like the following:
leaf N:
...
item 240 key (282 DIR_LOG_ITEM 0) itemoff 8189 itemsize 8
dir log end 1275809046
leaf N + 1:
item 0 key (282 DIR_LOG_ITEM 3936149215) itemoff 16275 itemsize 8
dir log end 18446744073709551615
...
When we pass the value 1275809046 + 1 as the parameter start_ret to the
function tree-log.c:find_dir_range() (done by replay_dir_deletes()), we
end up with path->slots[0] having the value 239 (points to the last item
of leaf N, item 240). Because the dir log item in that position has an
offset value smaller than *start_ret (1275809046 + 1) we need to move on
to the next leaf, however the logic for that is wrong since it compares
the current slot to the number of items in the leaf, which is smaller
and therefore we don't lookup for the next leaf but instead we set the
slot to point to an item that does not exist, at slot 240, and we later
operate on that slot which has unexpected content or in the worst case
can result in an invalid memory access (accessing beyond the last page
of leaf N's extent buffer).
So fix the logic that checks when we need to lookup at the next leaf
by first incrementing the slot and only after to check if that slot
is beyond the last item of the current leaf.
Signed-off-by: Robbie Ko
![](https://seccdn.libravatar.org/avatar/3035b38ff33cf86f480bb169b8500b80.jpg?s=120&d=mm&r=g)
http://bugzilla.suse.com/show_bug.cgi?id=1024843
http://bugzilla.suse.com/show_bug.cgi?id=1024843#c1
--- Comment #1 from Jeff Mahoney
![](https://seccdn.libravatar.org/avatar/3035b38ff33cf86f480bb169b8500b80.jpg?s=120&d=mm&r=g)
http://bugzilla.suse.com/show_bug.cgi?id=1024843
http://bugzilla.suse.com/show_bug.cgi?id=1024843#c2
Jeff Mahoney
![](https://seccdn.libravatar.org/avatar/3035b38ff33cf86f480bb169b8500b80.jpg?s=120&d=mm&r=g)
http://bugzilla.suse.com/show_bug.cgi?id=1024843
http://bugzilla.suse.com/show_bug.cgi?id=1024843#c3
--- Comment #3 from Jeff Mahoney
participants (1)
-
bugzilla_noreply@novell.com