Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795047206; b=PPMWAgHyfq/Gg+gJHGAF1Yq+k60jNYopBIeMBsz6A4s2O5fR0ayjumGvLGimjXti0zLx n3arptx++isYdZR+HxAGJkokwhEopXyt1UlRiN1nMV29qtSCJGoOGZsuaAOgzc9jusR5T w0ACyf+2FtK0raJDgZKxgBwe7vEfHCKcgCT67EvwJ8aMn9a4HXbqnmqT/qbze5rVOMy8f 4MgElTl/xtt8jBDE/D1PreBFMYX7xwyC9TLfDV6iKilMHEJ4ODz5Dwv2sU/9dEwu3dQM8 63CxTkf36V7G0iV+q8fx/3Vxw0GqOJzMdIoaDldReAUzJS/A+2HSKQDjT/FCzn1o5HQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795047206; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=UtSiuCY5ZHRzndgHJz29NfcG1sT6QFLU/2AhMg9FbJA=; b=F2adoqNUzQknhBfRpy6V45QNSuT5YXIdB3G6Ti01De7tgnnEFfZ9/sqxlcqnj1psDEtq 2x1tUsVjjGOCkkKOhTyR2JsxrjdYl/vPVgPIBTfQAyNBbTkX0/nT0+Wvj9rBSMflbk/wA TJPlWgMqnhzAzRxatGs2WIuzN6ymHy5pIck9YxS1bNlQWPht77zrJBGSXsd5HB4oVu9aW LmdtnxDHynzwsGruQr5f7/jwTy1W3lAQd9lbko997NOC9K7EtpPl5mjtyZ4XGFZccPSaF LsXbTMEGoie/bzvLmcyDV6OClDC1GEmVVBDW9UHnYQjR7dRK8oZbT/UYcTxJsBA07Cw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=jjP0f+WU; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF29160A2609; Thu, 19 Nov 2026 00:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=jjP0f+WU Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE8361F000C4; Thu, 19 Nov 2026 00:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795047206; bh=UtSiuCY5ZHRzndgHJz29NfcG1sT6QFLU/2AhMg9FbJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jjP0f+WU+icmXuyznAxbJQzLMT964zPyT9zORMZx2brD5kArVmeEZqaJQHU4v5msc Jwe/oU85UNwLTUK9m5zptzae2BlXR2sTtfadm1fE8O4Od3gUHJoIsnXcCeaDfK1b8F zBdUFKiwaDasicW1tDyX6wciELUAzIy6JRz16LSE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tvrtko Ursulin , Alex Deucher , Sasha Levin Subject: [PATCH 6.1 1506/2857] drm/amdgpu: Use (v)memdup_array_user in amdgpu_cs_pass1 Date: Wed, 18 Nov 2026 15:42:20 +0100 Message-ID: <20261118150255.557322938@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tvrtko Ursulin [ 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. Signed-off-by: Tvrtko Ursulin Signed-off-by: Alex Deucher Stable-dep-of: ba4c3c202919 ("drm/amdgpu: reject CS chunks too large for kvmalloc()") Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 33 ++++++++------------------ 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index 0a5fa026d595e..37782e2b6cf18 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -191,25 +191,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), @@ -222,7 +214,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, @@ -235,20 +226,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; -- 2.53.0