drm/amdkfd: check CRIU SVM priv data bounds before allocating
Subsystems (3)
PATCH 1/1 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.
copy_from_user() returns the number of bytes not copied, not an errno. Test it directly instead of storing it in ret, so ret only ever holds an error code.
No functional change for valid input.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +5 -7
@@ -4236,19 +4236,17 @@ 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); -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
Public
It looks like this patch contains two separate fixes. Could you split them into two patches?
Best Regards,
Yifan
-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Monday, November 2, 2026 3:02 PM
To: Deucher, Alexander <[email protected]>; Zhang, Yifan <[email protected]>; [email protected]
Cc: Koenig, Christian <[email protected]>; Yuan, Perry <[email protected]>
Subject: [PATCH] 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.
copy_from_user() returns the number of bytes not copied, not an errno. Test it directly instead of storing it in ret, so ret only ever holds an error code.
No functional change for valid input.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +5 -7
@@ -4236,19 +4236,17 @@ 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); -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
Public
Quoted 9 lines
-----Original Message-----
From: Zhang, Yifan <[email protected]>
Sent: Thursday, November 5, 2026 11:23 AM
To: Yuan, Perry <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Cc: Koenig, Christian <[email protected]>
Subject: RE: [PATCH] drm/amdkfd: check CRIU SVM priv data bounds before allocating
Quoted 7 lines
Public
It looks like this patch contains two separate fixes. Could you split them into two patches?
Best Regards,
Yifan
Sure, will split into two fixes patch in v2.
Thanks.
Quoted 58 lines
-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Monday, November 2, 2026 3:02 PM
To: Deucher, Alexander <[email protected]>; Zhang, Yifan <[email protected]>; [email protected]
Cc: Koenig, Christian <[email protected]>; Yuan, Perry <[email protected]>
Subject: [PATCH] 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-EINVALdirectly.
copy_from_user()returns the number of bytes not copied, not an errno. Test it directly instead of storing it in ret, so ret only ever holds an error code.No functional change for valid input.
Signed-off-by Perry Yuan <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +5
-8@@ -4236,19 +4236,17 @@ 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); -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