Skip to contentSkip to conversation

hfsplus: avoid crash on failed block map free

PATCH In review Vyacheslav Dubeyko 3 participants 13 messages Nov 13, 2012 – Dec 19, 2012

Subsystems (2)
lore
Share & tools
lore

Vyacheslav Dubeyko

author maintainer
#0 lore raw

PATCH v2 1/1 hfsplus: avoid crash on failed block map free

Hi Alan,

Do you agree with second version of the patch?

With the best regards,
Vyacheslav Dubeyko.
--
From: Alan Cox <[email protected]>
Subject: [PATCH v2] hfsplus: avoid crash on failed block map free

v1->v2
* Change hardcoded error code on -ENOENT.
* Add return -EIO for the case of kmap error.
* Fix issue with twice mutex unlock.
* Fix issue with printing kmap error message on every call.

If the read fails we kmap an error code. This doesn't end well. Instead print a critical error and pray. This mirrors the rest of the fs behaviour with critical error cases.

---
 fs/hfsplus/bitmap.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
fs/hfsplus/bitmap.c +12 -1
index 4cfbe2e..6feefc0 100644
@@ -176,12 +176,14 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 	dprint(DBG_BITMAP, "block_free: %u,%u\n", offset, count);
 	/* are all of the bits in range? */
 	if ((offset + count) > sbi->total_blocks)
-		return -2;
+		return -ENOENT;
 
 	mutex_lock(&sbi->alloc_mutex);
 	mapping = sbi->alloc_file->i_mapping;
 	pnr = offset / PAGE_CACHE_BITS;
 	page = read_mapping_page(mapping, pnr, NULL);
+	if (IS_ERR(page))
+		goto kaboom;
 	pptr = kmap(page);
 	curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32;
 	end = pptr + PAGE_CACHE_BITS / 32;
@@ -214,6 +216,8 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 		set_page_dirty(page);
 		kunmap(page);
 		page = read_mapping_page(mapping, ++pnr, NULL);
+		if (IS_ERR(page))
+			goto kaboom;
 		pptr = kmap(page);
 		curr = pptr;
 		end = pptr + PAGE_CACHE_BITS / 32;
@@ -232,4 +236,11 @@ out:
 	mutex_unlock(&sbi->alloc_mutex);
 
 	return 0;
+
+kaboom:
+	printk(KERN_CRIT "hfsplus: unable to mark blocks free: error %ld\n",
+			PTR_ERR(page));
+	mutex_unlock(&sbi->alloc_mutex);
+
+	return -EIO;
 }
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 34 lines · On Tue, 13 Nov 2012 13:31:05 +0400 Vyacheslav Dubeyko <[email protected]> wrote:

If the read fails we kmap an error code. This doesn't end well. Instead print a critical error and pray. This mirrors the rest of the fs behaviour with critical error cases.

...

index 4cfbe2e..6feefc0 100644

fs/hfsplus/bitmap.c +5 -1
@@ -176,12 +176,14 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 	dprint(DBG_BITMAP, "block_free: %u,%u\n", offset, count);
 	/* are all of the bits in range? */
 	if ((offset + count) > sbi->total_blocks)
-		return -2;
+		return -ENOENT;
 
 	mutex_lock(&sbi->alloc_mutex);
 	mapping = sbi->alloc_file->i_mapping;
 	pnr = offset / PAGE_CACHE_BITS;
 	page = read_mapping_page(mapping, pnr, NULL);
+	if (IS_ERR(page))
+		goto kaboom;
 	pptr = kmap(page);
 	curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32;
 	end = pptr + PAGE_CACHE_BITS / 32;
@@ -214,6 +216,8 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 		set_page_dirty(page);
 		kunmap(page);
 		page = read_mapping_page(mapping, ++pnr, NULL);
+		if (IS_ERR(page))
+			goto kaboom;
 		pptr = kmap(page);
 		curr = pptr;
 		end = pptr + PAGE_CACHE_BITS / 32;
@@ -232,4 +236,11 @@ out:
 	mutex_unlock(&sbi->alloc_mutex);

fs/hfsplus/bitmap.c out: · line 246

Quoted 10 lines
fs/hfsplus/bitmap.c +7 -0
 
 	return 0;
+
+kaboom:
+	printk(KERN_CRIT "hfsplus: unable to mark blocks free: error %ld\n",
+			PTR_ERR(page));
+	mutex_unlock(&sbi->alloc_mutex);
+
+	return -EIO;
 }

It looks better than what we currently have!

The code is missing a flush_dcache_page()? We should have one in there after the CPU has modified userspace-mappable page contents.

btw, I still have question marks over your earlier patches:

hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch hfsplus-add-support-of-manipulation-by-attributes-file.patch hfsplus-add-support-of-manipulation-by-attributes-file-checkpatch-fixes.patch hfsplus-code-style-fixes-reworked-support-of-extended-attributes.patch

