Skip to content

Commit

Permalink
hfs: do not free node before using
Browse files Browse the repository at this point in the history
hfs_bmap_free() frees the node via hfs_bnode_put(node).  However, it
then reads node->this when dumping error message on an error path, which
may result in a use-after-free bug.  This patch frees the node only when
it is never again used.

Link: http://lkml.kernel.org/r/[email protected]
Fixes: a1185ffa2fc ("HFS rewrite")
Signed-off-by: Pan Bian <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: Ernesto A. Fernandez <[email protected]>
Cc: Viacheslav Dubeyko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
SinkFinder authored and torvalds committed Nov 30, 2018
1 parent 94570a4 commit ce96a40
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/hfs/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,14 @@ void hfs_bmap_free(struct hfs_bnode *node)

nidx -= len * 8;
i = node->next;
hfs_bnode_put(node);
if (!i) {
/* panic */;
pr_crit("unable to free bnode %u. bmap not found!\n",
node->this);
hfs_bnode_put(node);
return;
}
hfs_bnode_put(node);
node = hfs_bnode_find(tree, i);
if (IS_ERR(node))
return;
Expand Down

0 comments on commit ce96a40

Please sign in to comment.