From: Matthew Brost <matthew.brost@intel.com>
To: Matthew Auld <matthew.auld@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] drm/xe/vm: move xa_alloc to prevent UAF
Date: Wed, 25 Sep 2024 16:33:58 +0000 [thread overview]
Message-ID: <ZvQ7doZ1OdK4e4Ax@DUT025-TGLU.fm.intel.com> (raw)
In-Reply-To: <20240925071426.144015-3-matthew.auld@intel.com>
On Wed, Sep 25, 2024 at 08:14:27AM +0100, Matthew Auld wrote:
> Evil user can guess the next id of the vm before the ioctl completes and
> then call vm destroy ioctl to trigger UAF since create ioctl is still
> referencing the same vm. Move the xa_alloc all the way to the end to
> prevent this.
>
> v2:
> - Rebase
>
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> Cc: <stable@vger.kernel.org> # v6.8+
> ---
> drivers/gpu/drm/xe/xe_vm.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index 31fe31db3fdc..ce9dca4d4e87 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -1765,10 +1765,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
> if (IS_ERR(vm))
> return PTR_ERR(vm);
>
> - err = xa_alloc(&xef->vm.xa, &id, vm, xa_limit_32b, GFP_KERNEL);
> - if (err)
> - goto err_close_and_put;
> -
> if (xe->info.has_asid) {
> down_write(&xe->usm.lock);
> err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
> @@ -1776,12 +1772,11 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
> &xe->usm.next_asid, GFP_KERNEL);
> up_write(&xe->usm.lock);
> if (err < 0)
> - goto err_free_id;
> + goto err_close_and_put;
>
> vm->usm.asid = asid;
> }
>
> - args->vm_id = id;
> vm->xef = xe_file_get(xef);
>
> /* Record BO memory for VM pagetable created against client */
> @@ -1794,10 +1789,15 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
> args->reserved[0] = xe_bo_main_addr(vm->pt_root[0]->bo, XE_PAGE_SIZE);
> #endif
>
> + /* user id alloc must always be last in ioctl to prevent UAF */
> + err = xa_alloc(&xef->vm.xa, &id, vm, xa_limit_32b, GFP_KERNEL);
> + if (err)
> + goto err_close_and_put;
> +
> + args->vm_id = id;
> +
> return 0;
>
> -err_free_id:
> - xa_erase(&xef->vm.xa, id);
> err_close_and_put:
> xe_vm_close_and_put(vm);
>
> --
> 2.46.1
>
next prev parent reply other threads:[~2024-09-25 16:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-25 7:14 [PATCH v2 1/2] drm/xe/vm: move xa_alloc to prevent UAF Matthew Auld
2024-09-25 7:14 ` [PATCH v2 2/2] drm/xe/queue: " Matthew Auld
2024-09-25 9:33 ` Nirmoy Das
2024-09-25 9:51 ` Matthew Auld
2024-09-25 10:44 ` Nirmoy Das
2024-09-25 11:24 ` Matthew Auld
2024-09-25 11:50 ` Nirmoy Das
2024-09-25 16:34 ` Matthew Brost
2024-09-25 9:24 ` [PATCH v2 1/2] drm/xe/vm: " Nirmoy Das
2024-09-25 16:33 ` Matthew Brost [this message]
2024-09-26 9:14 ` ✓ CI.Patch_applied: success for series starting with [v2,1/2] " Patchwork
2024-09-26 9:14 ` ✓ CI.checkpatch: " Patchwork
2024-09-26 9:15 ` ✓ CI.KUnit: " Patchwork
2024-09-26 9:27 ` ✓ CI.Build: " Patchwork
2024-09-26 9:29 ` ✓ CI.Hooks: " Patchwork
2024-09-26 9:30 ` ✓ CI.checksparse: " Patchwork
2024-09-26 10:00 ` ✓ CI.BAT: " Patchwork
2024-09-27 1:40 ` ✗ CI.FULL: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZvQ7doZ1OdK4e4Ax@DUT025-TGLU.fm.intel.com \
--to=matthew.brost@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.auld@intel.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.