Christoph sounded unhappy, but the review discussion petered out?

#2 lore raw
Quoted 8 lines · Andrew Morton

It looks better than what we currently have!

The code is missing a flush_dcache_page()? We should have one in there after the CPU has modified userspace-mappable page contents.

btw, I still have question marks over your earlier patches:

Quoted 8 lines

hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch hfsplus-add-support-of-manipulation-by-attributes-file.patch hfsplus-add-support-of-manipulation-by-attributes-file-checkpatch-fixes.patch hfsplus-code-style-fixes-reworked-support-of-extended-attributes.patch

Christoph sounded unhappy, but the review discussion petered out?

It really just needs the xattr namespace fixed. JFS is a good model for how to expose the legacy OS/2 attributes that are lacking a namespace prefix.

author maintainer
#3 lore raw

Hi,

Quoted 16 lines · Christoph Hellwig
Quoted 15 lines · Andrew Morton

It looks better than what we currently have!

The code is missing a flush_dcache_page()? We should have one in there after the CPU has modified userspace-mappable page contents.

btw, I still have question marks over your earlier patches:

hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch hfsplus-add-support-of-manipulation-by-attributes-file.patch hfsplus-add-support-of-manipulation-by-attributes-file-checkpatch-fixes.patch hfsplus-code-style-fixes-reworked-support-of-extended-attributes.patch

Quoted 4 lines
Quoted 1 line

Christoph sounded unhappy, but the review discussion petered out?

It really just needs the xattr namespace fixed. JFS is a good model for how to expose the legacy OS/2 attributes that are lacking a namespace prefix.

So, likewise JFS model every pure Mac OS X xattr (for example, com.apple.FinderInfo) will be prefixed with "mac-os-x." during list_xattr stage. Then this prefix will be excluded for search in Catalog b-tree during get_xattr and set_xattr calls. And I try to rework the code for using general dispatching code also.

Do you have any objections? :-)

With the best regards,
Vyacheslav Dubeyko.

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 7 lines · Vyacheslav Dubeyko

So, likewise JFS model every pure Mac OS X xattr (for example, com.apple.FinderInfo) will be prefixed with "mac-os-x." during list_xattr stage. Then this prefix will be excluded for search in Catalog b-tree during get_xattr and set_xattr calls. And I try to rework the code for using general dispatching code also.

Do you have any objections? :-)

How about just osx as a short prefix? That'll mirror os2. and looks less awkward. Otherwise the plan looks good.

author maintainer
#5 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Vyacheslav Dubeyko

So, likewise JFS model every pure Mac OS X xattr (for example, com.apple.FinderInfo) will be prefixed with "mac-os-x." during list_xattr stage. Then this prefix will be excluded for search in Catalog b-tree during get_xattr and set_xattr calls. And I try to rework the code for using general dispatching code also.

Quoted 5 lines
Quoted 1 line

Do you have any objections? :-)

How about just osx as a short prefix? That'll mirror os2. and looks less awkward. Otherwise the plan looks good.

Ok. I agree with "osx." prefix.

With the best regards,
Vyacheslav Dubeyko.

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#6 lore raw
In reply to Andrew Morton

On Tue, 2012-11-13 at 14:34 -0800, Andrew Morton wrote:

[snip]

Quoted 4 lines

The code is missing a flush_dcache_page()? We should have one in there after the CPU has modified userspace-mappable page contents.

Yes, I think your comment is precious. But I feel a necessity to analyze hfsplus driver code more deeply for proper fix of this issue. An userspace-mappable page content is the main use-case for such fix. But it exists the multi CPUs use-case. So, I need to think about correctness of hfsplus driver for such use-case also, I think.

Quoted 12 lines

btw, I still have question marks over your earlier patches:

hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch hfsplus-add-support-of-manipulation-by-attributes-file.patch hfsplus-add-support-of-manipulation-by-attributes-file-checkpatch-fixes.patch hfsplus-code-style-fixes-reworked-support-of-extended-attributes.patch

Christoph sounded unhappy, but the review discussion petered out?

So, as you can see the discussion revives again. :-) And I need to familiarize with implementation of xattrs in JFS before to answer again. I had objection that we need to remember about using HFS+ volumes as under Linux as under Mac OS X. Maybe, JFS implementation of xattrs to change my vision.

With the best regards,
Vyacheslav Dubeyko.

#7 lore raw
Quoted 24 lines · On Wed, 14 Nov 2012 16:50:53 +0400 Vyacheslav Dubeyko <[email protected]> wrote:

On Tue, 2012-11-13 at 14:34 -0800, Andrew Morton wrote:

[snip]

Quoted 4 lines

The code is missing a flush_dcache_page()? We should have one in there after the CPU has modified userspace-mappable page contents.

