FAILED: patch "[PATCH] drm/amdgpu: reject CS chunks too large for kvmalloc()" failed to apply to 6.6-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x ba4c3c202919405f461a393e823e4b72c8518494
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From ba4c3c202919405f461a393e823e4b72c8518494 Mon Sep 17 00:00:00 2001
From: Jesse Zhang <[email protected]>
Date: Sun, 18 Oct 2026 19:17:57 +0800
Subject: [PATCH] drm/amdgpu: reject CS chunks too large for kvmalloc()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The CS ioctl copies every chunk with vmemdup_array_user() before it looks at it, for whatever length_dw userspace gives. kvmalloc() warns about allocations above INT_MAX when called without __GFP_NOWARN, so any process with the render node can trigger a warning. On navi31, a CS with a chunk of length_dw 0x20000000 returns -ENOMEM after:
WARNING: mm/slub.c:6841 at __kvmalloc_node_noprof+0x5a5/0x7d0
Reject such chunks with -EINVAL before trying to copy them.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6 -0
@@ -218,6 +218,12 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p, size = p->chunks[i].length_dw; +if (size >INT_MAX /sizeof (uint32_t )) { + ret = -EINVAL ; + i--; + goto free_partial_kdata; + } + p->chunks[i].kdata =vmemdup_array_user (u64_to_user_ptr (user_chunk.chunk_data), size,sizeof (uint32_t ));
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 drm/amdgpu: Use (v)memdup_array_user in amdgpu_cs_pass1
From: Tvrtko Ursulin <[email protected]>
[ Upstream commit d4b6274cbf0b0ee92294d699f138b63aa4796ad0 ]
Replace k(v)malloc_array() + copy_from_user() with (v)memdup_array_user().
This shrinks the source code and improves separation between the kernel and userspace slabs.
Stable-dep-of: ba4c3c202919 ("drm/amdgpu: reject CS chunks too large for kvmalloc()")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 33 ++++++++------------------ 1 file changed, 10 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10 -23
@@ -202,25 +202,17 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,struct amdgpu_fpriv *fpriv = p->filp->driver_priv;unsigned int num_ibs[AMDGPU_CS_GANG_SIZE ] = { };struct amdgpu_vm *vm = &fpriv->vm; -uint64_t *chunk_array_user;uint64_t *chunk_array;uint32_t uf_offset =0 ;size_t size;int ret;int i; - chunk_array =kvmalloc_array (cs->in.num_chunks,sizeof (uint64_t ), -GFP_KERNEL ); -if (!chunk_array) -return -ENOMEM ; - -/* get chunks */ - chunk_array_user =u64_to_user_ptr (cs->in.chunks); -if (copy_from_user (chunk_array, chunk_array_user, -sizeof (uint64_t )*cs->in.num_chunks)) { - ret = -EFAULT ; - goto free_chunk; - } + chunk_array =memdup_array_user (u64_to_user_ptr (cs->in.chunks), + cs->in.num_chunks, +sizeof (uint64_t )); +if (IS_ERR (chunk_array)) +return PTR_ERR (chunk_array); p->nchunks = cs->in.num_chunks; p->chunks = kvmalloc_array(p->nchunks, sizeof(struct amdgpu_cs_chunk),
@@ -233,7 +225,6 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,for (i =0 ; i < p->nchunks; i++) {struct drm_amdgpu_cs_chunk __user *chunk_ptr =NULL ;struct drm_amdgpu_cs_chunk user_chunk; -uint32_t __user *cdata; chunk_ptr =u64_to_user_ptr (chunk_array[i]); if (copy_from_user(&user_chunk, chunk_ptr,
@@ -246,20 +237,16 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p, p->chunks[i].length_dw = user_chunk.length_dw; size = p->chunks[i].length_dw; - cdata =u64_to_user_ptr (user_chunk.chunk_data); - p->chunks[i].kdata =kvmalloc_array (size,sizeof (uint32_t ), -GFP_KERNEL ); -if (p->chunks[i].kdata ==NULL ) { - ret = -ENOMEM ; + p->chunks[i].kdata =vmemdup_array_user (u64_to_user_ptr (user_chunk.chunk_data), + size, +sizeof (uint32_t )); +if (IS_ERR (p->chunks[i].kdata)) { + ret =PTR_ERR (p->chunks[i].kdata); i--; goto free_partial_kdata; } size *=sizeof (uint32_t ); -if (copy_from_user (p->chunks[i].kdata, cdata, size)) { - ret = -EFAULT ; - goto free_partial_kdata; - }/* Assume the worst on the following checks */ ret = -EINVAL ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 drm/amdgpu: reject CS chunks too large for kvmalloc()
From: Jesse Zhang <[email protected]>
[ Upstream commit ba4c3c202919405f461a393e823e4b72c8518494 ]
The CS ioctl copies every chunk with vmemdup_array_user() before it looks at it, for whatever length_dw userspace gives. kvmalloc() warns about allocations above INT_MAX when called without __GFP_NOWARN, so any process with the render node can trigger a warning. On navi31, a CS with a chunk of length_dw 0x20000000 returns -ENOMEM after:
WARNING: mm/slub.c:6841 at __kvmalloc_node_noprof+0x5a5/0x7d0
Reject such chunks with -EINVAL before trying to copy them.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6 -0
@@ -238,6 +238,12 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p, size = p->chunks[i].length_dw; +if (size >INT_MAX /sizeof (uint32_t )) { + ret = -EINVAL ; + i--; + goto free_partial_kdata; + } + p->chunks[i].kdata =vmemdup_array_user (u64_to_user_ptr (user_chunk.chunk_data), size,sizeof (uint32_t ));
Signature · 1 line
2.53.0