• Sergei Antonov's avatar
    hfsplus: fix B-tree corruption after insertion at position 0 · 23b443f7
    Sergei Antonov authored
    commit 98cf21c61a7f5419d82f847c4d77bf6e96a76f5f upstream.
    
    Fix B-tree corruption when a new record is inserted at position 0 in the
    node in hfs_brec_insert().  In this case a hfs_brec_update_parent() is
    called to update the parent index node (if exists) and it is passed
    hfs_find_data with a search_key containing a newly inserted key instead
    of the key to be updated.  This results in an inconsistent index node.
    The bug reproduces on my machine after an extents overflow record for
    the catalog file (CNID=4) is inserted into the extents overflow B-tree.
    Because of a low (reserved) value of CNID=4, it has to become the first
    record in the first leaf node.
    
    The resulting first leaf node is correct:
    
      ----------------------------------------------------
      | key0.CNID=4 | key1.CNID=123 | key2.CNID=456, ... |
      ----------------------------------------------------
    
    But the parent index key0 still contains the previous key CNID=123:
    
      -----------------------
      | key0.CNID=123 | ... |
      -----------------------
    
    A change in hfs_brec_insert() makes hfs_brec_update_parent() work
    correctly by preventing it from getting fd->record=-1 value from
    __hfs_brec_find().
    
    Along the way, I removed duplicate code with unification of the if
    condition.  The resulting code is equivalent to the original code
    because node is never 0.
    
    Also hfs_brec_update_parent() will now return an error after getting a
    negative fd->record value.  However, the return value of
    hfs_brec_update_parent() is not checked anywhere in the file and I'm
    leaving it unchanged by this patch.  brec.c lacks error checking after
    some other calls too, but this issue is of less importance than the one
    being fixed by this patch.
    Signed-off-by: 's avatarSergei Antonov <saproj@gmail.com>
    Cc: Joe Perches <joe@perches.com>
    Reviewed-by: 's avatarVyacheslav Dubeyko <slava@dubeyko.com>
    Acked-by: 's avatarHin-Tak Leung <htl10@users.sourceforge.net>
    Cc: Anton Altaparmakov <aia21@cam.ac.uk>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Cc: Christoph Hellwig <hch@infradead.org>
    Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    23b443f7
Name
Last commit
Last update
..
Kconfig Loading commit data...
Makefile Loading commit data...
attributes.c Loading commit data...
bfind.c Loading commit data...
bitmap.c Loading commit data...
bnode.c Loading commit data...
brec.c Loading commit data...
btree.c Loading commit data...
catalog.c Loading commit data...
dir.c Loading commit data...
extents.c Loading commit data...
hfsplus_fs.h Loading commit data...
hfsplus_raw.h Loading commit data...
inode.c Loading commit data...
ioctl.c Loading commit data...
options.c Loading commit data...
part_tbl.c Loading commit data...
super.c Loading commit data...
tables.c Loading commit data...
unicode.c Loading commit data...
wrapper.c Loading commit data...
xattr.c Loading commit data...
xattr.h Loading commit data...
xattr_security.c Loading commit data...
xattr_trusted.c Loading commit data...
xattr_user.c Loading commit data...