drm/amdkfd: check CRIU SVM priv data bounds before allocating
Subsystems (3)
PATCH v2 1/2 drm/amdkfd: check CRIU SVM priv data bounds before allocating
kfd_criu_restore_svm() allocated the per-range metadata before checking that the range fits in the user supplied private data buffer, so an out of range offset cost a pointless kzalloc()/kfree() round trip. Do the bounds check first and return -EINVAL directly.
v2:
- split the original patch into two, one change per patch (Yifan)
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -4
@@ -4248,15 +4248,14 @@ int kfd_criu_restore_svm(struct kfd_process *p, svm_priv_data_size =sizeof (struct kfd_criu_svm_range_priv_data ) + svm_attrs_size; +if (*priv_data_offset + svm_priv_data_size > max_priv_data_size) +return -EINVAL ; + criu_svm_md =kzalloc (svm_object_md_size,GFP_KERNEL );if (!criu_svm_md) {pr_err ("failed to allocate memory to store svm metadata\n" );return -ENOMEM ; } -if (*priv_data_offset + svm_priv_data_size > max_priv_data_size) { - ret = -EINVAL ; - goto exit; - } ret =copy_from_user (&criu_svm_md->data, user_priv_ptr + *priv_data_offset, svm_priv_data_size);
Signature · 1 line
2.34.1
PATCH v2 2/2 drm/amdkfd: test copy_from_user() directly in kfd_criu_restore_svm()
copy_from_user() returns the number of bytes not copied, not an errno. kfd_criu_restore_svm() stored that count in ret before overwriting it with -EFAULT. Test the return value directly so ret only ever holds an error code.
v2:
- split the original patch into two, one change per patch (Yifan)
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -3
@@ -4257,9 +4257,8 @@ int kfd_criu_restore_svm(struct kfd_process *p,return -ENOMEM ; } - ret =copy_from_user (&criu_svm_md->data, user_priv_ptr + *priv_data_offset, - svm_priv_data_size); -if (ret) { +if (copy_from_user (&criu_svm_md->data, user_priv_ptr + *priv_data_offset, + svm_priv_data_size)) { ret = -EFAULT ; goto exit; }
Signature · 1 line
2.34.1
RE: [PATCH v2 2/2] drm/amdkfd: test copy_from_user() directly in kfd_criu_restore_svm()
Public
This series is:
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Perry Yuan
Sent: Friday, November 6, 2026 2:26 PM
To: [email protected]
Cc: Zhang, Yifan <[email protected]>; Yuan, Perry <[email protected]>
Subject: [PATCH v2 2/2] drm/amdkfd: test copy_from_user() directly in kfd_criu_restore_svm()
copy_from_user() returns the number of bytes not copied, not an errno.kfd_criu_restore_svm() stored that count in ret before overwriting it with -EFAULT. Test the return value directly so ret only ever holds an error code.
v2:
- split the original patch into two, one change per patch (Yifan)
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -3
@@ -4257,9 +4257,8 @@ int kfd_criu_restore_svm(struct kfd_process *p,return -ENOMEM ; } - ret =copy_from_user (&criu_svm_md->data, user_priv_ptr + *priv_data_offset, - svm_priv_data_size); -if (ret) { +if (copy_from_user (&criu_svm_md->data, user_priv_ptr + *priv_data_offset, + svm_priv_data_size)) { ret = -EFAULT ; goto exit; }
--
2.34.1