Skip to contentSkip to conversation

vfio: Fix NULL pointer dereference caused by uninitialized group->iommufd

PATCH Applied Yan Zhao 5 participants 5 messages Feb 22, 2023

Subsystems (2)
lore
Share & tools
lore

Yan Zhao

author
#0 lore raw

PATCH 1/1 vfio: Fix NULL pointer dereference caused by uninitialized group->iommufd

group->iommufd is not initialized for the iommufd_ctx_put()

[20018.331541] BUG: kernel NULL pointer dereference, address: 0000000000000000
[20018.377508] RIP: 0010:iommufd_ctx_put+0x5/0x10 [iommufd]
...
[20018.476483] Call Trace:
[20018.479214]  <TASK>
[20018.481555]  vfio_group_fops_unl_ioctl+0x506/0x690 [vfio]
[20018.487586]  __x64_sys_ioctl+0x6a/0xb0
[20018.491773]  ? trace_hardirqs_on+0xc5/0xe0
[20018.496347]  do_syscall_64+0x67/0x90
[20018.500340]  entry_SYSCALL_64_after_hwframe+0x4b/0xb5
Fixes 9eefba8002c2 ("vfio: Move vfio group specific code into group.c")
---
 drivers/vfio/group.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/group.c +1 -1
index 57ebe5e1a7e6..8649f85f3be4 100644
@@ -137,7 +137,7 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
 
 		ret = iommufd_vfio_compat_ioas_id(iommufd, &ioas_id);
 		if (ret) {
-			iommufd_ctx_put(group->iommufd);
+			iommufd_ctx_put(iommufd);
 			goto out_unlock;
 		}
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 27 lines · Yan Zhao

group->iommufd is not initialized for the iommufd_ctx_put()

[20018.331541] BUG: kernel NULL pointer dereference, address:
0000000000000000
[20018.377508] RIP: 0010:iommufd_ctx_put+0x5/0x10 [iommufd]
...
[20018.476483] Call Trace:
[20018.479214]  <TASK>
[20018.481555]  vfio_group_fops_unl_ioctl+0x506/0x690 [vfio]
[20018.487586]  __x64_sys_ioctl+0x6a/0xb0
[20018.491773]  ? trace_hardirqs_on+0xc5/0xe0
[20018.496347]  do_syscall_64+0x67/0x90
[20018.500340]  entry_SYSCALL_64_after_hwframe+0x4b/0xb5
Fixes 9eefba8002c2 ("vfio: Move vfio group specific code into

group.c")

---
 drivers/vfio/group.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/group.c +0 -0
index 57ebe5e1a7e6..8649f85f3be4 100644
@@ -137,7 +137,7 @@ static int vfio_group_ioctl_set_container(struct
 vfio_group *group,
Quoted 8 lines


                ret = iommufd_vfio_compat_ioas_id(iommufd, &ioas_id); if (ret) {
-                       iommufd_ctx_put(group->iommufd);
+                       iommufd_ctx_put(iommufd);
                        goto out_unlock;
                }

Might want to Cc this to the stable mailing list.

Signature · 1 line
~miko
Reviewed-by on v1 1/1
#2 lore raw
In reply to Yan Zhao
Quoted 16 lines

From: Zhao, Yan Y <[email protected]>
Sent: Wednesday, February 22, 2023 3:50 PM group->iommufd is not initialized for the iommufd_ctx_put()

[20018.331541] BUG: kernel NULL pointer dereference, address:
0000000000000000
[20018.377508] RIP: 0010:iommufd_ctx_put+0x5/0x10 [iommufd]
...
[20018.476483] Call Trace:
[20018.479214]  <TASK>
[20018.481555]  vfio_group_fops_unl_ioctl+0x506/0x690 [vfio]
[20018.487586]  __x64_sys_ioctl+0x6a/0xb0
[20018.491773]  ? trace_hardirqs_on+0xc5/0xe0
[20018.496347]  do_syscall_64+0x67/0x90
[20018.500340]  entry_SYSCALL_64_after_hwframe+0x4b/0xb5
Quoted 2 lines
Fixes 9eefba8002c2 ("vfio: Move vfio group specific code into group.c")
Quoted 20 lines
---
 drivers/vfio/group.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/group.c +1 -2
index 57ebe5e1a7e6..8649f85f3be4 100644
@@ -137,7 +137,7 @@ static int vfio_group_ioctl_set_container(struct
 vfio_group *group,
 
 		ret = iommufd_vfio_compat_ioas_id(iommufd, &ioas_id);
 		if (ret) {
-			iommufd_ctx_put(group->iommufd);
+			iommufd_ctx_put(iommufd);
 			goto out_unlock;
 		}
 
--

2.17.1

Reviewed-by on v1 1/1
#3 lore raw
In reply to Yan Zhao
Quoted 13 lines · Yan Zhao

group->iommufd is not initialized for the iommufd_ctx_put()

[20018.331541] BUG: kernel NULL pointer dereference, address: 0000000000000000
[20018.377508] RIP: 0010:iommufd_ctx_put+0x5/0x10 [iommufd]
...
[20018.476483] Call Trace:
[20018.479214]  <TASK>
[20018.481555]  vfio_group_fops_unl_ioctl+0x506/0x690 [vfio]
[20018.487586]  __x64_sys_ioctl+0x6a/0xb0
[20018.491773]  ? trace_hardirqs_on+0xc5/0xe0
[20018.496347]  do_syscall_64+0x67/0x90
[20018.500340]  entry_SYSCALL_64_after_hwframe+0x4b/0xb5
Quoted 5 lines
Fixes 9eefba8002c2 ("vfio: Move vfio group specific code into group.c")
---
 drivers/vfio/group.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Jason

#4 lore raw
In reply to Yan Zhao
Quoted 24 lines · On Wed, 22 Feb 2023 15:49:38 +0800 Yan Zhao <[email protected]> wrote:

group->iommufd is not initialized for the iommufd_ctx_put()

[20018.331541] BUG: kernel NULL pointer dereference, address: 0000000000000000
[20018.377508] RIP: 0010:iommufd_ctx_put+0x5/0x10 [iommufd]
...
[20018.476483] Call Trace:
[20018.479214]  <TASK>
[20018.481555]  vfio_group_fops_unl_ioctl+0x506/0x690 [vfio]
[20018.487586]  __x64_sys_ioctl+0x6a/0xb0
[20018.491773]  ? trace_hardirqs_on+0xc5/0xe0
[20018.496347]  do_syscall_64+0x67/0x90
[20018.500340]  entry_SYSCALL_64_after_hwframe+0x4b/0xb5
Fixes 9eefba8002c2 ("vfio: Move vfio group specific code into group.c")
---
 drivers/vfio/group.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/group.c +0 -0
index 57ebe5e1a7e6..8649f85f3be4 100644

drivers/vfio/group.c static int vfio_group_ioctl_set_container(struct vfio_group *group, · line 143

Quoted 8 lines
drivers/vfio/group.c +1 -1
@@ -137,7 +137,7 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
 
 		ret = iommufd_vfio_compat_ioas_id(iommufd, &ioas_id);
 		if (ret) {
-			iommufd_ctx_put(group->iommufd);
+			iommufd_ctx_put(iommufd);
 			goto out_unlock;
 		}
 

Applied to vfio next branch for v6.3 and added a stable cc. Thanks,

Alex