Skip to contentSkip to conversation

drm: limit property blob creation per file

PATCH In review Xiao Kan 2 participants 8 messages Jan 3 – Jan 16

Subsystems (2)
lore
Share & tools
lore

Xiao Kan

author
#0 lore raw

PATCH 1/1 drm: limit property blob creation per file

DRM_IOCTL_MODE_CREATEPROPBLOB allows userspace to create property blobs whose lifetime is scoped to a drm_file.

Currently, a single drm_file may create an unbounded number of blobs. Repeated ioctl calls can trigger unbounded kernel memory allocation and lead to OOM, resulting in a denial-of-service.

Introduce a per-drm_file limit on the number of user-created property blobs. The limit is enforced at the point where a blob becomes associated with a drm_file, matching the existing ownership and lifetime model. This bounds per-file allocations while the total number of DRM file descriptors remains constrained by existing kernel limits.

---
 drivers/gpu/drm/drm_file.c     | 1 +
 drivers/gpu/drm/drm_property.c | 8 ++++++++
 include/drm/drm_file.h         | 6 ++++++
 3 files changed, 15 insertions(+)
drivers/gpu/drm/drm_file.c +1 -0
index eebd1a05e..873bf6248 100755
@@ -152,6 +152,7 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
 	INIT_LIST_HEAD(&file->fbs);
 	mutex_init(&file->fbs_lock);
 	INIT_LIST_HEAD(&file->blobs);
+	file->blob_count = 0;
 	INIT_LIST_HEAD(&file->pending_event_list);
 	INIT_LIST_HEAD(&file->event_list);
 	init_waitqueue_head(&file->event_wait);
drivers/gpu/drm/drm_property.c +8 -0
index 596272149..00eac336a 100755
@@ -618,6 +618,7 @@ void drm_property_destroy_user_blobs(struct drm_device *dev,
 	 */
 	list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) {
 		list_del_init(&blob->head_file);
+		file_priv->blob_count--;
 		drm_property_blob_put(blob);
 	}
 }
