hfsplus: fix ignored error return in hfsplus_delete_cat
Subsystems (2)
PATCH 1/1 hfsplus: fix ignored error return in hfsplus_delete_cat
hfsplus_delete_cat() calls hfsplus_delete_all_attrs() to remove all extended attributes associated with a catalog entry, but silently discards its return value.
When the xattr deletion fails on a corrupt filesystem image (as triggered by syzbot), hfsplus_delete_cat() incorrectly returns 0 (success) to its callers, allowing execution to continue with the filesystem in an inconsistent state and eventually triggering a
general protection fault in hfsplus_cat_write_inode().
Fix this by capturing the return value of hfsplus_delete_all_attrs() and propagating genuine errors back to the caller. -ENOENT is excluded since it signals normal loop termination (no more xattrs left to delete) and is not an error condition.
--- fs/hfsplus/catalog.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/hfsplus/catalog.c +9 -2
@@ -421,8 +421,15 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str)hfsplus_mark_inode_dirty (dir,HFSPLUS_I_CAT_DIRTY );if (type ==HFSPLUS_FILE || type ==HFSPLUS_FOLDER ) { -if (HFSPLUS_SB (sb)->attr_tree) -hfsplus_delete_all_attrs (dir, cnid); +if (HFSPLUS_SB (sb)->attr_tree) { +int attr_err =hfsplus_delete_all_attrs (dir, cnid); + +if (attr_err && attr_err != -ENOENT ) { +pr_err ("hfsplus: failed to delete xattrs for cnid %u: %d\n" , + cnid, attr_err); + err = attr_err; + } + } } out:
Signature · 1 line
2.43.0
Quoted 48 lines · Deepanshu Kartikey
hfsplus_delete_cat()callshfsplus_delete_all_attrs()to remove all extended attributes associated with a catalog entry, but silently discards its return value.When the xattr deletion fails on a corrupt filesystem image (as triggered by syzbot),
hfsplus_delete_cat()incorrectly returns 0 (success) to its callers, allowing execution to continue with the filesystem in an inconsistent state and eventually triggering ageneral protection fault in hfsplus_cat_write_inode().Fix this by capturing the return value of
hfsplus_delete_all_attrs()and propagating genuine errors back to the caller.-ENOENTis excluded since it signals normal loop termination (no more xattrs left to delete) and is not an error condition.Fixes 324ef39a8a4f ("hfsplus: add support of manipulation by attributes file")Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- fs/hfsplus/catalog.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)fs/hfsplus/catalog.c +9
-3@@ -421,8 +421,15 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str)hfsplus_mark_inode_dirty (dir,HFSPLUS_I_CAT_DIRTY );if (type ==HFSPLUS_FILE || type ==HFSPLUS_FOLDER ) { -if (HFSPLUS_SB (sb)->attr_tree) -hfsplus_delete_all_attrs (dir, cnid); +if (HFSPLUS_SB (sb)->attr_tree) { +int attr_err =hfsplus_delete_all_attrs (dir, cnid); + +if (attr_err && attr_err != -ENOENT ) { +pr_err ("hfsplus: failed to delete xattrs for cnid %u: %d\n" , + cnid, attr_err); + err = attr_err; + } + } } out: --
Quoted 2 lines
2.43.0
I have sent pach v2.
Thanks
Deepanshu