Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1262269 > unrolled thread

[PATCH] vfio: Fix bug in vfio_device_get_from_name()

Started byJoerg Roedel <joro@8bytes.org>
First post2015-11-04 14:00 +0100
Last post2015-11-04 17:30 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] vfio: Fix bug in vfio_device_get_from_name() Joerg Roedel <joro@8bytes.org> - 2015-11-04 14:00 +0100
    Re: [PATCH] vfio: Fix bug in vfio_device_get_from_name() Alex Williamson <alex.williamson@redhat.com> - 2015-11-04 17:30 +0100

#1262269 — [PATCH] vfio: Fix bug in vfio_device_get_from_name()

FromJoerg Roedel <joro@8bytes.org>
Date2015-11-04 14:00 +0100
Subject[PATCH] vfio: Fix bug in vfio_device_get_from_name()
Message-ID<qr5Ps-yZ-25@gated-at.bofh.it>
From: Joerg Roedel <jroedel@suse.de>

The vfio_device_get_from_name() function might return a
non-NULL pointer, when called with a device name that is not
found in the list. This causes undefined behavior, in my
case calling an invalid function pointer later on:

 kernel tried to execute NX-protected page - exploit attempt? (uid: 0)
 BUG: unable to handle kernel paging request at ffff8800cb3ddc08

[...]

 Call Trace:
  [<ffffffffa03bd733>] ? vfio_group_fops_unl_ioctl+0x253/0x410 [vfio]
  [<ffffffff811efc4d>] do_vfs_ioctl+0x2cd/0x4c0
  [<ffffffff811f9657>] ? __fget+0x77/0xb0
  [<ffffffff811efeb9>] SyS_ioctl+0x79/0x90
  [<ffffffff81001bb0>] ? syscall_return_slowpath+0x50/0x130
  [<ffffffff8167f776>] entry_SYSCALL_64_fastpath+0x16/0x75

Fix the issue by returning NULL when there is no device with
the requested name in the list.

Cc: stable@vger.kernel.org # v4.2+
Fixes: 4bc94d5dc95d ("vfio: Fix lockdep issue")
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/vfio/vfio.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 563c510..8c50ea6 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -692,11 +692,12 @@ EXPORT_SYMBOL_GPL(vfio_device_get_from_dev);
 static struct vfio_device *vfio_device_get_from_name(struct vfio_group *group,
 						     char *buf)
 {
-	struct vfio_device *device;
+	struct vfio_device *it, *device = NULL;
 
 	mutex_lock(&group->device_lock);
-	list_for_each_entry(device, &group->device_list, group_next) {
-		if (!strcmp(dev_name(device->dev), buf)) {
+	list_for_each_entry(it, &group->device_list, group_next) {
+		if (!strcmp(dev_name(it->dev), buf)) {
+			device = it;
 			vfio_device_get(device);
 			break;
 		}
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1262420

FromAlex Williamson <alex.williamson@redhat.com>
Date2015-11-04 17:30 +0100
Message-ID<qr96F-2O2-11@gated-at.bofh.it>
In reply to#1262269
On Wed, 2015-11-04 at 13:53 +0100, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
> 
> The vfio_device_get_from_name() function might return a
> non-NULL pointer, when called with a device name that is not
> found in the list. This causes undefined behavior, in my
> case calling an invalid function pointer later on:
> 
>  kernel tried to execute NX-protected page - exploit attempt? (uid: 0)
>  BUG: unable to handle kernel paging request at ffff8800cb3ddc08
> 
> [...]
> 
>  Call Trace:
>   [<ffffffffa03bd733>] ? vfio_group_fops_unl_ioctl+0x253/0x410 [vfio]
>   [<ffffffff811efc4d>] do_vfs_ioctl+0x2cd/0x4c0
>   [<ffffffff811f9657>] ? __fget+0x77/0xb0
>   [<ffffffff811efeb9>] SyS_ioctl+0x79/0x90
>   [<ffffffff81001bb0>] ? syscall_return_slowpath+0x50/0x130
>   [<ffffffff8167f776>] entry_SYSCALL_64_fastpath+0x16/0x75
> 
> Fix the issue by returning NULL when there is no device with
> the requested name in the list.
> 
> Cc: stable@vger.kernel.org # v4.2+
> Fixes: 4bc94d5dc95d ("vfio: Fix lockdep issue")
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
> ---

Thanks for tracking this down, Joerg!  Looks right, I'll queue it for
next.  Thanks,

Alex

>  drivers/vfio/vfio.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 563c510..8c50ea6 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -692,11 +692,12 @@ EXPORT_SYMBOL_GPL(vfio_device_get_from_dev);
>  static struct vfio_device *vfio_device_get_from_name(struct vfio_group *group,
>  						     char *buf)
>  {
> -	struct vfio_device *device;
> +	struct vfio_device *it, *device = NULL;
>  
>  	mutex_lock(&group->device_lock);
> -	list_for_each_entry(device, &group->device_list, group_next) {
> -		if (!strcmp(dev_name(device->dev), buf)) {
> +	list_for_each_entry(it, &group->device_list, group_next) {
> +		if (!strcmp(dev_name(it->dev), buf)) {
> +			device = it;
>  			vfio_device_get(device);
>  			break;
>  		}



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web