From 987c5acd76f0425f79f1f1ba34fcf5d167b57246 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sun, 13 Nov 2011 16:51:57 +0000 Subject: [PATCH] hfs: fix hfs_find_init() sb->ext_tree NULL ptr oops (CVE-2011-2203) svn path=/dists/trunk/linux-2.6/; revision=18258 --- debian/changelog | 1 + ..._find_init-sb-ext_tree-NULL-ptr-oops.patch | 89 +++++++++++++++++++ debian/patches/series/base | 1 + 3 files changed, 91 insertions(+) create mode 100644 debian/patches/bugfix/all/hfs-fix-hfs_find_init-sb-ext_tree-NULL-ptr-oops.patch diff --git a/debian/changelog b/debian/changelog index b4ffd2dd4..ff62e6df0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,7 @@ linux-2.6 (3.1.1-1) UNRELEASED; urgency=low * [alpha] Remove old, broken udeb configuration * DFSG: Remove drivers/staging/ft1000/ft1000-*/*.img, non-free firmware for drivers we don't build + * hfs: fix hfs_find_init() sb->ext_tree NULL ptr oops (CVE-2011-2203) -- Ben Hutchings Fri, 04 Nov 2011 15:05:47 +0000 diff --git a/debian/patches/bugfix/all/hfs-fix-hfs_find_init-sb-ext_tree-NULL-ptr-oops.patch b/debian/patches/bugfix/all/hfs-fix-hfs_find_init-sb-ext_tree-NULL-ptr-oops.patch new file mode 100644 index 000000000..8f9ebcb58 --- /dev/null +++ b/debian/patches/bugfix/all/hfs-fix-hfs_find_init-sb-ext_tree-NULL-ptr-oops.patch @@ -0,0 +1,89 @@ +From: Phillip Lougher +Date: Wed, 2 Nov 2011 13:38:01 -0700 +Subject: [PATCH] hfs: fix hfs_find_init() sb->ext_tree NULL ptr oops + +commit 434a964daa14b9db083ce20404a4a2add54d037a upstream. + +Clement Lecigne reports a filesystem which causes a kernel oops in +hfs_find_init() trying to dereference sb->ext_tree which is NULL. + +This proves to be because the filesystem has a corrupted MDB extent +record, where the extents file does not fit into the first three extents +in the file record (the first blocks). + +In hfs_get_block() when looking up the blocks for the extent file +(HFS_EXT_CNID), it fails the first blocks special case, and falls +through to the extent code (which ultimately calls hfs_find_init()) +which is in the process of being initialised. + +Hfs avoids this scenario by always having the extents b-tree fitting +into the first blocks (the extents B-tree can't have overflow extents). + +The fix is to check at mount time that the B-tree fits into first +blocks, i.e. fail if HFS_I(inode)->alloc_blocks >= +HFS_I(inode)->first_blocks + +Note, the existing commit 47f365eb57573 ("hfs: fix oops on mount with +corrupted btree extent records") becomes subsumed into this as a special +case, but only for the extents B-tree (HFS_EXT_CNID), it is perfectly +acceptable for the catalog B-Tree file to grow beyond three extents, +with the remaining extent descriptors in the extents overfow. + +This fixes CVE-2011-2203 + +Reported-by: Clement LECIGNE +Signed-off-by: Phillip Lougher +Cc: Jeff Mahoney +Cc: Christoph Hellwig +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +--- + fs/hfs/btree.c | 20 +++++++++++++++----- + 1 files changed, 15 insertions(+), 5 deletions(-) + +diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c +index 3ebc437..1cbdeea 100644 +--- a/fs/hfs/btree.c ++++ b/fs/hfs/btree.c +@@ -46,11 +46,26 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke + case HFS_EXT_CNID: + hfs_inode_read_fork(tree->inode, mdb->drXTExtRec, mdb->drXTFlSize, + mdb->drXTFlSize, be32_to_cpu(mdb->drXTClpSiz)); ++ if (HFS_I(tree->inode)->alloc_blocks > ++ HFS_I(tree->inode)->first_blocks) { ++ printk(KERN_ERR "hfs: invalid btree extent records\n"); ++ unlock_new_inode(tree->inode); ++ goto free_inode; ++ } ++ + tree->inode->i_mapping->a_ops = &hfs_btree_aops; + break; + case HFS_CAT_CNID: + hfs_inode_read_fork(tree->inode, mdb->drCTExtRec, mdb->drCTFlSize, + mdb->drCTFlSize, be32_to_cpu(mdb->drCTClpSiz)); ++ ++ if (!HFS_I(tree->inode)->first_blocks) { ++ printk(KERN_ERR "hfs: invalid btree extent records " ++ "(0 size).\n"); ++ unlock_new_inode(tree->inode); ++ goto free_inode; ++ } ++ + tree->inode->i_mapping->a_ops = &hfs_btree_aops; + break; + default: +@@ -59,11 +74,6 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke + } + unlock_new_inode(tree->inode); + +- if (!HFS_I(tree->inode)->first_blocks) { +- printk(KERN_ERR "hfs: invalid btree extent records (0 size).\n"); +- goto free_inode; +- } +- + mapping = tree->inode->i_mapping; + page = read_mapping_page(mapping, 0, NULL); + if (IS_ERR(page)) +-- +1.7.7.2 + diff --git a/debian/patches/series/base b/debian/patches/series/base index e76a90a9b..4f9fa6413 100644 --- a/debian/patches/series/base +++ b/debian/patches/series/base @@ -55,3 +55,4 @@ + bugfix/all/CIFS-Fixup-trivial-checkpatch-warning.patch + bugfix/all/Fix-build-break-when-freezer-not-configured.patch + bugfix/all/PM-Freezer-Reimplement-wait_event_freezekillable-usi.patch ++ bugfix/all/hfs-fix-hfs_find_init-sb-ext_tree-NULL-ptr-oops.patch