[PATCH] gpib: fix NULL pointer dereference in autospoll_ioctl()
From: YuanZhe Liu
Date: Mon Nov 16 2026 - 02:48:56 EST
IBCLOSEDEV with handle 0 removes the board descriptor from
file_priv->descriptors and frees it. autospoll_ioctl() is the only
handler that looks the board descriptor up without checking the result
of handle_to_descriptor(), so a following IBAUTOSPOLL dereferences the
NULL pointer in the autopoll_enabled bitfield:
general protection fault, probably for non-canonical address
0xdffffc0000000002: 0000 [#1] SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017]
RIP: autospoll_ioctl drivers/gpib/common/gpib_os.c:1667
Call Trace:
ibioctl
__x64_sys_ioctl
do_syscall_64
entry_SYSCALL_64_after_hwframe
The lookup is also performed without file_priv->descriptors_mutex, so
even without the NULL case the descriptor can be freed by a concurrent
IBCLOSEDEV between the lookup and the access.
Take descriptors_mutex around the lookup and the use, as the other
handlers that use a descriptor do, and return -EINVAL when the board
descriptor has been closed.
Fixes: 9dde4559e939 ("staging: gpib: Add GPIB common core driver")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/gpib/common/gpib_os.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/gpib/common/gpib_os.c b/drivers/gpib/common/gpib_os.c
index 384800e6bf97..f341c36ba475 100644
--- a/drivers/gpib/common/gpib_os.c
+++ b/drivers/gpib/common/gpib_os.c
@@ -1661,7 +1661,16 @@ static int autospoll_ioctl(struct gpib_board *board, struct gpib_file_private *f
if (retval)
return -EFAULT;
+ /*
+ * IBCLOSEDEV removes the board descriptor from the table and frees
+ * it, so the lookup and the use have to be under descriptors_mutex.
+ */
+ mutex_lock(&file_priv->descriptors_mutex);
desc = handle_to_descriptor(file_priv, 0); /* board handle is 0 */
+ if (!desc) {
+ mutex_unlock(&file_priv->descriptors_mutex);
+ return -EINVAL;
+ }
if (enable) {
if (!desc->autopoll_enabled) {
@@ -1685,6 +1694,7 @@ static int autospoll_ioctl(struct gpib_board *board, struct gpib_file_private *f
retval = -EINVAL;
}
}
+ mutex_unlock(&file_priv->descriptors_mutex);
return retval;
}
--
2.34.1