Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

char: xillybus: Fix trivial bug with mutex

@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 282a4b71816b ("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 <imv4bel@gmail.com>
Signed-off-by: Eli Billauer <eli.billauer@gmail.com>
Link: https://lore.kernel.org/r/20221117071825.3942-1-eli.billauer@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Eli Billauer and committed by
Greg Kroah-Hartman
c002f04c 0ef77698

+4 -3
+4 -3
drivers/char/xillybus/xillybus_class.c
··· 227 227 break; 228 228 } 229 229 230 - mutex_unlock(&unit_mutex); 231 - 232 - if (!unit) 230 + if (!unit) { 231 + mutex_unlock(&unit_mutex); 233 232 return -ENODEV; 233 + } 234 234 235 235 *private_data = unit->private_data; 236 236 *index = minor - unit->lowest_minor; 237 237 238 + mutex_unlock(&unit_mutex); 238 239 return 0; 239 240 } 240 241 EXPORT_SYMBOL(xillybus_find_inode);