Yes, I think your comment is precious. But I feel a necessity to analyze hfsplus driver code more deeply for proper fix of this issue. An userspace-mappable page content is the main use-case for such fix. But it exists the multi CPUs use-case. So, I need to think about correctness of hfsplus driver for such use-case also, I think.

Quoted 10 lines

btw, I still have question marks over your earlier patches:

hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch hfsplus-add-support-of-manipulation-by-attributes-file.patch hfsplus-add-support-of-manipulation-by-attributes-file-checkpatch-fixes.patch hfsplus-code-style-fixes-reworked-support-of-extended-attributes.patch

Quoted 8 lines
Quoted 2 lines

Christoph sounded unhappy, but the review discussion petered out?

So, as you can see the discussion revives again. :-) And I need to familiarize with implementation of xattrs in JFS before to answer again. I had objection that we need to remember about using HFS+ volumes as under Linux as under Mac OS X. Maybe, JFS implementation of xattrs to change my vision.

I'm still unclear where we stand with these patches. Which if any of these should I merge?

Thanks.

hfsplus-avoid-crash-on-failed-block-map-free.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-avoid-crash-on-failed-block-map-free.patch

hfsplus-add-osx-prefix-for-handling-namespace-of-mac-os-x-extended-attributes.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-osx-prefix-for-handling-namespace-of-mac-os-x-extended-attributes.patch

hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch

hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch

hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch

hfsplus-add-support-of-manipulation-by-attributes-file.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-support-of-manipulation-by-attributes-file.patch

hfsplus-rework-processing-errors-in-hfsplus_free_extents.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-rework-processing-errors-in-hfsplus_free_extents.patch

hfsplus-rework-processing-of-hfs_btree_write-returned-error.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-rework-processing-of-hfs_btree_write-returned-error.patch

hfsplus-add-error-message-for-the-case-of-failure-of-sync-fs-in-delayed_sync_fs-method.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-error-message-for-the-case-of-failure-of-sync-fs-in-delayed_sync_fs-method.patch

author maintainer
#8 lore raw
Quoted 30 lines · Andrew Morton
Quoted 27 lines · On Wed, 14 Nov 2012 16:50:53 +0400 Vyacheslav Dubeyko <[email protected]> wrote:

On Tue, 2012-11-13 at 14:34 -0800, Andrew Morton wrote:

[snip]

Quoted 4 lines

The code is missing a flush_dcache_page()? We should have one in there after the CPU has modified userspace-mappable page contents.

Yes, I think your comment is precious. But I feel a necessity to analyze hfsplus driver code more deeply for proper fix of this issue. An userspace-mappable page content is the main use-case for such fix. But it exists the multi CPUs use-case. So, I need to think about correctness of hfsplus driver for such use-case also, I think.

Quoted 12 lines

btw, I still have question marks over your earlier patches:

hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch hfsplus-add-support-of-manipulation-by-attributes-file.patch hfsplus-add-support-of-manipulation-by-attributes-file-checkpatch-fixes.patch hfsplus-code-style-fixes-reworked-support-of-extended-attributes.patch

Christoph sounded unhappy, but the review discussion petered out?

Quoted 9 lines
Quoted 5 lines

So, as you can see the discussion revives again. :-) And I need to familiarize with implementation of xattrs in JFS before to answer again. I had objection that we need to remember about using HFS+ volumes as under Linux as under Mac OS X. Maybe, JFS implementation of xattrs to change my vision.

I'm still unclear where we stand with these patches. Which if any of these should I merge?

As I can see these patches contain implementation of xattr support (v3) and reworked error processing in some parts of hfsplus driver. The version 3 of xattr support was implemented after remarks of Christoph Hellwig about necessity to have "osx." prefix. So, after this e-mail we had achieved understanding about proper implementation and it was done.

Maybe I misunderstand something but I thought that these patches were merged in linux-next yet. Or do you talking about merging in mainline?

Currently, I am working on ACLs support in hfsplus driver. But, from my point of view, these patches are important and without ACLs support.

With the best regards,
Vyacheslav Dubeyko.

Quoted 29 lines

Thanks.

hfsplus-avoid-crash-on-failed-block-map-free.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-avoid-crash-on-failed-block-map-free.patch

hfsplus-add-osx-prefix-for-handling-namespace-of-mac-os-x-extended-attributes.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-osx-prefix-for-handling-namespace-of-mac-os-x-extended-attributes.patch

hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-on-disk-layout-declarations-related-to-attributes-tree.patch

hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-functionality-of-manipulating-by-records-in-attributes-tree.patch

hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-rework-functionality-of-getting-setting-and-deleting-of-extended-attributes.patch

hfsplus-add-support-of-manipulation-by-attributes-file.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-support-of-manipulation-by-attributes-file.patch

