Commit eb2e5f45 authored by Dave Anderson's avatar Dave Anderson Committed by Linus Torvalds

hfs: fix memory leak when unmounting

When an HFS filesystem is unmounted, it leaks a 2-page bitmap.  Also,
under extreme memory pressure, it's possible that hfs_releasepage() may
use a tree pointer that has not been initialized, and if so, the release
request should just be rejected.

[akpm@linux-foundation.org: free_pages(0) is legal, remove obvious comment]
Signed-off-by: default avatarDave Anderson <anderson@redhat.com>
Tested-by: default avatarEugene Teo <eugeneteo@kernel.sg>
Cc: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 251eb40f
...@@ -70,6 +70,10 @@ static int hfs_releasepage(struct page *page, gfp_t mask) ...@@ -70,6 +70,10 @@ static int hfs_releasepage(struct page *page, gfp_t mask)
BUG(); BUG();
return 0; return 0;
} }
if (!tree)
return 0;
if (tree->node_size >= PAGE_CACHE_SIZE) { if (tree->node_size >= PAGE_CACHE_SIZE) {
nidx = page->index >> (tree->node_size_shift - PAGE_CACHE_SHIFT); nidx = page->index >> (tree->node_size_shift - PAGE_CACHE_SHIFT);
spin_lock(&tree->hash_lock); spin_lock(&tree->hash_lock);
......
...@@ -349,6 +349,7 @@ void hfs_mdb_put(struct super_block *sb) ...@@ -349,6 +349,7 @@ void hfs_mdb_put(struct super_block *sb)
if (HFS_SB(sb)->nls_disk) if (HFS_SB(sb)->nls_disk)
unload_nls(HFS_SB(sb)->nls_disk); unload_nls(HFS_SB(sb)->nls_disk);
free_pages((unsigned long)HFS_SB(sb)->bitmap, PAGE_SIZE < 8192 ? 1 : 0);
kfree(HFS_SB(sb)); kfree(HFS_SB(sb));
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
} }
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