Skip to content

Commit

Permalink
char: xillybus: Fix trivial bug with mutex
Browse files Browse the repository at this point in the history
commit c002f04 upstream.

@unit_mutex protects @Unit from being freed, so obviously it should be
released after @Unit is used, and not before.

This is a follow-up to commit 282a4b7 ("char: xillybus: Prevent
use-after-free due to race condition") which ensures, among others, the
protection of @private_data after @unit_mutex has been released.

Reported-by: Hyunwoo Kim <[email protected]>
Signed-off-by: Eli Billauer <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
billauer authored and gregkh committed Nov 22, 2024
1 parent 00baca7 commit 9b242c4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/char/xillybus/xillybus_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,15 @@ int xillybus_find_inode(struct inode *inode,
break;
}

mutex_unlock(&unit_mutex);

if (!unit)
if (!unit) {
mutex_unlock(&unit_mutex);
return -ENODEV;
}

*private_data = unit->private_data;
*index = minor - unit->lowest_minor;

mutex_unlock(&unit_mutex);
return 0;
}
EXPORT_SYMBOL(xillybus_find_inode);
Expand Down

0 comments on commit 9b242c4

Please sign in to comment.