hfsplus-rework-processing-errors-in-hfsplus_free_extents.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-rework-processing-errors-in-hfsplus_free_extents.patch

hfsplus-rework-processing-of-hfs_btree_write-returned-error.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-rework-processing-of-hfs_btree_write-returned-error.patch

hfsplus-add-error-message-for-the-case-of-failure-of-sync-fs-in-delayed_sync_fs-method.patch
http://ozlabs.org/~akpm/mmots/broken-out/hfsplus-add-error-message-for-the-case-of-failure-of-sync-fs-in-delayed_sync_fs-method.patch

#9 lore raw
Quoted 16 lines · On Wed, 19 Dec 2012 10:26:37 +0400 Vyacheslav Dubeyko <[email protected]> wrote:
Quoted 9 lines
Quoted 5 lines

So, as you can see the discussion revives again. :-) And I need to familiarize with implementation of xattrs in JFS before to answer again. I had objection that we need to remember about using HFS+ volumes as under Linux as under Mac OS X. Maybe, JFS implementation of xattrs to change my vision.

I'm still unclear where we stand with these patches. Which if any of these should I merge?

As I can see these patches contain implementation of xattr support (v3) and reworked error processing in some parts of hfsplus driver. The version 3 of xattr support was implemented after remarks of Christoph Hellwig about necessity to have "osx." prefix. So, after this e-mail we had achieved understanding about proper implementation and it was done.

Quoted 5 lines

Maybe I misunderstand something but I thought that these patches were merged in linux-next yet. Or do you talking about merging in mainline?

Currently, I am working on ACLs support in hfsplus driver. But, from my point of view, these patches are important and without ACLs support.

Yes, they've all been in linux-next for a while.

To be more specific: is Christoph OK with a mainline merge?

author maintainer
#10 lore raw
Quoted 21 lines · Andrew Morton
Quoted 19 lines · On Wed, 19 Dec 2012 10:26:37 +0400 Vyacheslav Dubeyko <[email protected]> wrote:
Quoted 9 lines
Quoted 5 lines

So, as you can see the discussion revives again. :-) And I need to familiarize with implementation of xattrs in JFS before to answer again. I had objection that we need to remember about using HFS+ volumes as under Linux as under Mac OS X. Maybe, JFS implementation of xattrs to change my vision.

I'm still unclear where we stand with these patches. Which if any of these should I merge?

As I can see these patches contain implementation of xattr support (v3) and reworked error processing in some parts of hfsplus driver. The version 3 of xattr support was implemented after remarks of Christoph Hellwig about necessity to have "osx." prefix. So, after this e-mail we had achieved understanding about proper implementation and it was done.

Maybe I misunderstand something but I thought that these patches were merged in linux-next yet. Or do you talking about merging in mainline?

Quoted 6 lines
Quoted 2 lines

Currently, I am working on ACLs support in hfsplus driver. But, from my point of view, these patches are important and without ACLs support.

Yes, they've all been in linux-next for a while.

To be more specific: is Christoph OK with a mainline merge?

I think that we need to ask his about it. :-) I haven't any private e-mailing with him about it.

Maybe, it makes sense to merge in mainline reworked error processing patches previously and, then, to merge the xattr support after ACLs support implementation.

Christoph, could you share your opinion?

With the best regards,
Vyacheslav Dubeyko.

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw
Quoted 4 lines · Vyacheslav Dubeyko
Quoted 3 lines

Yes, they've all been in linux-next for a while.

To be more specific: is Christoph OK with a mainline merge?

Quoted 8 lines

I think that we need to ask his about it. :-) I haven't any private e-mailing with him about it.

Maybe, it makes sense to merge in mainline reworked error processing patches previously and, then, to merge the xattr support after ACLs support implementation.

Christoph, could you share your opinion?

I haven't actually managed to look at your new xattr patches, but at least conceptually I'm fine with them.

Let's get the error handling and misc hfsplus patches in ASAP, in the meantime I'll get a review for the xattr bits in, and then we can decide to merge them directly or together with the ACL bits.

author maintainer
#12 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Vyacheslav Dubeyko
Quoted 3 lines

Yes, they've all been in linux-next for a while.

To be more specific: is Christoph OK with a mainline merge?

I think that we need to ask his about it. :-) I haven't any private e-mailing with him about it.

Maybe, it makes sense to merge in mainline reworked error processing patches previously and, then, to merge the xattr support after ACLs support implementation.

Quoted 9 lines
Quoted 1 line

Christoph, could you share your opinion?

I haven't actually managed to look at your new xattr patches, but at least conceptually I'm fine with them.

Let's get the error handling and misc hfsplus patches in ASAP, in the meantime I'll get a review for the xattr bits in, and then we can decide to merge them directly or together with the ACL bits.

Ok. Thank you.

With the best regards,
Vyacheslav Dubeyko.

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html