@@ -864,8 +865,14 @@ int drm_mode_createblob_ioctl(struct drm_device *dev,
 	 * as only the same file_priv can remove the blob; at this point, it is
 	 * not associated with any file_priv. */
 	mutex_lock(&dev->mode_config.blob_lock);
+	if (file_priv->blob_count >= DRM_FILE_MAX_PROPBLOBS) {
+		mutex_unlock(&dev->mode_config.blob_lock);
+		drm_property_blob_put(blob);
+		return -ENOSPC;
+	}
 	out_resp->blob_id = blob->base.id;
 	list_add_tail(&blob->head_file, &file_priv->blobs);
+	file_priv->blob_count++;
 	mutex_unlock(&dev->mode_config.blob_lock);
 
 	return 0;
@@ -907,6 +914,7 @@ int drm_mode_destroyblob_ioctl(struct drm_device *dev,
 	/* We must drop head_file here, because we may not be the last
 	 * reference on the blob. */
 	list_del_init(&blob->head_file);
+	file_priv->blob_count--;
 	mutex_unlock(&dev->mode_config.blob_lock);
 
 	/* One reference from lookup, and one from the filp. */
include/drm/drm_file.h +6 -0
index 115763799..211c4284f 100755
@@ -38,6 +38,9 @@
 
 #include <drm/drm_prime.h>
 
+/* Maximum number of user-created property blobs per drm_file */
+#define DRM_FILE_MAX_PROPBLOBS 256
+
 struct dma_fence;
 struct drm_file;
 struct drm_device;
@@ -349,6 +352,9 @@ struct drm_file {
 	 */
 	struct list_head blobs;
 
+	/* Number of property blobs owned by this file */
+	unsigned int blob_count;
+
 	/** @event_wait: Waitqueue for new events added to @event_list. */
 	wait_queue_head_t event_wait;
 
Signature · 1 line
2.51.0
maintainer
#1 lore raw

Hi,

Quoted 7 lines · Xiao Kan

DRM_IOCTL_MODE_CREATEPROPBLOB allows userspace to create property blobs whose lifetime is scoped to a drm_file.

Currently, a single drm_file may create an unbounded number of blobs. Repeated ioctl calls can trigger unbounded kernel memory allocation and lead to OOM, resulting in a denial-of-service.

Quoted 8 lines

Introduce a per-drm_file limit on the number of user-created property blobs. The limit is enforced at the point where a blob becomes associated with a drm_file, matching the existing ownership and lifetime model. This bounds per-file allocations while the total number of DRM file descriptors remains constrained by existing kernel limits.

Wouldn't it make more sense to account the allocation in memcg by passing GFP_ACCOUNT to the kvzalloc call in drm_property_create_blob?

Maxime

author
#2 lore raw

Hi Maxime,

Thanks for the suggestion — that makes sense.

Accounting the property blob allocation via GFP_ACCOUNT addresses the problem at the right layer by charging memory usage to the caller’s memcg, instead of introducing additional per-file limits or policy in DRM. This ensures that excessive allocations are contained within the offending cgroup and handled by memcg OOM, avoiding system-wide impact. I agree this is a cleaner approach and will respin the patch accordingly.

BR,
Xiao

---Original---
From: "Maxime Ripard"<[email protected]&gt;
Date: Mon, Jan 5, 2026 18:36 PM
To: "Xiao Kan"<[email protected]&gt;;
Cc: "maarten.lankhorst"<[email protected]&gt;;"tzimmermann"<[email protected]&gt;;"airlied"<[email protected]&gt;;"simona"<[email protected]&gt;;"dri-devel"<[email protected]&gt;;"linux-kernel"<[email protected]&gt;;"w"<[email protected]&gt;;"security"<[email protected]&gt;;"kanxiao666"<[email protected]&gt;;"xiao.kan"<[email protected]&gt;;
Subject: Re: [PATCH] drm: limit property blob creation per file

Hi,

On&nbsp;Sat,&nbsp;Jan&nbsp;03,&nbsp;2026&nbsp;at&nbsp;10:25:29AM&nbsp;-0500,&nbsp;Xiao&nbsp;Kan&nbsp;wrote:
&gt;&nbsp;DRM_IOCTL_MODE_CREATEPROPBLOB&nbsp;allows&nbsp;userspace&nbsp;to&nbsp;create&nbsp;property&nbsp;blobs &gt;&nbsp;whose&nbsp;lifetime&nbsp;is&nbsp;scoped&nbsp;to&nbsp;a&nbsp;drm_file.
&gt;&nbsp; &gt;&nbsp;Currently,&nbsp;a&nbsp;single&nbsp;drm_file&nbsp;may&nbsp;create&nbsp;an&nbsp;unbounded&nbsp;number&nbsp;of&nbsp;blobs. &gt;&nbsp;Repeated&nbsp;ioctl&nbsp;calls&nbsp;can&nbsp;trigger&nbsp;unbounded&nbsp;kernel&nbsp;memory&nbsp;allocation&nbsp;and &gt;&nbsp;lead&nbsp;to&nbsp;OOM,&nbsp;resulting&nbsp;in&nbsp;a&nbsp;denial-of-service.
&gt;&nbsp; &gt;&nbsp;Introduce&nbsp;a&nbsp;per-drm_file&nbsp;limit&nbsp;on&nbsp;the&nbsp;number&nbsp;of&nbsp;user-created&nbsp;property &gt;&nbsp;blobs.&nbsp;The&nbsp;limit&nbsp;is&nbsp;enforced&nbsp;at&nbsp;the&nbsp;point&nbsp;where&nbsp;a&nbsp;blob&nbsp;becomes&nbsp;associated &gt;&nbsp;with&nbsp;a&nbsp;drm_file,&nbsp;matching&nbsp;the&nbsp;existing&nbsp;ownership&nbsp;and&nbsp;lifetime&nbsp;model. &gt;&nbsp;This&nbsp;bounds&nbsp;per-file&nbsp;allocations&nbsp;while&nbsp;the&nbsp;total&nbsp;number&nbsp;of&nbsp;DRM&nbsp;file &gt;&nbsp;descriptors&nbsp;remains&nbsp;constrained&nbsp;by&nbsp;existing&nbsp;kernel&nbsp;limits.
&gt;&nbsp;
&gt;&nbsp;Signed-off-by:&nbsp;Xiao&nbsp;Kan&nbsp;<[email protected]&gt; &gt;&nbsp;Signed-off-by:&nbsp;Xiao&nbsp;Kan&nbsp;<[email protected]&gt;

Wouldn't&nbsp;it&nbsp;make&nbsp;more&nbsp;sense&nbsp;to&nbsp;account&nbsp;the&nbsp;allocation&nbsp;in&nbsp;memcg&nbsp;by passing&nbsp;GFP_ACCOUNT&nbsp;to&nbsp;the&nbsp;kvzalloc&nbsp;call&nbsp;in&nbsp;drm_property_create_blob?

Maxime

author
#3 lore raw

PATCH v2 1/1 drm: Account property blob allocations to memcg

In reply to Maxime Ripard

DRM_IOCTL_MODE_CREATEPROPBLOB allows userspace to allocate arbitrary-sized property blobs backed by kernel memory.

Currently, the blob data allocation is not accounted to the allocating process's memory cgroup, allowing unprivileged users to trigger unbounded kernel memory consumption and potentially cause system-wide OOM.

Mark the property blob data allocation with GFP_ACCOUNT so that the memory is properly charged to the caller's memcg. This ensures existing cgroup memory limits apply and prevents uncontrolled kernel memory growth without introducing additional policy or per-file limits.

Changes since v1:
- Drop the per-drm_file blob count limit.
- Account blob data allocations to memcg via GFP_ACCOUNT instead.

---
 drivers/gpu/drm/drm_property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_property.c +1 -1
index 596272149..c5c91b88f 100755
@@ -562,7 +562,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,
 	if (!length || length > INT_MAX - sizeof(struct drm_property_blob))
 		return ERR_PTR(-EINVAL);
 
-	blob = kvzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
+	blob = kvzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL | GFP_ACCOUNT);
 	if (!blob)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
2.51.0
author
#4 lore raw

PATCH v2 1/1 drm: Account property blob allocations to memcg

In reply to Maxime Ripard

DRM_IOCTL_MODE_CREATEPROPBLOB allows userspace to allocate arbitrary-sized property blobs backed by kernel memory.

Currently, the blob data allocation is not accounted to the allocating process's memory cgroup, allowing unprivileged users to trigger unbounded kernel memory consumption and potentially cause system-wide OOM.

Mark the property blob data allocation with GFP_ACCOUNT so that the memory is properly charged to the caller's memcg. This ensures existing cgroup memory limits apply and prevents uncontrolled kernel memory growth without introducing additional policy or per-file limits.

Changes since v1:
- Drop the per-drm_file blob count limit.
- Account blob data allocations to memcg via GFP_KERNEL_ACCOUNT instead.

---
 drivers/gpu/drm/drm_property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_property.c +1 -1
index 596272149..a34758712 100755
@@ -562,7 +562,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,
 	if (!length || length > INT_MAX - sizeof(struct drm_property_blob))
 		return ERR_PTR(-EINVAL);
 
-	blob = kvzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
+	blob = kvzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL_ACCOUNT);
 	if (!blob)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
2.51.0
maintainer
#5 lore raw

Re: [PATCH v2] drm: Account property blob allocations to memcg

Hi,

Quoted 12 lines · Xiao Kan

DRM_IOCTL_MODE_CREATEPROPBLOB allows userspace to allocate arbitrary-sized property blobs backed by kernel memory.

Currently, the blob data allocation is not accounted to the allocating process's memory cgroup, allowing unprivileged users to trigger unbounded kernel memory consumption and potentially cause system-wide OOM.

Mark the property blob data allocation with GFP_ACCOUNT so that the memory is properly charged to the caller's memcg. This ensures existing cgroup memory limits apply and prevents uncontrolled kernel memory growth without introducing additional policy or per-file limits.

Quoted 6 lines

Changes since v1:
- Drop the per-drm_file blob count limit.
- Account blob data allocations to memcg via GFP_KERNEL_ACCOUNT instead.

It looks like you sent two different patches labelled v2? Sending a new version in itself is not a problem (and even encourage), but you should always bump the version number.

Maxime

author
#6 lore raw

PATCH v3 1/1 drm: Account property blob allocations to memcg

DRM_IOCTL_MODE_CREATEPROPBLOB allows userspace to allocate arbitrary-sized property blobs backed by kernel memory.

Currently, the blob data allocation is not accounted to the allocating process's memory cgroup, allowing unprivileged users to trigger unbounded kernel memory consumption and potentially cause system-wide OOM.

Mark the property blob data allocation with GFP_KERNEL_ACCOUNT so that the memory is properly charged to the caller's memcg. This ensures existing cgroup memory limits apply and prevents uncontrolled kernel memory growth without introducing additional policy or per-file limits.

---
 drivers/gpu/drm/drm_property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_property.c +1 -1
index 596272149..3c88b5fbd 100755
@@ -562,7 +562,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,
 	if (!length || length > INT_MAX - sizeof(struct drm_property_blob))
 		return ERR_PTR(-EINVAL);
 
-	blob = kvzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
+	blob = kvzalloc(sizeof(struct drm_property_blob) + length, GFP_KERNEL_ACCOUNT);
 	if (!blob)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
2.51.0
maintainer Applied
#7 lore raw

Re: [PATCH v3] drm: Account property blob allocations to memcg

Quoted 8 lines · Xiao Kan

DRM_IOCTL_MODE_CREATEPROPBLOB allows userspace to allocate arbitrary-sized property blobs backed by kernel memory.

Currently, the blob data allocation is not accounted to the allocating process's memory cgroup, allowing unprivileged users to trigger unbounded kernel memory consumption and potentially cause system-wide OOM.

[...]

Applied to misc/kernel.git (drm-misc-next).

Thanks!
Maxime