Skip to content

Commit e3885f7

Browse files
airlieddakr
authored andcommitted
nouveau/u_memcpya: use vmemdup_user
I think there are limit checks in place for most things but the new uAPI wants to not have them. Add a limit check and use the vmemdup_user helper instead. Signed-off-by: Dave Airlie <airlied@redhat.com> Reviewed-by: Danilo Krummrich <dakr@redhat.com> Signed-off-by: Danilo Krummrich <dakr@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230810185020.231135-1-airlied@gmail.com
1 parent 31499b0 commit e3885f7

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

drivers/gpu/drm/nouveau/nouveau_drv.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,12 @@ u_free(void *addr)
189189
static inline void *
190190
u_memcpya(uint64_t user, unsigned int nmemb, unsigned int size)
191191
{
192-
void *mem;
193-
void __user *userptr = (void __force __user *)(uintptr_t)user;
192+
void __user *userptr = u64_to_user_ptr(user);
193+
size_t bytes;
194194

195-
size *= nmemb;
196-
197-
mem = kvmalloc(size, GFP_KERNEL);
198-
if (!mem)
199-
return ERR_PTR(-ENOMEM);
200-
201-
if (copy_from_user(mem, userptr, size)) {
202-
u_free(mem);
203-
return ERR_PTR(-EFAULT);
204-
}
205-
206-
return mem;
195+
if (unlikely(check_mul_overflow(nmemb, size, &bytes)))
196+
return NULL;
197+
return vmemdup_user(userptr, bytes);
207198
}
208199

209200
#include <nvif/object.h>

0 commit comments

Comments
 (0)