linux/fs/hfsplus
Sergei Antonov 4bcbae5481 hfsplus: fix B-tree corruption after insertion at position 0
commit 98cf21c61a 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: Sergei Antonov <saproj@gmail.com>
Cc: Joe Perches <joe@perches.com>
Reviewed-by: Vyacheslav Dubeyko <slava@dubeyko.com>
Acked-by: Hin-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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-04-13 14:03:03 +02:00
..
acl.h hfsplus: use generic posix ACL infrastructure 2014-01-25 23:58:20 -05:00
attributes.c hfs/hfsplus: convert printks to pr_<level> 2013-04-30 17:04:05 -07:00
bfind.c hfs/hfsplus: convert printks to pr_<level> 2013-04-30 17:04:05 -07:00
bitmap.c hfsplus: remove duplicated message prefix in hfsplus_block_free() 2013-04-30 17:04:05 -07:00
bnode.c hfs/hfsplus: convert printks to pr_<level> 2013-04-30 17:04:05 -07:00
brec.c hfsplus: fix B-tree corruption after insertion at position 0 2015-04-13 14:03:03 +02:00
btree.c hfsplus: add metadata file's clump size calculation functionality 2013-11-13 12:09:32 +09:00
catalog.c hfsplus: add HFSX subfolder count support 2014-03-10 17:26:21 -07:00
dir.c hfsplus: use xattr handlers for removexattr 2014-01-31 14:44:39 -05:00
extents.c hfsplus: add error propagation to __hfsplus_ext_write_extent() 2013-04-30 17:04:05 -07:00
hfsplus_fs.h hfsplus: add HFSX subfolder count support 2014-03-10 17:26:21 -07:00
hfsplus_raw.h hfsplus: add HFSX subfolder count support 2014-03-10 17:26:21 -07:00
inode.c hfsplus: add HFSX subfolder count support 2014-03-10 17:26:21 -07:00
ioctl.c hfsplus: add support of manipulation by attributes file 2013-02-27 19:10:10 -08:00
Kconfig hfsplus: add necessary declarations for POSIX ACLs support 2013-09-11 15:59:00 -07:00
Makefile hfsplus: integrate POSIX ACLs support into driver 2013-09-11 15:59:01 -07:00
options.c hfsplus: fix remount issue 2014-03-04 07:55:49 -08:00
part_tbl.c hfsplus: ensure bio requests are not smaller than the hardware sectors 2011-07-22 16:37:44 +02:00
posix_acl.c hfsplus: use generic posix ACL infrastructure 2014-01-25 23:58:20 -05:00
super.c hfsplus: implement attributes file creation functionality 2013-11-13 12:09:32 +09:00
tables.c Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
unicode.c Don't pass inode to ->d_hash() and ->d_compare() 2013-06-29 12:57:36 +04:00
wrapper.c block: submit_bio_wait() conversions 2013-11-24 16:33:41 -07:00
xattr_security.c hfsplus: integrate POSIX ACLs support into driver 2013-09-11 15:59:01 -07:00
xattr_trusted.c hfsplus: rework functionality of getting, setting and deleting of extended attributes 2013-02-27 19:10:10 -08:00
xattr_user.c hfsplus: rework functionality of getting, setting and deleting of extended attributes 2013-02-27 19:10:10 -08:00
xattr.c hfsplus: use xattr handlers for removexattr 2014-01-31 14:44:39 -05:00
xattr.h hfsplus: use xattr handlers for removexattr 2014-01-31 14:44:39 -05:00