All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/amdgpu: validate GEM_CREATE domain combinations
@ 2026-08-06 10:00 Candice Li
  2026-08-06 12:20 ` Christian König
  0 siblings, 1 reply; 2+ messages in thread
From: Candice Li @ 2026-08-06 10:00 UTC (permalink / raw)
  To: amd-gfx; +Cc: Christian Koenig, Alexander Deucher, Candice Li

AMDGPU_GEM_CREATE checked domain bits against AMDGPU_GEM_DOMAIN_MASK,
but did not validate domain combinations. Userspace could combine
CPU|GTT|VRAM with DOORBELL, GDS, GWS, or OA, making
amdgpu_bo_placement_from_domain() exceed AMDGPU_BO_MAX_PLACEMENTS and
hit BUG_ON().

Allow combinations only within CPU/GTT/VRAM, and require non-CPU/GTT/
VRAM domains to be specified one at a time. Return -EINVAL for invalid
combinations in amdgpu_gem_create_ioctl().

v2: Rename helper from amdgpu_gem_domain_valid() to
    amdgpu_gem_are_domains_valid() (Christian)

Signed-off-by: Candice Li <candice.li@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 6a0699746fbcd6..f754a4a3a1c22d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -397,6 +397,25 @@ const struct drm_gem_object_funcs amdgpu_gem_object_funcs = {
 	.vm_ops = &amdgpu_gem_vm_ops,
 };
 
+static bool amdgpu_gem_are_domains_valid(u32 domains)
+{
+	u32 normal = AMDGPU_GEM_DOMAIN_CPU |
+		     AMDGPU_GEM_DOMAIN_GTT |
+		     AMDGPU_GEM_DOMAIN_VRAM;
+	/* Treat all non CPU/GTT/VRAM domains as special domains. */
+	u32 special = AMDGPU_GEM_DOMAIN_MASK & ~normal;
+	u32 normal_mask = domains & normal;
+	u32 special_mask = domains & special;
+
+	if (!special_mask)
+		return true;
+
+	if (normal_mask)
+		return false;
+
+	return !(special_mask & (special_mask - 1));
+}
+
 /*
  * GEM ioctls.
  */
@@ -421,6 +440,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
 	/* reject invalid gem domains */
 	if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK)
 		return -EINVAL;
+	if (!amdgpu_gem_are_domains_valid(args->in.domains))
+		return -EINVAL;
 
 	if (!amdgpu_is_tmz(adev) && (flags & AMDGPU_GEM_CREATE_ENCRYPTED)) {
 		DRM_NOTE_ONCE("Cannot allocate secure buffer since TMZ is disabled\n");
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] drm/amdgpu: validate GEM_CREATE domain combinations
  2026-08-06 10:00 [PATCH v2] drm/amdgpu: validate GEM_CREATE domain combinations Candice Li
@ 2026-08-06 12:20 ` Christian König
  0 siblings, 0 replies; 2+ messages in thread
From: Christian König @ 2026-08-06 12:20 UTC (permalink / raw)
  To: Candice Li, amd-gfx; +Cc: Alexander Deucher

On 8/6/26 12:00, Candice Li wrote:
> AMDGPU_GEM_CREATE checked domain bits against AMDGPU_GEM_DOMAIN_MASK,
> but did not validate domain combinations. Userspace could combine
> CPU|GTT|VRAM with DOORBELL, GDS, GWS, or OA, making
> amdgpu_bo_placement_from_domain() exceed AMDGPU_BO_MAX_PLACEMENTS and
> hit BUG_ON().
> 
> Allow combinations only within CPU/GTT/VRAM, and require non-CPU/GTT/
> VRAM domains to be specified one at a time. Return -EINVAL for invalid
> combinations in amdgpu_gem_create_ioctl().
> 
> v2: Rename helper from amdgpu_gem_domain_valid() to
>     amdgpu_gem_are_domains_valid() (Christian)
> 
> Signed-off-by: Candice Li <candice.li@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 6a0699746fbcd6..f754a4a3a1c22d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -397,6 +397,25 @@ const struct drm_gem_object_funcs amdgpu_gem_object_funcs = {
>  	.vm_ops = &amdgpu_gem_vm_ops,
>  };
>  
> +static bool amdgpu_gem_are_domains_valid(u32 domains)
> +{
> +	u32 normal = AMDGPU_GEM_DOMAIN_CPU |
> +		     AMDGPU_GEM_DOMAIN_GTT |
> +		     AMDGPU_GEM_DOMAIN_VRAM;
> +	/* Treat all non CPU/GTT/VRAM domains as special domains. */
> +	u32 special = AMDGPU_GEM_DOMAIN_MASK & ~normal;
> +	u32 normal_mask = domains & normal;
> +	u32 special_mask = domains & special;
> +
> +	if (!special_mask)
> +		return true;
> +
> +	if (normal_mask)
> +		return false;
> +
> +	return !(special_mask & (special_mask - 1));
> +}
> +
>  /*
>   * GEM ioctls.
>   */
> @@ -421,6 +440,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
>  	/* reject invalid gem domains */
>  	if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK)
>  		return -EINVAL;
> +	if (!amdgpu_gem_are_domains_valid(args->in.domains))
> +		return -EINVAL;
>  
>  	if (!amdgpu_is_tmz(adev) && (flags & AMDGPU_GEM_CREATE_ENCRYPTED)) {
>  		DRM_NOTE_ONCE("Cannot allocate secure buffer since TMZ is disabled\n");


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-06 12:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06 10:00 [PATCH v2] drm/amdgpu: validate GEM_CREATE domain combinations Candice Li
2026-08-06 12:20 ` Christian König

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.